helper-cache
Advanced tools
Comparing version 0.4.1 to 0.4.2
@@ -226,2 +226,3 @@ /*! | ||
var nextCallback = function (err, results) { | ||
if (err) return cb(err); | ||
content = content.replace(helper.id, results); | ||
@@ -228,0 +229,0 @@ next(null, content); |
{ | ||
"name": "helper-cache", | ||
"description": "Easily get and set helper functions to pass to any application or template engine.", | ||
"version": "0.4.1", | ||
"version": "0.4.2", | ||
"homepage": "https://github.com/jonschlinkert/helper-cache", | ||
@@ -6,0 +6,0 @@ "author": { |
@@ -85,3 +85,65 @@ /*! | ||
it('should bubble up an error.', function (done) { | ||
var helper = cache(); | ||
var partials = { | ||
foo: { | ||
data: { 'bar': 'baz' }, | ||
content: 'Hi there <%= bar %>' | ||
}, | ||
bar: { | ||
data: { 'baz': 'bang' }, | ||
content: 'This is <%= baz %>' | ||
} | ||
}; | ||
function render (content, options, cb) { | ||
content = _.template(content, options, { imports: helper.getHelper() }); | ||
return helper.resolve(content, function (err, content) { | ||
if (err) return cb(err); | ||
return cb(null, content); | ||
}); | ||
} | ||
helper.addAsyncHelper('lower', function (str, callback) { | ||
callback(null, str.toLowerCase()); | ||
}); | ||
helper.addAsyncHelper('upper', function (str, callback) { | ||
callback(null, str.toUpperCase()); | ||
}); | ||
helper.addAsyncHelper('sleep', function (ms, msg, callback) { | ||
var start = new Date(); | ||
setTimeout(function () { | ||
var end = new Date(); | ||
var elapsed = end - start; | ||
callback(null, elapsed + ' ' + msg); | ||
}, ms); | ||
}); | ||
helper.addAsyncHelper('partial', function (name, locals, callback) { | ||
var partial = partials[name]; | ||
if (typeof locals === 'function') { | ||
callback = locals; | ||
locals = {}; | ||
} | ||
if (!partial) return callback(new Error('Partial ' + name + ' not found!')); | ||
render(partial.content, _.extend({}, partial.data, locals), callback); | ||
}); | ||
var template = [ | ||
'Elapsed: <%= sleep(50, "milliseconds") %>', | ||
'Lower: <%= lower(name) %>', | ||
'Upper: <%= upper(name) %>', | ||
'Partial-1: <%= partial("foo") %>', | ||
'Partial-2: <%= partial("bar", { baz: "beep boop bop" }) %>', | ||
'Partial-3: <%= partial("blah") %>' | ||
].join('\n'); | ||
var content = render(template, {name: 'Brian Woodward'}, function (err, content) { | ||
if (err) return done(); | ||
return done(new Error('Expected an error')); | ||
}); | ||
}); | ||
}); | ||
}); |
@@ -50,3 +50,33 @@ /*! | ||
}); | ||
}); | ||
it('should handle an error.', function (done) { | ||
var helper = cache(); | ||
helper.addAsyncHelper('lower', function (str, callback) { | ||
callback(null, str.toLowerCase()); | ||
}); | ||
helper.addAsyncHelper('upper', function (str, callback) { | ||
callback(null, str.toUpperCase()); | ||
}); | ||
helper.addAsyncHelper('error', function (ms, msg, callback) { | ||
var start = new Date(); | ||
setTimeout(function () { | ||
var end = new Date(); | ||
var elapsed = end - start; | ||
callback(new Error('Something bad happened')); | ||
}, ms); | ||
}); | ||
var template = [ | ||
'Elapsed: <%= error(50, "milliseconds") %>', | ||
'Lower: <%= lower(name) %>', | ||
'Upper: <%= upper(name) %>' | ||
].join('\n'); | ||
var content = _.template(template, {name: 'Brian Woodward'}, { imports: helper.getHelper() }); | ||
helper.resolve(content, function (err, content) { | ||
if (err) return done(); | ||
done(new Error('Expected an error to be thrown.')); | ||
}); | ||
}); | ||
@@ -53,0 +83,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
42292
1235