From ffdbd7193fe1d6b90b1b1a56c6adfc0ef08c6b5f Mon Sep 17 00:00:00 2001 From: Mike Taylor Date: Wed, 26 Mar 2014 10:32:16 +0000 Subject: [PATCH] Move Handlebars helpers out to their own new file, mkws-handlebars.js --- src/mkws-core.js | 65 ------------------------------------------------------ 1 file changed, 65 deletions(-) diff --git a/src/mkws-core.js b/src/mkws-core.js index d03dcd5..3ed81a3 100644 --- a/src/mkws-core.js +++ b/src/mkws-core.js @@ -6,71 +6,6 @@ "use strict"; // HTML5: disable for log_level >= 2 -// Handlebars helpers -Handlebars.registerHelper('json', function(obj) { - return $.toJSON(obj); -}); - - -Handlebars.registerHelper('translate', function(s) { - return mkws.M(s); -}); - - -// 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 ""; -}); - - -Handlebars.registerHelper('commaList', function(items, options) { - var out = ""; - - for (var i in items) { - if (i > 0) out += ", "; - out += options.fn(items[i]) - } - - return out; -}); - - -Handlebars.registerHelper('index1', function(obj) { - return obj.data.index + 1; -}); - - - // Set up global mkws object. Contains truly global state such as SP // authentication, and a hash of team objects, indexed by team-name. // -- 1.7.10.4