X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=tools%2Fhtdocs%2Fmkws.js;h=0638ee47084f6edb9b4e41128f8cd83847f3ced3;hb=85503eefcf6222ccd6717be07a58684001587865;hp=8e282a8d3f2271dab6f393d35426af018e198c91;hpb=b02972410ce4e86179e43f92f66a9eb4a6d3e909;p=mkws-moved-to-github.git diff --git a/tools/htdocs/mkws.js b/tools/htdocs/mkws.js index 8e282a8..0638ee4 100644 --- a/tools/htdocs/mkws.js +++ b/tools/htdocs/mkws.js @@ -101,25 +101,56 @@ mkws.debug_function = function (string) { var debug = mkws.debug_function; // local alias -Handlebars.registerHelper('link', function(a) { - var result = ""; - for (var i in a) { - if (i > 0) result += "
"; - var text = Handlebars.Utils.escapeExpression(a[i]); - result += '' + text + ''; - } +Handlebars.registerHelper('json', function(obj) { + return JSON.stringify(obj); +}); + - return new Handlebars.SafeString(result); +// We need {{attr '@name'}} because Handlebars can't parse {{@name}} +Handlebars.registerHelper('attr', function(attrName) { + return this[attrName]; }); -Handlebars.registerHelper('json', function(obj) { - return JSON.stringify(obj); +/* + * 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) { - return options.fn(items[0]); + var having = options.hash.having; + for (var i in items) { + var item = items[i] + if (!having || item[having]) { + return options.fn(item); + } + } + return ""; +}); + + +Handlebars.registerHelper('commaList', function(items, options) { + var out = ""; + + for (var i in items) { + if (i > 0) out += ", "; + out += options.fn(items[i]) + } + + return out; });