@bigcommerce/stencil-paper
Advanced tools
Comparing version 1.0.5 to 1.0.6
@@ -16,11 +16,43 @@ var _ = require('lodash'), | ||
internals.implementation.prototype.register = function(context) { | ||
this.handlebars.registerHelper('any', function(collection, options) { | ||
var predicate = options.hash, | ||
any = _.any(collection, predicate); | ||
this.handlebars.registerHelper('any', function() { | ||
var args = [], | ||
opts, | ||
predicate, | ||
any; | ||
// Translate arguments to array safely | ||
for (var i = 0; i < arguments.length; i++) { | ||
args.push(arguments[i]); | ||
} | ||
// Take the last argument (content) out of testing array | ||
opts = args.pop(); | ||
predicate = opts.hash; | ||
if (!_.isEmpty(predicate)) { | ||
// With options hash, we check the contents of first argument | ||
any = _.any(args[0], predicate); | ||
} else { | ||
// Without options hash, we check all the arguments | ||
any = _.any(args, function(arg) { | ||
if (_.isArray(arg)) { | ||
return !!arg.length; | ||
} | ||
// If an empty object is passed, arg is false | ||
else if (_.isEmpty(arg) && _.isObject(arg)) { | ||
return false; | ||
} | ||
// Everything else | ||
else { | ||
return !!arg; | ||
} | ||
}); | ||
} | ||
if (any) { | ||
return options.fn(this); | ||
return opts.fn(this); | ||
} | ||
return options.inverse(this); | ||
return opts.inverse(this); | ||
}); | ||
@@ -27,0 +59,0 @@ }; |
@@ -9,4 +9,8 @@ var internals = {}; | ||
this.handlebars.registerHelper('replace', function(needle, haystack, options) { | ||
var contains = haystack.indexOf(needle) > -1; | ||
var contains = false; | ||
if (typeof(haystack) === 'string') { | ||
contains = haystack.indexOf(needle) > -1; | ||
} | ||
// Yield block if true | ||
@@ -13,0 +17,0 @@ if (contains) { |
{ | ||
"name": "@bigcommerce/stencil-paper", | ||
"version": "1.0.5", | ||
"version": "1.0.6", | ||
"description": "A stencil plugin to register partials and helpers from handlebars and returns the compiled version for the stencil platform.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -31,2 +31,10 @@ var Code = require('code'), | ||
it('should handle undefined values', function(done) { | ||
var context = {}; | ||
expect(c(templates, context)) | ||
.to.be.equal(''); | ||
done(); | ||
}); | ||
}); |
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
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
145230
74
2344