projects
/
mkws-moved-to-github.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Simplify handling of optional count argument.
[mkws-moved-to-github.git]
/
src
/
mkws-handlebars.js
diff --git
a/src/mkws-handlebars.js
b/src/mkws-handlebars.js
index
66c9f1c
..
999c138
100644
(file)
--- a/
src/mkws-handlebars.js
+++ b/
src/mkws-handlebars.js
@@
-8,9
+8,16
@@
Handlebars.registerHelper('mkws-json', function(obj) {
// This is intended to handle paragraphs from Wikipedia, hence the
// rather hacky code to remove numbered references.
//
// 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 = [];
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 == 0 || count > obj.length) {
+ count = obj.length;
+ }
+
+ for (var i = 0; i < count; i++) {
acc.push('<p>', obj[i].replace(/\[[0-9,]+\]/g, ''), '</p>');
}
return acc.join('');
acc.push('<p>', obj[i].replace(/\[[0-9,]+\]/g, ''), '</p>');
}
return acc.join('');