diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2021-03-26 19:07:43 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-26 19:07:43 -0400 |
commit | a14caaeab92027c57545f9db40c29e6afac14993 (patch) | |
tree | 0323f1a30291717602abe56247eb5f61ddf5f529 | |
parent | a756ce85c0cdeedcdf9bbe784c0fd039ac1ce92e (diff) |
Add join and concat utility functions for template rendering (#1559)
-rw-r--r-- | ext/js/templates/template-renderer.js | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/ext/js/templates/template-renderer.js b/ext/js/templates/template-renderer.js index 2db9e177..f72740d5 100644 --- a/ext/js/templates/template-renderer.js +++ b/ext/js/templates/template-renderer.js @@ -108,7 +108,9 @@ class TemplateRenderer { ['noop', this._noop.bind(this)], ['isMoraPitchHigh', this._isMoraPitchHigh.bind(this)], ['getKanaMorae', this._getKanaMorae.bind(this)], - ['typeof', this._getTypeof.bind(this)] + ['typeof', this._getTypeof.bind(this)], + ['join', this._join.bind(this)], + ['concat', this._concat.bind(this)] ]; for (const [name, helper] of helpers) { @@ -414,4 +416,16 @@ class TemplateRenderer { const value = (ii > 0 ? args[0] : args[ii].fn(context)); return typeof value; } + + _join(context, ...args) { + return args.length > 1 ? args.slice(1, args.length - 1).flat().join(args[0]) : ''; + } + + _concat(context, ...args) { + let result = ''; + for (let i = 0, ii = args.length - 1; i < ii; ++i) { + result += args[i]; + } + return result; + } } |