Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

engine-cache

Package Overview
Dependencies
Maintainers
2
Versions
51
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

engine-cache - npm Package Compare versions

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": [

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc