From a8c7a8602fff55df8279b9f56dfece875005a7fa Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Mon, 28 Mar 2016 19:44:28 -0700 Subject: [PATCH] Use partials --- build_tmpl.sh | 2 +- ext/bg/templates.js | 36 +++++++++++++++++++++++++++++++++++- ext/bg/yomichan.js | 2 ++ util/tmpl/defs.html | 7 ++----- util/tmpl/term.html | 3 +++ 5 files changed, 43 insertions(+), 7 deletions(-) create mode 100644 util/tmpl/term.html diff --git a/build_tmpl.sh b/build_tmpl.sh index f826e77d..303c5db6 100755 --- a/build_tmpl.sh +++ b/build_tmpl.sh @@ -1,2 +1,2 @@ #!/bin/sh -handlebars -m util/tmpl/* -f ext/bg/templates.js +handlebars util/tmpl/* -f ext/bg/templates.js diff --git a/ext/bg/templates.js b/ext/bg/templates.js index 41d4adc0..8ac5f8e5 100644 --- a/ext/bg/templates.js +++ b/ext/bg/templates.js @@ -1 +1,35 @@ -!function(){var n=Handlebars.template,a=Handlebars.templates=Handlebars.templates||{};a["defs.html"]=n({1:function(n,a,e,l,s){var i,r,o=null!=a?a:{},d=e.helperMissing,t="function",c=n.escapeExpression;return'
\n
'+c((r=null!=(r=e.expression||(null!=a?a.expression:a))?r:d,typeof r===t?r.call(o,{name:"expression",hash:{},data:s}):r))+"
\n"+(null!=(i=e["if"].call(o,null!=a?a.reading:a,{name:"if",hash:{},fn:n.program(2,s,0),inverse:n.noop,data:s}))?i:"")+'
'+c((r=null!=(r=e.glossary||(null!=a?a.glossary:a))?r:d,typeof r===t?r.call(o,{name:"glossary",hash:{},data:s}):r))+"
\n
\n"},2:function(n,a,e,l,s){var i;return'
'+n.escapeExpression((i=null!=(i=e.reading||(null!=a?a.reading:a))?i:e.helperMissing,"function"==typeof i?i.call(null!=a?a:{},{name:"reading",hash:{},data:s}):i))+"
\n"},compiler:[7,">= 4.0.0"],main:function(n,a,e,l,s){var i;return null!=(i=e.each.call(null!=a?a:{},null!=a?a.defs:a,{name:"each",hash:{},fn:n.program(1,s,0),inverse:n.noop,data:s}))?i:""},useData:!0})}(); \ No newline at end of file +(function() { + var template = Handlebars.template, templates = Handlebars.templates = Handlebars.templates || {}; +templates['defs.html'] = template({"1":function(container,depth0,helpers,partials,data) { + var stack1; + + return "
\n" + + ((stack1 = container.invokePartial(partials["term.html"],depth0,{"name":"term.html","data":data,"indent":" ","helpers":helpers,"partials":partials,"decorators":container.decorators})) != null ? stack1 : "") + + " " + + ((stack1 = helpers.unless.call(depth0 != null ? depth0 : {},(data && data.last),{"name":"unless","hash":{},"fn":container.program(2, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + "\n
\n"; +},"2":function(container,depth0,helpers,partials,data) { + return "
"; +},"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data) { + var stack1; + + return ((stack1 = helpers.each.call(depth0 != null ? depth0 : {},(depth0 != null ? depth0.defs : depth0),{"name":"each","hash":{},"fn":container.program(1, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : ""); +},"usePartial":true,"useData":true}); +templates['term.html'] = template({"1":function(container,depth0,helpers,partials,data) { + var helper; + + return "
" + + container.escapeExpression(((helper = (helper = helpers.reading || (depth0 != null ? depth0.reading : depth0)) != null ? helper : helpers.helperMissing),(typeof helper === "function" ? helper.call(depth0 != null ? depth0 : {},{"name":"reading","hash":{},"data":data}) : helper))) + + "
"; +},"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data) { + var stack1, helper, alias1=depth0 != null ? depth0 : {}, alias2=helpers.helperMissing, alias3="function", alias4=container.escapeExpression; + + return "
" + + alias4(((helper = (helper = helpers.expression || (depth0 != null ? depth0.expression : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"expression","hash":{},"data":data}) : helper))) + + "
\n" + + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.reading : depth0),{"name":"if","hash":{},"fn":container.program(1, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + "\n
" + + alias4(((helper = (helper = helpers.glossary || (depth0 != null ? depth0.glossary : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"glossary","hash":{},"data":data}) : helper))) + + "
\n"; +},"useData":true}); +})(); \ No newline at end of file diff --git a/ext/bg/yomichan.js b/ext/bg/yomichan.js index d845661f..8d989078 100644 --- a/ext/bg/yomichan.js +++ b/ext/bg/yomichan.js @@ -31,6 +31,8 @@ class Yomichan { chrome.runtime.onMessage.addListener(this.onMessage.bind(this)); chrome.browserAction.onClicked.addListener(this.onBrowserAction.bind(this)); + + Handlebars.partials = Handlebars.templates; } onMessage(request, sender, callback) { diff --git a/util/tmpl/defs.html b/util/tmpl/defs.html index 553a8c62..2fcc4ea9 100644 --- a/util/tmpl/defs.html +++ b/util/tmpl/defs.html @@ -1,9 +1,6 @@ {{#each defs}}
-
{{expression}}
- {{#if reading}} -
{{reading}}
- {{/if}} -
{{glossary}}
+ {{> term.html}} + {{#unless @last}}
{{/unless}}
{{/each}} diff --git a/util/tmpl/term.html b/util/tmpl/term.html new file mode 100644 index 00000000..e46e9d5b --- /dev/null +++ b/util/tmpl/term.html @@ -0,0 +1,3 @@ +
{{expression}}
+{{#if reading}}
{{reading}}
{{/if}} +
{{glossary}}