2424
2525var Handlebars = require ( 'handlebars' ) ;
2626
27+ // regexes, stored here so they're only compiled once
28+ const findPartialsRE = / { { # ? > \s * ( [ \w -\/ . ] + ) (?: .| \s + ) * ?} } / g;
29+ const findListItemsRE = / ( { { # ( ) ? ) ( l i s t ( I | i ) t e m s .) ( o n e | t w o | t h r e e | f o u r | f i v e | s i x | s e v e n | e i g h t | n i n e | t e n | e l e v e n | t w e l v e | t h i r t e e n | f o u r t e e n | f i f t e e n | s i x t e e n | s e v e n t e e n | e i g h t e e n | n i n e t e e n | t w e n t y ) ( ) ? } } / g;
30+ const findAtPartialBlockRE = / { { # ? > \s * @ p a r t i a l - b l o c k \s * } } / g;
31+
32+ function escapeAtPartialBlock ( partialString ) {
33+ var partial = partialString . replace ( findAtPartialBlockRE , '{{> @partial-block }}' )
34+ return partial ;
35+ }
36+
2737var engine_handlebars = {
2838 engine : Handlebars ,
2939 engineName : 'handlebars' ,
@@ -33,15 +43,12 @@ var engine_handlebars = {
3343 // style modifiers or pattern parameters (I think)
3444 expandPartials : false ,
3545
36- // regexes, stored here so they're only compiled once
37- findPartialsRE : / { { # ? > \s * ( [ \w -\/ . ] + ) (?: .| \s + ) * ?} } / g,
38- findListItemsRE : / ( { { # ( ) ? ) ( l i s t ( I | i ) t e m s .) ( o n e | t w o | t h r e e | f o u r | f i v e | s i x | s e v e n | e i g h t | n i n e | t e n | e l e v e n | t w e l v e | t h i r t e e n | f o u r t e e n | f i f t e e n | s i x t e e n | s e v e n t e e n | e i g h t e e n | n i n e t e e n | t w e n t y ) ( ) ? } } / g,
39-
4046 // render it
4147 renderPattern : function renderPattern ( pattern , data , partials ) {
4248 if ( partials ) {
4349 Handlebars . registerPartial ( partials ) ;
4450 }
51+ pattern . extendedTemplate = escapeAtPartialBlock ( pattern . extendedTemplate ) ;
4552 var compiled = Handlebars . compile ( pattern . extendedTemplate ) ;
4653 return compiled ( data ) ;
4754 } ,
@@ -56,7 +63,7 @@ var engine_handlebars = {
5663
5764 // find and return any {{> template-name }} within pattern
5865 findPartials : function findPartials ( pattern ) {
59- var matches = pattern . template . match ( this . findPartialsRE ) ;
66+ var matches = pattern . template . match ( findPartialsRE ) ;
6067 return matches ;
6168 } ,
6269 findPartialsWithStyleModifiers : function ( ) {
@@ -73,14 +80,14 @@ var engine_handlebars = {
7380 return [ ] ;
7481 } ,
7582 findListItems : function ( pattern ) {
76- var matches = pattern . template . match ( this . findListItemsRE ) ;
83+ var matches = pattern . template . match ( findListItemsRE ) ;
7784 return matches ;
7885 } ,
7986
8087 // given a pattern, and a partial string, tease out the "pattern key" and
8188 // return it.
8289 findPartial : function ( partialString ) {
83- var partial = partialString . replace ( this . findPartialsRE , '$1' ) ;
90+ var partial = partialString . replace ( findPartialsRE , '$1' ) ;
8491 return partial ;
8592 }
8693} ;
0 commit comments