engine-cache
Advanced tools
Comparing version 0.9.0 to 0.10.0
55
index.js
'use strict'; | ||
var debug = require('debug')('engine-cache'); | ||
var AsyncHelpers = require('async-helpers'); | ||
var Helpers = require('helper-cache'); | ||
@@ -8,2 +9,3 @@ var slice = require('array-slice'); | ||
var forOwn = require('for-own'); | ||
var async = require('async'); | ||
@@ -85,2 +87,3 @@ /** | ||
engine.helpers = new Helpers(options); | ||
engine.asyncHelpers = new AsyncHelpers(options); | ||
@@ -164,2 +167,12 @@ if (typeof engine.render !== 'function' && typeof engine.renderSync !== 'function') { | ||
engine.compile = function (str, options) { | ||
if (typeof str === 'function') { | ||
return str; | ||
} | ||
var opts = extend({}, options); | ||
this.asyncHelpers.helpers = extend({}, this.helpers, opts.helpers); | ||
opts.helpers = this.asyncHelpers.get({wrap: opts.async}); | ||
return compile(str, opts); | ||
} | ||
engine.render = function(str, options, callback) { | ||
@@ -175,10 +188,13 @@ if (typeof options === 'function') { | ||
if (typeof str === 'function') { | ||
return engine.helpers.resolveHelper(str(options), callback); | ||
return this.resolve(str(options), callback); | ||
} | ||
var opts = options || {}; | ||
opts.helpers = extend({}, engine.helpers, opts.helpers); | ||
var opts = extend({}, options); | ||
this.asyncHelpers.helpers = extend({}, this.helpers, opts.helpers); | ||
opts.helpers = this.asyncHelpers.get({wrap: true}); | ||
var self = this; | ||
return render.call(this, str, opts, function (err, content) { | ||
if (err) return callback(err); | ||
return engine.helpers.resolveHelper(content, callback); | ||
return self.resolve(content, callback); | ||
}); | ||
@@ -196,14 +212,27 @@ }; | ||
var opts = options || {}; | ||
opts.helpers = extend({}, engine.helpers, opts.helpers); | ||
opts.helpers = extend({}, this.helpers, opts.helpers); | ||
return renderSync(str, opts); | ||
}; | ||
engine.compile = function (str, options) { | ||
if (typeof str === 'function') { | ||
return str; | ||
} | ||
var opts = options || {}; | ||
opts.helpers = extend({}, engine.helpers, opts.helpers); | ||
return compile(str, opts); | ||
} | ||
engine.resolve = function (str, callback) { | ||
var self = this; | ||
// `stash` contains the objects created when rendering the template | ||
var stashed = self.asyncHelpers.stash; | ||
async.eachSeries(Object.keys(stashed), function (key, next) { | ||
// check to see if the async ID is in the rendered string | ||
if (str.indexOf(key) === -1) { | ||
return next(null); | ||
} | ||
self.asyncHelpers.resolve(key, function (err, value) { | ||
if (err) return next(err); | ||
// replace the async ID with the resolved value | ||
str = str.replace(key, value); | ||
next(null); | ||
}); | ||
}, function (err) { | ||
if (err) return callback(err); | ||
callback(null, str); | ||
}); | ||
}; | ||
}; | ||
@@ -210,0 +239,0 @@ |
{ | ||
"name": "engine-cache", | ||
"description": "express.js inspired template-engine manager.", | ||
"version": "0.9.0", | ||
"version": "0.10.0", | ||
"homepage": "https://github.com/jonschlinkert/engine-cache", | ||
@@ -51,6 +51,8 @@ "author": { | ||
"array-slice": "^0.2.2", | ||
"async": "^0.9.0", | ||
"async-helpers": "^0.1.1", | ||
"debug": "^2.1.1", | ||
"extend-shallow": "^0.2.0", | ||
"for-own": "^0.1.2", | ||
"helper-cache": "^0.5.0" | ||
"helper-cache": "^0.6.0" | ||
}, | ||
@@ -57,0 +59,0 @@ "keywords": [ |
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
12885
271
7
+ Addedasync@^0.9.0
+ Addedasync-helpers@^0.1.1
+ Addedasync@0.9.2(transitive)
+ Addedasync-helpers@0.1.3(transitive)
+ Addedhelper-cache@0.6.0(transitive)
- Removedhelper-cache@0.5.2(transitive)
- Removedis-buffer@1.1.6(transitive)
- Removedis-number@3.0.0(transitive)
- Removedkind-of@3.2.24.0.0(transitive)
- Removedrandomatic@1.1.7(transitive)
Updatedhelper-cache@^0.6.0