wheelhouse-handlebars
Version:
A wheelhouse library to handlebars templates for rendering views
27 lines (21 loc) • 648 B
JavaScript
;
var Handlebars = require('handlebars')
// Usage: {{#key_value obj}} Key: {{key}} // Value: {{value}} {{/key_value}}
//
// Iterate over an object, setting 'key' and 'value' for each property in
// the object.
// via https://gist.github.com/strathmeyer/1371586
function eachKeysHelper(context, options) {
var buffer = ''
, key
for (key in context) {
if (context.hasOwnProperty(key)) {
buffer += options.fn({key: key, value: context[key]})
}
}
return buffer
}
module.exports = function(handlebars){
handlebars || (handlebars = Handlebars)
return handlebars.registerHelper('eachKeys', eachKeysHelper)
}