From: Mike Taylor Date: Fri, 2 May 2014 14:04:10 +0000 (+0100) Subject: Prefix names of all Handlebars helpers with "mkws-": X-Git-Tag: 1.0.0~751 X-Git-Url: http://git.indexdata.com/?p=mkws-moved-to-github.git;a=commitdiff_plain;h=084846fd874a094a8c5e70bee766d07e5b69e1b1 Prefix names of all Handlebars helpers with "mkws-": mkws-json mkws-paragraphs mkws-translate mkws-attr mkws-if-any mkws-first mkws-commaList mkws-index1 This fixes MKWS-172 ("Prefix Handlebars helpers"), which OK was only a P5, but it irritated my sense of neatness having a P5 hanging around in the MKWS area with all the good bugs. --- diff --git a/examples/htdocs/lolcat.html b/examples/htdocs/lolcat.html index 89c6790..512c990 100644 --- a/examples/htdocs/lolcat.html +++ b/examples/htdocs/lolcat.html @@ -9,9 +9,9 @@ diff --git a/examples/htdocs/mkws-widget-reference.js b/examples/htdocs/mkws-widget-reference.js index 3231ebc..20e701a 100644 --- a/examples/htdocs/mkws-widget-reference.js +++ b/examples/htdocs/mkws-widget-reference.js @@ -13,7 +13,7 @@ mkws.registerWidgetType('Reference', function() { {{md-title-responsibility}}\ {{/if}}\

\ - {{{paragraphs md-description}}}\ + {{{mkws-paragraphs md-description}}}\

\ '); }); diff --git a/examples/htdocs/templates.html b/examples/htdocs/templates.html index 2f39dd2..bed0122 100644 --- a/examples/htdocs/templates.html +++ b/examples/htdocs/templates.html @@ -51,23 +51,23 @@ {{/if}} - {{#if-any location having="md-subject"}} + {{#mkws-if-any location having="md-subject"}} Subject - {{#first location having="md-subject"}} + {{#mkws-first location having="md-subject"}} {{#if md-subject}} {{md-subject}} {{/if}} - {{/first}} + {{/mkws-first}} - {{/if-any}} + {{/mkws-if-any}} Locations - {{#commaList location}} - {{attr "@name"}}{{/commaList}} + {{#mkws-commaList location}} + {{mkws-attr "@name"}}{{/mkws-commaList}} diff --git a/src/NEWS b/src/NEWS index 5bbb6ad..7d9df79 100644 --- a/src/NEWS +++ b/src/NEWS @@ -7,7 +7,7 @@ The 0.9.x series of releases are beta quality. They are functional but have not yet been extensively battle-tested. 0.9.2 [IN PROGRESS] - - Full-record template invokes {{translate}} on fieldnames. + - Full-record template invokes {{mkws-translate}} on fieldnames. Fixes MKWS-84 Translate fieldnames in full-record popup. 0.9.1 Thu Dec 19 15:33:13 GMT 2013 diff --git a/src/mkws-core.js b/src/mkws-core.js index 79ce880..7d5128e 100644 --- a/src/mkws-core.js +++ b/src/mkws-core.js @@ -169,7 +169,7 @@ mkws.defaultTemplate = function(name) { return '\ \ \ - \ + \ \ {{#if md-date}}\ \ - \ + \ \ \ {{/if}}\ {{#if md-author}}\ \ - \ + \ \ \ {{/if}}\ {{#if md-electronic-url}}\ \ - \ + \ \ \ {{/if}}\ - {{#if-any location having="md-subject"}}\ + {{#mkws-if-any location having="md-subject"}}\ \ - \ + \ \ \ - {{/if-any}}\ + {{/mkws-if-any}}\ \ - \ + \ \ \
{{translate "Title"}}{{mkws-translate "Title"}}\ {{md-title}}\ {{#if md-title-remainder}}\ @@ -182,44 +182,44 @@ mkws.defaultTemplate = function(name) {
{{translate "Date"}}{{mkws-translate "Date"}}{{md-date}}
{{translate "Author"}}{{mkws-translate "Author"}}{{md-author}}
{{translate "Links"}}{{mkws-translate "Links"}}\ {{#each md-electronic-url}}\ - Link{{index1}}\ + Link{{mkws-index1}}\ {{/each}}\
{{translate "Subject"}}{{mkws-translate "Subject"}}\ - {{#first location having="md-subject"}}\ + {{#mkws-first location having="md-subject"}}\ {{#if md-subject}}\ - {{#commaList md-subject}}\ - {{this}}{{/commaList}}\ + {{#mkws-commaList md-subject}}\ + {{this}}{{/mkws-commaList}}\ {{/if}}\ - {{/first}}\ + {{/mkws-first}}\
{{translate "Locations"}}{{mkws-translate "Locations"}}\ - {{#commaList location}}\ - {{attr "@name"}}{{/commaList}}\ + {{#mkws-commaList location}}\ + {{mkws-attr "@name"}}{{/mkws-commaList}}\
\ @@ -239,9 +239,9 @@ mkws.defaultTemplate = function(name) { } else if (name === "Image") { return '\ \ - {{#first md-thumburl}}\ + {{#mkws-first md-thumburl}}\ {{../md-title}}\ - {{/first}}\ + {{/mkws-first}}\
\
\ '; diff --git a/src/mkws-handlebars.js b/src/mkws-handlebars.js index 5fae905..58c95a1 100644 --- a/src/mkws-handlebars.js +++ b/src/mkws-handlebars.js @@ -1,10 +1,10 @@ // Handlebars helpers -Handlebars.registerHelper('json', function(obj) { +Handlebars.registerHelper('mkws-json', function(obj) { return $.toJSON(obj); }); -Handlebars.registerHelper('paragraphs', function(obj) { +Handlebars.registerHelper('mkws-paragraphs', function(obj) { var acc = []; for (var i = 0; i < obj.length; i++) { acc.push('

', obj[i], '

'); @@ -13,24 +13,24 @@ Handlebars.registerHelper('paragraphs', function(obj) { }); -Handlebars.registerHelper('translate', function(s) { +Handlebars.registerHelper('mkws-translate', function(s) { return mkws.M(s); }); -// We need {{attr '@name'}} because Handlebars can't parse {{@name}} -Handlebars.registerHelper('attr', function(attrName) { +// We need {{mkws-attr '@name'}} because Handlebars can't parse {{@name}} +Handlebars.registerHelper('mkws-attr', function(attrName) { return this[attrName]; }); /* - * Use as follows: {{#if-any NAME1 having="NAME2"}} + * Use as follows: {{#mkws-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) { +Handlebars.registerHelper('mkws-if-any', function(items, options) { var having = options.hash.having; for (var i in items) { var item = items[i] @@ -42,7 +42,7 @@ Handlebars.registerHelper('if-any', function(items, options) { }); -Handlebars.registerHelper('first', function(items, options) { +Handlebars.registerHelper('mkws-first', function(items, options) { var having = options.hash.having; for (var i in items) { var item = items[i] @@ -54,7 +54,7 @@ Handlebars.registerHelper('first', function(items, options) { }); -Handlebars.registerHelper('commaList', function(items, options) { +Handlebars.registerHelper('mkws-commaList', function(items, options) { var out = ""; for (var i in items) { @@ -66,6 +66,6 @@ Handlebars.registerHelper('commaList', function(items, options) { }); -Handlebars.registerHelper('index1', function(obj) { +Handlebars.registerHelper('mkws-index1', function(obj) { return obj.data.index + 1; });