@@ -52,21 +52,20 @@ function addParentContext(data, currentContext) {
52
52
53
53
_ . mixin ( {
54
54
renderNamedPartial : function ( partialKey , data , currentContext ) {
55
- var partialString = partialRegistry [ partialKey ] ;
56
- if ( typeof partialString !== 'string ' ) { throw `Pattern ${ partialKey } not found.` ; }
55
+ var compiledPartial = partialRegistry [ partialKey ] ;
56
+ if ( typeof compiledPartial !== 'function ' ) { throw `Pattern ${ partialKey } not found.` ; }
57
57
58
- return _ . renderPartial ( partialString , data , currentContext ) ;
58
+ return _ . renderPartial ( compiledPartial , data , currentContext ) ;
59
59
} ,
60
- renderPartial : function ( partial , dataIn , currentContext ) {
60
+ renderPartial : function ( compiledPartial , dataIn , currentContext ) {
61
61
var data = dataIn || { } ;
62
- var compiled ;
62
+
63
63
if ( dataIn && currentContext &&
64
64
dataIn instanceof Object && currentContext instanceof Object ) {
65
65
data = addParentContext ( data , currentContext ) ;
66
66
}
67
- compiled = _ . template ( partial ) ;
68
67
69
- return compiled ( data ) ;
68
+ return compiledPartial ( data ) ;
70
69
} ,
71
70
/* eslint-disable no-eval, no-unused-vars */
72
71
getPath : function ( pathString , currentContext , debug ) {
@@ -102,9 +101,9 @@ var engine_underscore = {
102
101
var compiled ;
103
102
104
103
try {
105
- compiled = _ . template ( pattern . extendedTemplate ) ;
104
+ compiled = partialRegistry [ pattern . patternPartial ] ;
106
105
} catch ( e ) {
107
- console . log ( `Error compiling underscore template ${ pattern . patternName } :` , pattern . extendedTemplate , e ) ;
106
+ console . log ( `Error looking up underscore template ${ pattern . patternName } :` , pattern . extendedTemplate , e ) ;
108
107
}
109
108
110
109
// This try-catch is necessary because references to undefined variables
@@ -134,7 +133,15 @@ var engine_underscore = {
134
133
} ,
135
134
136
135
registerPartial : function ( pattern ) {
137
- partialRegistry [ pattern . patternPartial ] = pattern . template ;
136
+ var compiled ;
137
+
138
+ try {
139
+ var templateString = pattern . extendedTemplate || pattern . template ;
140
+ compiled = _ . template ( templateString ) ;
141
+ } catch ( e ) {
142
+ console . log ( `Error compiling underscore template ${ pattern . patternName } :` , pattern . extendedTemplate , e ) ;
143
+ }
144
+ partialRegistry [ pattern . patternPartial ] = compiled ;
138
145
} ,
139
146
140
147
// find and return any {{> template-name }} within pattern
0 commit comments