3 Handlebars.registerHelper('mkws-json', function(obj) {
8 // This is intended to handle paragraphs from Wikipedia, hence the
9 // rather hacky code to remove numbered references.
11 Handlebars.registerHelper('mkws-paragraphs', function(obj, count) {
14 // For some reason, Handlebars provides the value
15 // {"hash":{},"data":{}} for parameters that are not provided. So we
16 // have to be prepared for actual numbers, explicitly undefined
17 // values and this dumb magic value.
18 if (count === undefined || count.hasOwnProperty('hash') || count == 0 || count > obj.length) {
22 for (var i = 0; i < count; i++) {
23 acc.push('<p>', obj[i].replace(/\[[0-9,]+\]/g, ''), '</p>');
29 Handlebars.registerHelper('mkws-translate', function(s) {
34 // We need {{mkws-attr '@name'}} because Handlebars can't parse {{@name}}
35 Handlebars.registerHelper('mkws-attr', function(attrName) {
36 return this[attrName];
41 * Use as follows: {{#mkws-if-any NAME1 having="NAME2"}}
42 * Applicable when NAME1 is the name of an array
43 * The guarded code runs only if at least one element of the NAME1
44 * array has a subelement called NAME2.
46 Handlebars.registerHelper('mkws-if-any', function(items, options) {
47 var having = options.hash.having;
48 for (var i in items) {
50 if (!having || item[having]) {
51 return options.fn(this);
58 Handlebars.registerHelper('mkws-first', function(items, options) {
59 var having = options.hash.having;
60 for (var i in items) {
62 if (!having || item[having]) {
63 return options.fn(item);
70 Handlebars.registerHelper('mkws-commaList', function(items, options) {
73 for (var i in items) {
74 if (i > 0) out += ", ";
75 out += options.fn(items[i])
82 Handlebars.registerHelper('mkws-index1', function(obj) {
83 return obj.data.index + 1;