helper-cache
Advanced tools
Comparing version 0.2.1 to 0.2.2
24
index.js
@@ -212,5 +212,6 @@ /*! | ||
var self = this; | ||
var next = function (i, callback) { | ||
var i = 0; | ||
var next = function (err, content) { | ||
// current helper info | ||
var helper = self._.waiting[i]; | ||
var helper = self._.waiting[i++]; | ||
@@ -220,19 +221,24 @@ if (helper) { | ||
var fn = self.getHelperAsync(helper.key); | ||
if (!fn) return next(i+1, callback); | ||
if (!fn) return next(null, content); | ||
if (content.indexOf(helper.id) === -1) { | ||
return next(null, content); | ||
} | ||
// call the async helper and replace id with results | ||
var args = helper.args || []; | ||
args.push(function (err, results) { | ||
var nextCallback = function (err, results) { | ||
content = content.replace(helper.id, results); | ||
next(i+1, callback); | ||
}); | ||
next(null, content); | ||
}; | ||
if (args[args.length-1].toString() !== nextCallback.toString()) { | ||
args.push(nextCallback); | ||
} | ||
fn.apply(self, args); | ||
} else { | ||
self._.waiting = []; | ||
// call final callback | ||
callback(null, content); | ||
return cb(null, content); | ||
} | ||
} | ||
next(0, cb.bind(self)); | ||
return next(null, content); | ||
}; | ||
@@ -239,0 +245,0 @@ }); |
{ | ||
"name": "helper-cache", | ||
"description": "Easily get and set helper functions to pass to any application or template engine.", | ||
"version": "0.2.1", | ||
"version": "0.2.2", | ||
"homepage": "https://github.com/jonschlinkert/helper-cache", | ||
@@ -6,0 +6,0 @@ "author": { |
@@ -27,3 +27,3 @@ /*! | ||
}); | ||
helper.addHelperAsync('sleep', function (ms, callback) { | ||
helper.addHelperAsync('sleep', function (ms, msg, callback) { | ||
var start = new Date(); | ||
@@ -33,3 +33,3 @@ setTimeout(function () { | ||
var elapsed = end - start; | ||
callback(null, elapsed); | ||
callback(null, elapsed + ' ' + msg); | ||
}, ms); | ||
@@ -39,3 +39,3 @@ }); | ||
var template = [ | ||
'Elapsed: <%= sleep(50) %>', | ||
'Elapsed: <%= sleep(50, "milliseconds") %>', | ||
'Lower: <%= lower(name) %>', | ||
@@ -42,0 +42,0 @@ 'Upper: <%= upper(name) %>' |
39889
27
1135