aboutsummaryrefslogtreecommitdiff
path: root/ext/bg
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2016-04-24 18:59:29 -0700
committerAlex Yatskov <alex@foosoft.net>2016-04-24 18:59:29 -0700
commitcac6fc1427106420b28777d94907bf27ab1995a3 (patch)
treee8ab59bed16d7e2ba1ed887ffb2b9ccee510f9a9 /ext/bg
parenta192a8d8b549d5979a427d86c51f94bb5f4be907 (diff)
Basic kanji output
Diffstat (limited to 'ext/bg')
-rw-r--r--ext/bg/js/dictionary.js13
-rw-r--r--ext/bg/js/templates.js13
-rw-r--r--ext/bg/js/translator.js6
-rw-r--r--ext/bg/js/yomichan.js2
4 files changed, 26 insertions, 8 deletions
diff --git a/ext/bg/js/dictionary.js b/ext/bg/js/dictionary.js
index 90a40ee5..cc7b507c 100644
--- a/ext/bg/js/dictionary.js
+++ b/ext/bg/js/dictionary.js
@@ -74,11 +74,16 @@ class Dictionary {
findKanji(kanji) {
const results = [];
- for (const name in this.termDicts) {
- const def = this.termDicts[name][kanji];
+ for (const name in this.kanjiDicts) {
+ const def = this.kanjiDicts[name][kanji];
if (def) {
- const [c, k, o, g] = def;
- results.push({id: index, character: c, kunyomi: k, onyomi: o, glossary: g});
+ const [k, o, g] = def;
+ results.push({
+ character: kanji,
+ kunyomi: k.split(' '),
+ onyomi: o.split(' '),
+ glossary: g
+ });
}
}
diff --git a/ext/bg/js/templates.js b/ext/bg/js/templates.js
index 1c14e569..1133e41a 100644
--- a/ext/bg/js/templates.js
+++ b/ext/bg/js/templates.js
@@ -34,6 +34,19 @@ templates['kanji-link.html'] = template({"compiler":[7,">= 4.0.0"],"main":functi
+ container.escapeExpression(((helper = (helper = helpers.kanji || (depth0 != null ? depth0.kanji : depth0)) != null ? helper : helpers.helperMissing),(typeof helper === "function" ? helper.call(depth0 != null ? depth0 : {},{"name":"kanji","hash":{},"data":data}) : helper)))
+ "</a>\n";
},"useData":true});
+templates['kanji-list.html'] = template({"1":function(container,depth0,helpers,partials,data) {
+ var stack1;
+
+ return "<div class=\"definition\">\n"
+ + ((stack1 = container.invokePartial(partials["kanji.html"],depth0,{"name":"kanji.html","data":data,"indent":" ","helpers":helpers,"partials":partials,"decorators":container.decorators})) != null ? stack1 : "")
+ + "</div>\n";
+},"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data) {
+ var stack1;
+
+ return ((stack1 = container.invokePartial(partials["header.html"],depth0,{"name":"header.html","data":data,"helpers":helpers,"partials":partials,"decorators":container.decorators})) != null ? stack1 : "")
+ + ((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 : "")
+ + ((stack1 = container.invokePartial(partials["footer.html"],depth0,{"name":"footer.html","data":data,"helpers":helpers,"partials":partials,"decorators":container.decorators})) != null ? stack1 : "");
+},"usePartial":true,"useData":true});
templates['term.html'] = template({"1":function(container,depth0,helpers,partials,data) {
var stack1, helper, options, alias1=depth0 != null ? depth0 : {}, alias2=helpers.helperMissing, alias3="function", buffer =
"<div class=\"term\"><ruby>";
diff --git a/ext/bg/js/translator.js b/ext/bg/js/translator.js
index 6be80581..606f6ec5 100644
--- a/ext/bg/js/translator.js
+++ b/ext/bg/js/translator.js
@@ -131,11 +131,11 @@ class Translator {
}
findKanji(text) {
- let results = [];
-
+ let results = [];
const processed = {};
+
for (const c of text) {
- if (!processed.has(c)) {
+ if (!processed[c]) {
results = results.concat(this.dictionary.findKanji(c));
processed[c] = true;
}
diff --git a/ext/bg/js/yomichan.js b/ext/bg/js/yomichan.js
index 7c802675..ac02f882 100644
--- a/ext/bg/js/yomichan.js
+++ b/ext/bg/js/yomichan.js
@@ -50,7 +50,7 @@ class Yomichan {
onMessage(request, sender, callback) {
const {action, data} = request, handlers = {
- findKanji: ({text}) => this.translator.onFindKanji(text),
+ findKanji: ({text}) => this.translator.findKanji(text),
findTerm: ({text}) => this.translator.findTerm(text),
getState: () => this.state,
getOptions: () => this.options,