base-helpers
Advanced tools
Comparing version 0.1.1 to 0.2.0
48
index.js
@@ -67,3 +67,6 @@ /*! | ||
app.define('helpers', function() { | ||
app.define('helpers', function(name, helpers) { | ||
if (typeof name === 'string' && utils.isHelperGroup(helpers)) { | ||
return this.helperGroup.apply(this, arguments); | ||
} | ||
sync.apply(sync, arguments); | ||
@@ -108,3 +111,6 @@ return this; | ||
app.define('asyncHelpers', function() { | ||
app.define('asyncHelpers', function(name, helpers) { | ||
if (typeof name === 'string' && utils.isHelperGroup(helpers)) { | ||
return this.helperGroup.apply(this, arguments); | ||
} | ||
async.apply(async, arguments); | ||
@@ -205,8 +211,23 @@ return this; | ||
debug('registering helper group "%s"', name); | ||
helpers = utils.arrayify(helpers); | ||
var type = isAsync ? 'async' : 'sync'; | ||
this._.helpers[type][name] = this._.helpers[type][name] || {}; | ||
var loader = utils.loader(this._.helpers[type][name], {async: isAsync}); | ||
var group = this._.helpers[type][name] || (this._.helpers[type][name] = {}); | ||
if (typeof helpers === 'function' && utils.isHelperGroup(helpers)) { | ||
Object.defineProperty(helpers, 'isGroup', { | ||
enumerable: false, | ||
configurable: false, | ||
value: true | ||
}); | ||
if (isAsync === true) { | ||
decorateHelpers(helpers, helpers, isAsync); | ||
} | ||
decorateHelpers(helpers, group, isAsync, true); | ||
this._.helpers[type][name] = helpers; | ||
return this; | ||
} | ||
helpers = utils.arrayify(helpers); | ||
var loader = utils.loader(group, {async: isAsync}); | ||
loader.call(loader, helpers); | ||
@@ -217,1 +238,16 @@ return this; | ||
}; | ||
function decorateHelpers(oldHelpers, newHelpers, isAsync, override) { | ||
for (let key in newHelpers) { | ||
if (newHelpers.hasOwnProperty(key)) { | ||
// "newHelpers" is the helpers being passed by the user | ||
if (override === true && oldHelpers[key]) continue; | ||
let fn = newHelpers[key]; | ||
if (typeof fn === 'function') { | ||
fn.async = isAsync; | ||
} | ||
oldHelpers[key] = fn; | ||
} | ||
} | ||
} | ||
{ | ||
"name": "base-helpers", | ||
"description": "Adds support for managing template helpers to your base application.", | ||
"version": "0.1.1", | ||
"version": "0.2.0", | ||
"homepage": "https://github.com/node-base/base-helpers", | ||
@@ -24,24 +24,35 @@ "author": "Jon Schlinkert (https://github.com/jonschlinkert)", | ||
"dependencies": { | ||
"debug": "^2.2.0", | ||
"debug": "^2.6.0", | ||
"define-property": "^0.2.5", | ||
"is-valid-app": "^0.1.0", | ||
"lazy-cache": "^2.0.1", | ||
"load-helpers": "^0.2.11" | ||
"is-valid-app": "^0.2.1", | ||
"isobject": "^3.0.0", | ||
"lazy-cache": "^2.0.2", | ||
"load-helpers": "^0.3.1" | ||
}, | ||
"devDependencies": { | ||
"base": "^0.11.0", | ||
"gulp-format-md": "^0.1.9", | ||
"mocha": "^2.5.3" | ||
"base": "^0.11.1", | ||
"gulp-format-md": "^0.1.11", | ||
"mocha": "^3.2.0" | ||
}, | ||
"keywords": [ | ||
"api", | ||
"app", | ||
"application", | ||
"async", | ||
"base", | ||
"baseplugin", | ||
"building-blocks", | ||
"create", | ||
"engine", | ||
"framework", | ||
"helper", | ||
"helpers", | ||
"plugin", | ||
"plugins", | ||
"render", | ||
"template", | ||
"templates" | ||
"templates", | ||
"tool", | ||
"toolkit", | ||
"tools" | ||
], | ||
@@ -48,0 +59,0 @@ "verb": { |
17
utils.js
@@ -12,2 +12,3 @@ 'use strict'; | ||
require('isobject', 'isObject'); | ||
require('define-property', 'define'); | ||
@@ -30,3 +31,19 @@ require('is-valid-app'); | ||
}; | ||
/** | ||
* Return true if the given value is a helper "group" | ||
*/ | ||
utils.isHelperGroup = function(helpers) { | ||
if (!helpers) return false; | ||
if (typeof helpers === 'function' || utils.isObject(helpers)) { | ||
var len = Object.keys(helpers).length; | ||
var min = helpers.async ? 1 : 0; | ||
return helpers.isGroup === true || len > min; | ||
} | ||
if (Array.isArray(helpers)) { | ||
return helpers.isGroup === true; | ||
} | ||
return false; | ||
}; | ||
/** | ||
@@ -33,0 +50,0 @@ * Arrayify the given value by casting it to an array. |
Sorry, the diff of this file is not supported yet
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
No website
QualityPackage does not have a website.
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
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
16456
5
267
0
232
6
+ Addedisobject@^3.0.0
+ Addedcomponent-emitter@1.3.1(transitive)
+ Addedis-valid-app@0.2.1(transitive)
+ Addedis-valid-instance@0.2.0(transitive)
+ Addedisobject@3.0.1(transitive)
+ Addedload-helpers@0.3.1(transitive)
- Removedis-valid-app@0.1.2(transitive)
- Removedis-valid-instance@0.1.0(transitive)
- Removedload-helpers@0.2.11(transitive)
Updateddebug@^2.6.0
Updatedis-valid-app@^0.2.1
Updatedlazy-cache@^2.0.2
Updatedload-helpers@^0.3.1