aboutsummaryrefslogtreecommitdiff
path: root/ext/bg/js/handlebars.js
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2017-09-09 12:59:49 -0700
committerAlex Yatskov <alex@foosoft.net>2017-09-09 12:59:49 -0700
commit5f46006e8da1d51a66291f25a2bc75959ec81efd (patch)
tree1a0b4d7948273ae95f8517cd77fc6d9e008f0f05 /ext/bg/js/handlebars.js
parent9a5a9aa47fd9a6c7ea6830a821689321e8fd9fbb (diff)
scrap sandbox
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();
}