/*! ****************************** Handlebars helpers *******************************/ // debug helper // usage: {{debug}} or {{debug someValue}} // from: @commondream (http://thinkvitamin.com/code/handlebars-js-part-3-tips-and-tricks/) Handlebars.registerHelper("debug", function(optionalValue) { console.log("Current Context"); console.log("===================="); console.log(this); if (optionalValue) { console.log("Value"); console.log("===================="); console.log(optionalValue); } }); // return the first item of a list only // usage: {{#first items}}{{name}}{{/first}} Handlebars.registerHelper('first', function(context, block) { return block(context[0]); }); // a limited 'each' loop. // usage: {{#limit items offset="1" limit="5"}} : items 1 thru 6 // usage: {{#limit items limit="10"}} : items 0 thru 9 // usage: {{#limit items offset="3"}} : items 3 thru context.length // defaults are offset=0, limit=5 Handlebars.registerHelper('limit', function(context, block) { var ret = "", offset = parseInt(block.hash.offset) || 0, limit = parseInt(block.hash.limit) || 5, i = (offset < context.length) ? offset : 0, j = ((limit + offset) < context.length) ? (limit + offset) : context.length; for(i,j; i