@@ -189,36 +189,23 @@ exports.liquid = fromStringRenderer('liquid');
189
189
190
190
exports . liquid . render = function ( str , options , fn ) {
191
191
return promisify ( fn , function ( fn ) {
192
- var engine = requires . liquid || ( requires . liquid = require ( 'tinyliquid' ) ) ;
192
+ var Liquid = requires . liquid || ( requires . liquid = require ( 'liquid-node' ) ) ;
193
+ var engine = new Liquid . Engine ;
194
+
193
195
try {
194
- var context = engine . newContext ( ) ;
195
- var k ;
196
-
197
- /**
198
- * Note that there's a bug in the library that doesn't allow us to pass
199
- * the locals to newContext(), hence looping through the keys:
200
- */
201
-
202
- if ( options . locals ) {
203
- for ( k in options . locals ) {
204
- context . setLocals ( k , options . locals [ k ] ) ;
205
- }
206
- delete options . locals ;
207
- }
196
+ var locals = options . locals || { } ;
208
197
209
198
if ( options . meta ) {
210
- context . setLocals ( 'page' , options . meta ) ;
199
+ locals . pages = options . meta ;
211
200
delete options . meta ;
212
201
}
213
202
214
203
/**
215
204
* Add any defined filters:
216
205
*/
217
-
218
- if ( options . filters ) {
219
- for ( k in options . filters ) {
220
- context . setFilter ( k , options . filters [ k ] ) ;
221
- }
206
+
207
+ if ( options . filters ) {
208
+ engine . registerFilters ( options . filters ) ;
222
209
delete options . filters ;
223
210
}
224
211
@@ -227,16 +214,7 @@ exports.liquid.render = function(str, options, fn){
227
214
*/
228
215
229
216
var includeDir = options . includeDir || process . cwd ( ) ;
230
-
231
- context . onInclude ( function ( name , callback ) {
232
- var extname = path . extname ( name ) ? '' : '.liquid' ;
233
- var filename = path . resolve ( includeDir , name + extname ) ;
234
-
235
- fs . readFile ( filename , { encoding : 'utf8' } , function ( err , data ) {
236
- if ( err ) return callback ( err ) ;
237
- callback ( null , engine . parse ( data ) ) ;
238
- } ) ;
239
- } ) ;
217
+ engine . fileSystem = new Liquid . LocalFileSystem ( includeDir , 'liquid' ) ;
240
218
delete options . includeDir ;
241
219
242
220
/**
@@ -251,14 +229,15 @@ exports.liquid.render = function(str, options, fn){
251
229
252
230
if ( options . customTags ) {
253
231
var tagFunctions = options . customTags ;
254
-
232
+
255
233
for ( k in options . customTags ) {
234
+ engine . registerTag ( k , tagFunctions [ k ] ) ;
256
235
/*Tell jshint there's no problem with having this function in the loop */
257
236
/*jshint -W083 */
258
- compileOptions . customTags [ k ] = function ( context , name , body ) {
259
- var tpl = tagFunctions [ name ] ( body . trim ( ) ) ;
260
- context . astStack . push ( engine . parse ( tpl ) ) ;
261
- } ;
237
+ // compileOptions.customTags[k] = function (context, name, body){
238
+ // var tpl = tagFunctions[name](body.trim());
239
+ // context.astStack.push(engine.parse(tpl));
240
+ // };
262
241
/*jshint +W083 */
263
242
}
264
243
delete options . customTags ;
@@ -268,16 +247,27 @@ exports.liquid.render = function(str, options, fn){
268
247
* Now anything left in `options` becomes a local:
269
248
*/
270
249
271
- for ( k in options ) {
272
- context . setLocals ( k , options [ k ] ) ;
250
+ for ( var k in options ) {
251
+ locals [ k ] = options [ k ] ;
273
252
}
274
253
275
254
/**
276
255
* Finally, execute the template:
277
256
*/
257
+
258
+ return engine
259
+ . parseAndRender ( str , locals )
260
+ . nodeify ( function ( err , result ) {
261
+ if ( err ) {
262
+ throw new Error ( err ) ;
263
+ } else {
264
+ return fn ( null , result ) ;
265
+ }
266
+ } ) ;
267
+
268
+ // var tmpl = cache(context) || cache(context, engine.compile(str, compileOptions));
269
+ // tmpl(context, fn);
278
270
279
- var tmpl = cache ( context ) || cache ( context , engine . compile ( str , compileOptions ) ) ;
280
- tmpl ( context , fn ) ;
281
271
} catch ( err ) {
282
272
fn ( err ) ;
283
273
}
0 commit comments