1414 * Full. Partial calls and lineage hunting are supported. Handlebars does not
1515 * support the mustache-specific syntax extensions, style modifiers and pattern
1616 * parameters, because their use cases are addressed by the core Handlebars
17- * feature set.
17+ * feature set. It also does not support verbose partial syntax, because it
18+ * seems like it can't tolerate slashes in partial names. But honestly, did you
19+ * really want to use the verbose syntax anyway? I don't.
1820 *
1921 */
2022
2123"use strict" ;
2224
2325var Handlebars = require ( 'handlebars' ) ;
2426
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+
2537var engine_handlebars = {
2638 engine : Handlebars ,
2739 engineName : 'handlebars' ,
@@ -31,26 +43,27 @@ var engine_handlebars = {
3143 // style modifiers or pattern parameters (I think)
3244 expandPartials : false ,
3345
34- // regexes, stored here so they're only compiled once
35- findPartialsRE : / { { # ? > \s * ( [ \w -\/ . ] + ) (?: .| \s + ) * ?} } / g,
36- 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,
37-
3846 // render it
3947 renderPattern : function renderPattern ( pattern , data , partials ) {
4048 if ( partials ) {
4149 Handlebars . registerPartial ( partials ) ;
4250 }
51+ pattern . extendedTemplate = escapeAtPartialBlock ( pattern . extendedTemplate ) ;
4352 var compiled = Handlebars . compile ( pattern . extendedTemplate ) ;
4453 return compiled ( data ) ;
4554 } ,
4655
4756 registerPartial : function ( pattern ) {
57+ // register exact partial name
4858 Handlebars . registerPartial ( pattern . patternPartial , pattern . template ) ;
59+
60+ // register verbose syntax? No, it seems that Handlebars can't tolerate
61+ // slashes in partial names.
4962 } ,
5063
5164 // find and return any {{> template-name }} within pattern
5265 findPartials : function findPartials ( pattern ) {
53- var matches = pattern . template . match ( this . findPartialsRE ) ;
66+ var matches = pattern . template . match ( findPartialsRE ) ;
5467 return matches ;
5568 } ,
5669 findPartialsWithStyleModifiers : function ( ) {
@@ -67,14 +80,14 @@ var engine_handlebars = {
6780 return [ ] ;
6881 } ,
6982 findListItems : function ( pattern ) {
70- var matches = pattern . template . match ( this . findListItemsRE ) ;
83+ var matches = pattern . template . match ( findListItemsRE ) ;
7184 return matches ;
7285 } ,
7386
7487 // given a pattern, and a partial string, tease out the "pattern key" and
7588 // return it.
7689 findPartial : function ( partialString ) {
77- var partial = partialString . replace ( this . findPartialsRE , '$1' ) ;
90+ var partial = partialString . replace ( findPartialsRE , '$1' ) ;
7891 return partial ;
7992 }
8093} ;
0 commit comments