Skip to content

Instantly share code, notes, and snippets.

@jimmed
Last active December 14, 2015 16:29
Show Gist options
  • Save jimmed/5115658 to your computer and use it in GitHub Desktop.
Save jimmed/5115658 to your computer and use it in GitHub Desktop.
ObjectKeys
$.extend(dust.helpers, {
/**
* {@objectKeys input=someObject}
* {key}: {value}<br />
* {/objectKeys}
*/
"objectKeys": function(chunk, context, bodies, params) {
params = params || {};
if(!$.isPlainObject(params.input)) {
console.warn('Input parameter to @objectKeys must be a plain object');
}
var isEmpty = true;
if(bodies.block) {
for(var key in params.input) {
isEmpty = false;
var localContext = context.push({key: key, value: params.input[key]});
// TODO: Seems like a hack. Probably is a hack. Shouldn't be a hack
if(localContext && localContext.stack && localContext.stack.tail && localContext.stack.tail.head) {
localContext = localContext.push(localContext.stack.tail.head);
}
chunk.render(bodies.block, localContext);
}
}
if(isEmpty && bodies.empty) {
chunk.render(bodies.empty, context);
}
return chunk;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment