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.19.1 to 0.19.2

README.md

85

index.js

@@ -24,4 +24,4 @@ 'use strict';

this.cache = engines || {};
this.AsyncHelpers = this.options.AsyncHelpers || require('async-helpers');
this.Helpers = this.options.Helpers || require('helper-cache');
this.AsyncHelpers = this.options.AsyncHelpers || utils.AsyncHelpers;
this.Helpers = this.options.Helpers || utils.Helpers;
}

@@ -44,9 +44,10 @@

Engines.prototype.setEngine = function(ext, fn, opts) {
var engine = normalizeEngine(fn, opts);
Engines.prototype.setEngine = function(ext, fn, options) {
var engine = normalizeEngine(fn, options);
var opts = engine.options;
engine.helpers = new this.Helpers(engine.options);
engine.asyncHelpers = new this.AsyncHelpers(engine.options);
engine.name = utils.stripExt(engine.name || engine.options.name || ext);
engine.options.ext = utils.formatExt(ext);
engine.helpers = new this.Helpers(opts);
engine.asyncHelpers = new this.AsyncHelpers(opts);
engine.name = utils.stripExt(engine.name || opts.name || ext);
opts.ext = utils.formatExt(ext);

@@ -57,4 +58,5 @@ // decorate wrapped methods for async helper handling

inspect(engine);
// set the engine on the cache
this.cache[engine.options.ext] = engine;
this.cache[opts.ext] = engine;
return this;

@@ -103,9 +105,8 @@ };

Engines.prototype.getEngine = function(ext) {
if (!ext) return;
var engine = this.cache[utils.formatExt(ext)];
if (typeof engine === 'undefined' && this.options.defaultEngine) {
if (typeof this.options.defaultEngine === 'string') {
return this.cache[utils.formatExt(this.options.defaultEngine)];
var engine = ext ? this.cache[utils.formatExt(ext)] : null;
if (!engine) {
engine = this.options.defaultEngine;
if (typeof engine === 'string') {
engine = this.cache[utils.formatExt(engine)];
}
return this.options.defaultEngine;
}

@@ -136,3 +137,6 @@ return engine;

Engines.prototype.helpers = function(ext) {
return this.getEngine(ext).helpers;
var engine = this.getEngine(ext);
if (engine) {
return engine.helpers;
}
};

@@ -146,3 +150,3 @@

if (utils.isEngine(options)) {
return normalizeEngine(options, fn);
return normalizeEngine(options, fn); //<= reverse args
}

@@ -164,3 +168,3 @@

if (key === 'options') {
engine.options = utils.extend({}, engine.options, fn[key]);
engine.options = utils.merge({}, engine.options, fn[key]);
continue;

@@ -208,7 +212,7 @@ }

* @param {String} `str` Original string to compile.
* @param {Object} `opts` Options/settings to pass to engine's compile function.
* @param {Object} `opts` Options/options to pass to engine's compile function. If a function is passed on `options.mergeFn`, that will be used for merging context before passing it to render.
* @return {Function} Returns render function to call that takes `locals` and optional `callback` function.
*/
engine.compile = function engineCompile(str, settings) {
engine.compile = function engineCompile(str, options) {
if (typeof str === 'function') {

@@ -218,8 +222,8 @@ return str;

if (typeof settings !== 'undefined' && !utils.isObject(settings)) {
throw new TypeError('expected settings to be an object or undefined');
if (typeof options !== 'undefined' && !utils.isObject(options)) {
throw new TypeError('expected options to be an object or undefined');
}
settings = utils.extend({}, settings);
var helpers = mergeHelpers(engine, settings);
options = utils.extend({}, options);
var helpers = mergeHelpers(engine, options);
var compiled = compile ? compile(str, helpers) : null;

@@ -233,16 +237,19 @@

// if compiled already, we can delete helpers and partials from
// the `helpers` object, since were bound to the context and
// passed to the engine at compile time
if (typeof compiled === 'function') {
str = compiled;
// these have already been passed into the
// engine during compile time
delete helpers.helpers;
delete helpers.partials;
helpers = {};
}
var data = {};
if (settings && typeof settings.mergeFn === 'function') {
data = settings.mergeFn(helpers, locals);
if (typeof locals === 'string' || Array.isArray(locals)) {
data = locals;
} else if (options && typeof options.mergeFn === 'function') {
data = options.mergeFn(helpers, locals);
} else {
data = utils.extend({}, locals, helpers);
data = utils.merge({}, locals, helpers);
}

@@ -368,17 +375,17 @@

function mergeHelpers(engine, options) {
if (typeof options !== 'object') {
if (!options || typeof options !== 'object') {
throw new TypeError('expected an object');
}
var opts = utils.merge({}, options);
var opts = utils.extend({}, options);
var helpers = utils.merge({}, engine.helpers, opts.helpers);
if (typeof helpers === 'object') {
for (var key in helpers) {
if (helpers.hasOwnProperty(key)) {
engine.asyncHelpers.set(key, helpers[key]);
}
for (var key in helpers) {
if (helpers.hasOwnProperty(key)) {
engine.asyncHelpers.set(key, helpers[key]);
}
}
opts.helpers = engine.asyncHelpers.get({wrap: opts.async});
return opts;
}
{
"name": "engine-cache",
"description": "express.js inspired template-engine manager.",
"version": "0.19.1",
"version": "0.19.2",
"homepage": "https://github.com/jonschlinkert/engine-cache",

@@ -20,4 +20,2 @@ "author": "Jon Schlinkert (https://github.com/jonschlinkert)",

"index.js",
"LICENSE",
"README.md",
"utils.js"

@@ -36,8 +34,8 @@ ],

"helper-cache": "^0.7.2",
"isobject": "^2.1.0",
"lazy-cache": "^2.0.1",
"isobject": "^3.0.0",
"lazy-cache": "^2.0.2",
"mixin-deep": "^1.1.3"
},
"devDependencies": {
"consolidate": "^0.14.1",
"consolidate": "^0.14.5",
"engine-base": "^0.1.2",

@@ -47,10 +45,10 @@ "engine-handlebars": "^0.8.0",

"gulp": "^3.9.1",
"gulp-format-md": "^0.1.9",
"gulp-istanbul": "^0.10.4",
"gulp-jshint": "^1.11.2",
"gulp-mocha": "^2.2.0",
"handlebars": "^4.0.5",
"jshint-stylish": "^2.2.0",
"lodash": "^4.12.0",
"mocha": "^2.4.5",
"gulp-format-md": "^0.1.11",
"gulp-istanbul": "^1.1.1",
"gulp-jshint": "^2.0.4",
"gulp-mocha": "^3.0.1",
"handlebars": "^4.0.6",
"jshint-stylish": "^2.2.1",
"lodash": "^4.17.4",
"mocha": "^3.2.0",
"swig": "^1.4.2",

@@ -57,0 +55,0 @@ "underscore": "^1.8.3"

@@ -11,3 +11,5 @@ 'use strict';

require('async-helpers', 'AsyncHelpers');
require('extend-shallow', 'extend');
require('helper-cache', 'Helpers')
require('isobject', 'isObject');

@@ -14,0 +16,0 @@ require('mixin-deep', 'merge');

Sorry, the diff of this file is not supported yet

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