diff options
author | Alex Yatskov <alex@foosoft.net> | 2017-09-11 16:56:27 -0700 |
---|---|---|
committer | Alex Yatskov <alex@foosoft.net> | 2017-09-11 16:56:27 -0700 |
commit | 3a1aad07d61411f634e86f905babd6fbbac2eae1 (patch) | |
tree | f343fc427c0c791823a39a482dc3d1cd35d34253 /ext/bg/js/handlebars.js | |
parent | 65b679caeb7ae7261ea6f2ba76d1b14ff1d68c5c (diff) | |
parent | 2eb85cb835a4aece7839eba25c0030e9eb186f85 (diff) |
Merge branch 'master' into firefox-amo
Diffstat (limited to 'ext/bg/js/handlebars.js')
-rw-r--r-- | ext/bg/js/handlebars.js | 19 |
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(); } |