Prefix names of all Handlebars helpers with "mkws-":
authorMike Taylor <mike@indexdata.com>
Fri, 2 May 2014 14:04:10 +0000 (15:04 +0100)
committerMike Taylor <mike@indexdata.com>
Fri, 2 May 2014 14:04:10 +0000 (15:04 +0100)
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.

examples/htdocs/lolcat.html
examples/htdocs/mkws-widget-reference.js
examples/htdocs/templates.html
src/NEWS
src/mkws-core.js
src/mkws-handlebars.js

index 89c6790..512c990 100644 (file)
@@ -9,9 +9,9 @@
     <script type="text/javascript" src="http://mkws.indexdata.com/mkws-complete.js"></script>
     <script class="mkwsTemplate_Summary" type="text/x-handlebars-template">
       <a href="#" id="{{_id}}" onclick="{{_onclick}}">
-        {{#first md-thumburl}}
+        {{#mkws-first md-thumburl}}
          <img src="{{this}}" alt="{{../md-title}}"/>
-        {{/first}}
+        {{/mkws-first}}
        <br/>
       </a>
     </script>
index 3231ebc..20e701a 100644 (file)
@@ -13,7 +13,7 @@ mkws.registerWidgetType('Reference', function() {
   <i>{{md-title-responsibility}}</i>\
 {{/if}}\
   <p>\
-    {{{paragraphs md-description}}}\
+    {{{mkws-paragraphs md-description}}}\
   </p>\
 ');
 });
index 2f39dd2..bed0122 100644 (file)
          </td>
        </tr>
        {{/if}}
-       {{#if-any location having="md-subject"}}
+       {{#mkws-if-any location having="md-subject"}}
        <tr>
          <th>Subject</th>
          <td>
-           {{#first location having="md-subject"}}
+           {{#mkws-first location having="md-subject"}}
              {{#if md-subject}}
                {{md-subject}}
              {{/if}}
-           {{/first}}
+           {{/mkws-first}}
          </td>
        </tr>
-       {{/if-any}}
+       {{/mkws-if-any}}
        <tr>
          <th>Locations</th>
          <td>
-           {{#commaList location}}
-             {{attr "@name"}}{{/commaList}}
+           {{#mkws-commaList location}}
+             {{mkws-attr "@name"}}{{/mkws-commaList}}
          </td>
        </tr>
       </table>
index 5bbb6ad..7d9df79 100644 (file)
--- 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
index 79ce880..7d5128e 100644 (file)
@@ -169,7 +169,7 @@ mkws.defaultTemplate = function(name) {
        return '\
 <table>\
   <tr>\
-    <th>{{translate "Title"}}</th>\
+    <th>{{mkws-translate "Title"}}</th>\
     <td>\
       {{md-title}}\
       {{#if md-title-remainder}}\
@@ -182,44 +182,44 @@ mkws.defaultTemplate = function(name) {
   </tr>\
   {{#if md-date}}\
   <tr>\
-    <th>{{translate "Date"}}</th>\
+    <th>{{mkws-translate "Date"}}</th>\
     <td>{{md-date}}</td>\
   </tr>\
   {{/if}}\
   {{#if md-author}}\
   <tr>\
-    <th>{{translate "Author"}}</th>\
+    <th>{{mkws-translate "Author"}}</th>\
     <td>{{md-author}}</td>\
   </tr>\
   {{/if}}\
   {{#if md-electronic-url}}\
   <tr>\
-    <th>{{translate "Links"}}</th>\
+    <th>{{mkws-translate "Links"}}</th>\
     <td>\
       {{#each md-electronic-url}}\
-       <a href="{{this}}">Link{{index1}}</a>\
+       <a href="{{this}}">Link{{mkws-index1}}</a>\
       {{/each}}\
     </td>\
   </tr>\
   {{/if}}\
-  {{#if-any location having="md-subject"}}\
+  {{#mkws-if-any location having="md-subject"}}\
   <tr>\
-    <th>{{translate "Subject"}}</th>\
+    <th>{{mkws-translate "Subject"}}</th>\
     <td>\
-      {{#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}}\
     </td>\
   </tr>\
-  {{/if-any}}\
+  {{/mkws-if-any}}\
   <tr>\
-    <th>{{translate "Locations"}}</th>\
+    <th>{{mkws-translate "Locations"}}</th>\
     <td>\
-      {{#commaList location}}\
-       {{attr "@name"}}{{/commaList}}\
+      {{#mkws-commaList location}}\
+       {{mkws-attr "@name"}}{{/mkws-commaList}}\
     </td>\
   </tr>\
 </table>\
@@ -239,9 +239,9 @@ mkws.defaultTemplate = function(name) {
     } else if (name === "Image") {
        return '\
       <a href="#" id="{{_id}}" onclick="{{_onclick}}">\
-        {{#first md-thumburl}}\
+        {{#mkws-first md-thumburl}}\
          <img src="{{this}}" alt="{{../md-title}}"/>\
-        {{/first}}\
+        {{/mkws-first}}\
        <br/>\
       </a>\
 ';
index 5fae905..58c95a1 100644 (file)
@@ -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('<p>', obj[i], '</p>');
@@ -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;
 });