From a9fcc0cde6a09872e038e4aa4600d5cd80a71374 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sun, 27 Mar 2016 20:00:41 -0700 Subject: Switch to handlebars for templating --- ext/bg/templates.js | 1 + ext/bg/yomichan.js | 9 +++++---- 2 files changed, 6 insertions(+), 4 deletions(-) create mode 100644 ext/bg/templates.js (limited to 'ext/bg') diff --git a/ext/bg/templates.js b/ext/bg/templates.js new file mode 100644 index 00000000..72c9653b --- /dev/null +++ b/ext/bg/templates.js @@ -0,0 +1 @@ +!function(){var a=Handlebars.template,n=Handlebars.templates=Handlebars.templates||{};n["defs.html"]=a({1:function(a,n,s,e,l){var r,i=null!=n?n:{},o=s.helperMissing,p="function",t=a.escapeExpression;return'
\n '+t((r=null!=(r=s.expression||(null!=n?n.expression:n))?r:o,typeof r===p?r.call(i,{name:"expression",hash:{},data:l}):r))+'\n '+t((r=null!=(r=s.reading||(null!=n?n.reading:n))?r:o,typeof r===p?r.call(i,{name:"reading",hash:{},data:l}):r))+'\n '+t((r=null!=(r=s.glossary||(null!=n?n.glossary:n))?r:o,typeof r===p?r.call(i,{name:"glossary",hash:{},data:l}):r))+"\n
\n"},compiler:[7,">= 4.0.0"],main:function(a,n,s,e,l){var r;return null!=(r=s.each.call(null!=n?n:{},null!=n?n.defs:n,{name:"each",hash:{},fn:a.program(1,l,0),inverse:a.noop,data:l}))?r:""},useData:!0})}(); \ No newline at end of file diff --git a/ext/bg/yomichan.js b/ext/bg/yomichan.js index 9a049f77..d845661f 100644 --- a/ext/bg/yomichan.js +++ b/ext/bg/yomichan.js @@ -19,7 +19,6 @@ class Yomichan { constructor() { - this.translator = new Translator(); this.res = { rules: 'bg/data/rules.json', edict: 'bg/data/edict.json', @@ -27,6 +26,7 @@ class Yomichan { kanjidic: 'bg/data/kanjidic.json' }; + this.translator = new Translator(); this.updateState('disabled'); chrome.runtime.onMessage.addListener(this.onMessage.bind(this)); @@ -36,9 +36,10 @@ class Yomichan { onMessage(request, sender, callback) { const {action, data} = request; const handler = { - findKanji: ({text}) => this.translator.onFindKanji(text), - findTerm: ({text}) => this.translator.findTerm(text), - getState: () => this.state + findKanji: ({text}) => this.translator.onFindKanji(text), + findTerm: ({text}) => this.translator.findTerm(text), + getState: () => this.state, + renderTemplate: ({data, template}) => Handlebars.templates[template](data) }[action]; if (handler !== null) { -- cgit v1.2.3