The Credo widget's Reference subwidget is now passed a "paragraphs"
[mkws-moved-to-github.git] / src / mkws-handlebars.js
index 537779e..605282f 100644 (file)
@@ -12,9 +12,12 @@ Handlebars.registerHelper('mkws-paragraphs', function(obj, count) {
   var acc = [];
 
   // For some reason, Handlebars provides the value
-  // {"hash":{},"data":{}} for undefined parameters
-  if (count.hasOwnProperty('hash')) count = undefined;
-  if (!count || count > obj.length) count = obj.length;
+  // {"hash":{},"data":{}} for parameters that are not provided. So we
+  // have to be prepared for actual numbers, explicitly undefined
+  // values and this dumb magic value.
+  if (count === undefined || count.hasOwnProperty('hash') || count == 0 || count > obj.length) {
+    count = obj.length;
+  }
 
   for (var i = 0; i < count; i++) {
     acc.push('<p>', obj[i].replace(/\[[0-9,]+\]/g, ''), '</p>');