aboutsummaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-07-26 16:50:56 -0400
committerGitHub <noreply@github.com>2020-07-26 16:50:56 -0400
commite153971cd4a5768a6c7dc9df36cf446cf298227d (patch)
tree388be84361ecb3c81608986110a35eeb2188e024 /ext
parent2ed2b22d49b60b814ab578ccdb6d86897be9a3e4 (diff)
Add eachUpTo function (#690)
Diffstat (limited to 'ext')
-rw-r--r--ext/bg/js/template-renderer.js20
1 files changed, 19 insertions, 1 deletions
diff --git a/ext/bg/js/template-renderer.js b/ext/bg/js/template-renderer.js
index 27e5e548..f6c4374b 100644
--- a/ext/bg/js/template-renderer.js
+++ b/ext/bg/js/template-renderer.js
@@ -69,7 +69,8 @@ class TemplateRenderer {
['sanitizeCssClass', this._sanitizeCssClass.bind(this)],
['regexReplace', this._regexReplace.bind(this)],
['regexMatch', this._regexMatch.bind(this)],
- ['mergeTags', this._mergeTags.bind(this)]
+ ['mergeTags', this._mergeTags.bind(this)],
+ ['eachUpTo', this._eachUpTo.bind(this)]
];
for (const [name, helper] of helpers) {
@@ -206,4 +207,21 @@ class TemplateRenderer {
return [...tags].join(', ');
}
+
+ _eachUpTo(context, iterable, maxCount, options) {
+ if (iterable) {
+ const results = [];
+ let any = false;
+ for (const entry of iterable) {
+ any = true;
+ if (results.length >= maxCount) { break; }
+ const processedEntry = options.fn(entry);
+ results.push(processedEntry);
+ }
+ if (any) {
+ return results.join('');
+ }
+ }
+ return options.inverse(context);
+ }
}