X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=tools%2Fhtdocs%2Fmkws.js;h=20ca0454492b95c24a42278ba5211e2905b1ca2b;hb=4af42409cbfccf1527f7d4db4fd557cd1fff177c;hp=2ffffefc310d11acc27f5cef01c328722f60a327;hpb=9094d83be3e41337f159e404718de985fee85f74;p=mkws-moved-to-github.git diff --git a/tools/htdocs/mkws.js b/tools/htdocs/mkws.js index 2ffffef..20ca045 100644 --- a/tools/htdocs/mkws.js +++ b/tools/htdocs/mkws.js @@ -100,6 +100,48 @@ mkws.debug_function = function (string) { } var debug = mkws.debug_function; // local alias + +Handlebars.registerHelper('json', function(obj) { + return JSON.stringify(obj); +}); + + +// We need {{attr '@name'}} because Handlebars can't parse {{@name}} +Handlebars.registerHelper('attr', function(attrName) { + return this[attrName]; +}); + + +/* + * Use as follows: {{#if-any NAME1 having="NAME2"}} + * Applicable when NAME1 is the name of an array + * The guarded code runs only if at least one element of the NAME1 + * array has a subelement called NAME2. + */ +Handlebars.registerHelper('if-any', function(items, options) { + var having = options.hash.having; + for (var i in items) { + var item = items[i] + if (!having || item[having]) { + return options.fn(this); + } + } + return ""; +}); + + +Handlebars.registerHelper('first', function(items, options) { + var having = options.hash.having; + for (var i in items) { + var item = items[i] + if (!having || item[having]) { + return options.fn(item); + } + } + return ""; +}); + + { /* default mkws config */ var config_default = {