Last active
December 14, 2015 16:29
-
-
Save jimmed/5115658 to your computer and use it in GitHub Desktop.
ObjectKeys
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.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