From 94a3083ce79f3cdf185add39bb933d695815b623 Mon Sep 17 00:00:00 2001 From: Mike Taylor Date: Thu, 29 May 2014 16:12:26 +0100 Subject: [PATCH] the "mkws-paragraphs" Handlebars helper now accepts an optional second argument specifying how many paragraphs to emit. --- src/mkws-handlebars.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/mkws-handlebars.js b/src/mkws-handlebars.js index 66c9f1c..537779e 100644 --- a/src/mkws-handlebars.js +++ b/src/mkws-handlebars.js @@ -8,9 +8,15 @@ Handlebars.registerHelper('mkws-json', function(obj) { // This is intended to handle paragraphs from Wikipedia, hence the // rather hacky code to remove numbered references. // -Handlebars.registerHelper('mkws-paragraphs', function(obj) { +Handlebars.registerHelper('mkws-paragraphs', function(obj, count) { var acc = []; - for (var i = 0; i < obj.length; i++) { + + // 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; + + for (var i = 0; i < count; i++) { acc.push('

', obj[i].replace(/\[[0-9,]+\]/g, ''), '

'); } return acc.join(''); -- 1.7.10.4