summaryrefslogtreecommitdiff
path: root/ext/bg/js/handlebars.js
diff options
context:
space:
mode:
Diffstat (limited to 'ext/bg/js/handlebars.js')
-rw-r--r--ext/bg/js/handlebars.js19
1 files changed, 17 insertions, 2 deletions
diff --git a/ext/bg/js/handlebars.js b/ext/bg/js/handlebars.js
index e0804986..66d5fa2b 100644
--- a/ext/bg/js/handlebars.js
+++ b/ext/bg/js/handlebars.js
@@ -75,7 +75,7 @@ function handlebarsMultiLine(options) {
return options.fn(this).split('\n').join('<br>');
}
-function handlebarsRender(template, data) {
+function handlebarsRegisterHelpers() {
if (Handlebars.partials !== Handlebars.templates) {
Handlebars.partials = Handlebars.templates;
Handlebars.registerHelper('dumpObject', handlebarsDumpObject);
@@ -84,6 +84,21 @@ function handlebarsRender(template, data) {
Handlebars.registerHelper('kanjiLinks', handlebarsKanjiLinks);
Handlebars.registerHelper('multiLine', handlebarsMultiLine);
}
+}
+
+function handlebarsRenderStatic(name, data) {
+ handlebarsRegisterHelpers();
+ return Handlebars.templates[name](data).trim();
+}
+
+function handlebarsRenderDynamic(template, data) {
+ handlebarsRegisterHelpers();
+
+ Handlebars.yomichan_cache = Handlebars.yomichan_cache || {};
+ let instance = Handlebars.yomichan_cache[template];
+ if (!instance) {
+ instance = Handlebars.yomichan_cache[template] = Handlebars.compile(template);
+ }
- return Handlebars.templates[template](data).trim();
+ return instance(data).trim();
}