24
24
25
25
var Handlebars = require ( 'handlebars' ) ;
26
26
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
+
27
37
var engine_handlebars = {
28
38
engine : Handlebars ,
29
39
engineName : 'handlebars' ,
@@ -33,15 +43,12 @@ var engine_handlebars = {
33
43
// style modifiers or pattern parameters (I think)
34
44
expandPartials : false ,
35
45
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
-
40
46
// render it
41
47
renderPattern : function renderPattern ( pattern , data , partials ) {
42
48
if ( partials ) {
43
49
Handlebars . registerPartial ( partials ) ;
44
50
}
51
+ pattern . extendedTemplate = escapeAtPartialBlock ( pattern . extendedTemplate ) ;
45
52
var compiled = Handlebars . compile ( pattern . extendedTemplate ) ;
46
53
return compiled ( data ) ;
47
54
} ,
@@ -56,7 +63,7 @@ var engine_handlebars = {
56
63
57
64
// find and return any {{> template-name }} within pattern
58
65
findPartials : function findPartials ( pattern ) {
59
- var matches = pattern . template . match ( this . findPartialsRE ) ;
66
+ var matches = pattern . template . match ( findPartialsRE ) ;
60
67
return matches ;
61
68
} ,
62
69
findPartialsWithStyleModifiers : function ( ) {
@@ -73,14 +80,14 @@ var engine_handlebars = {
73
80
return [ ] ;
74
81
} ,
75
82
findListItems : function ( pattern ) {
76
- var matches = pattern . template . match ( this . findListItemsRE ) ;
83
+ var matches = pattern . template . match ( findListItemsRE ) ;
77
84
return matches ;
78
85
} ,
79
86
80
87
// given a pattern, and a partial string, tease out the "pattern key" and
81
88
// return it.
82
89
findPartial : function ( partialString ) {
83
- var partial = partialString . replace ( this . findPartialsRE , '$1' ) ;
90
+ var partial = partialString . replace ( findPartialsRE , '$1' ) ;
84
91
return partial ;
85
92
}
86
93
} ;
0 commit comments