From a14caaeab92027c57545f9db40c29e6afac14993 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Fri, 26 Mar 2021 19:07:43 -0400 Subject: Add join and concat utility functions for template rendering (#1559) --- ext/js/templates/template-renderer.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) 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; + } } -- cgit v1.2.3