From be87e916df3a2f26e32e3861ce3430aaaa2ea67e Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sun, 10 Sep 2017 21:49:37 -0700 Subject: wip on new database --- ext/bg/js/database.js | 174 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 103 insertions(+), 71 deletions(-) (limited to 'ext/bg') diff --git a/ext/bg/js/database.js b/ext/bg/js/database.js index e00cb7a3..c346da4e 100644 --- a/ext/bg/js/database.js +++ b/ext/bg/js/database.js @@ -24,33 +24,23 @@ class Database { this.tagCache = {}; } - async sanitize() { - try { - const db = new Dexie('dict'); - await db.open(); - db.close(); - if (db.verno !== this.version) { - await db.delete(); - } - } catch(e) { - // NOP - } - } - async prepare() { if (this.db) { throw 'database already initialized'; } - await this.sanitize(); - this.db = new Dexie('dict'); - this.db.version(this.version).stores({ - terms: '++id,dictionary,expression,reading', - kanji: '++,dictionary,character', - tagMeta: '++,dictionary', + this.db.version(2).stores({ + terms: '++id,dictionary,expression,reading', + kanji: '++,dictionary,character', + tagMeta: '++,dictionary', dictionaries: '++,title,version' }); + this.db.version(3).stores({ + termFreq: '++,dictionary,expression', + kanjiFreq: '++,dictionary,character', + tagMeta: '++,dictionary' + }); await this.db.open(); } @@ -154,35 +144,32 @@ class Database { return Promise.reject('database not initialized'); } - let summary = null; - const indexLoaded = async (title, version, revision, tagMeta, hasTerms, hasKanji) => { - summary = {title, version, revision, hasTerms, hasKanji}; - - const count = await this.db.dictionaries.where('title').equals(title).count(); - if (count > 0) { - throw `dictionary "${title}" is already imported`; - } + // const rows = []; + // for (const tag in tagMeta || {}) { + // const meta = tagMeta[tag]; + // const row = dictTagSanitize({ + // name: tag, + // category: meta.category, + // notes: meta.notes, + // order: meta.order, + // dictionary: title + // }); - await this.db.dictionaries.add({title, version, revision, hasTerms, hasKanji}); + // rows.push(row); + // } - const rows = []; - for (const tag in tagMeta || {}) { - const meta = tagMeta[tag]; - const row = dictTagSanitize({ - name: tag, - category: meta.category, - notes: meta.notes, - order: meta.order, - dictionary: title - }); + // await this.db.tagMeta.bulkAdd(rows); - rows.push(row); + const indexDataLoaded = async summary => { + const count = await this.db.dictionaries.where('title').equals(summary.title).count(); + if (count > 0) { + throw `dictionary "${title}" is already imported`; } - await this.db.tagMeta.bulkAdd(rows); + await this.db.dictionaries.add(summary); }; - const termsLoaded = async (title, entries, total, current) => { + const termDataLoaded = async (title, entries, total, current) => { if (callback) { callback(total, current); } @@ -203,7 +190,7 @@ class Database { await this.db.terms.bulkAdd(rows); }; - const kanjiLoaded = async (title, entries, total, current) => { + const kanjiDataLoaded = async (title, entries, total, current) => { if (callback) { callback(total, current); } @@ -223,11 +210,26 @@ class Database { await this.db.kanji.bulkAdd(rows); }; - await Database.importDictionaryZip(archive, indexLoaded, termsLoaded, kanjiLoaded); - return summary; + return await Database.importDictionaryZip( + archive, + indexDataLoaded, + termDataLoaded, + null, + kanjiDataLoaded, + null, + null + ); } - static async importDictionaryZip(archive, indexLoaded, termsLoaded, kanjiLoaded) { + static async importDictionaryZip( + archive, + indexDataLoaded, + termDataLoaded, + termFreqDataLoaded, + kanjiDataLoaded, + kanjiFreqDataLoaded, + tagDataLoaded + ) { const files = (await JSZip.loadAsync(archive)).files; const indexFile = files['index.json']; @@ -240,36 +242,66 @@ class Database { throw 'unrecognized dictionary format'; } - await indexLoaded( - index.title, - index.version, - index.revision, - index.tagMeta || {}, - index.termBanks > 0, - index.kanjiBanks > 0 - ); - - const banksTotal = index.termBanks + index.kanjiBanks; - let banksLoaded = 0; + const summary = {title: index.title, version: index.version, revision: index.revision}; + if (indexDataLoaded) { + await indexDataLoaded(summary); + } - for (let i = 1; i <= index.termBanks; ++i) { - const bankFile = files[`term_bank_${i}.json`]; - if (bankFile) { - const bank = JSON.parse(await bankFile.async('string')); - await termsLoaded(index.title, bank, banksTotal, banksLoaded++); - } else { - throw 'missing term bank file'; + if (tagDataLoaded && index.tagMeta) { + const tags = []; + for (const name of index.tagMeta) { + const tag = index.tagMeta; + tags.push([name, tag.category, tag.order, tag.notes]); } + + tagDataLoaded(tags); } - for (let i = 1; i <= index.kanjiBanks; ++i) { - const bankFile = files[`kanji_bank_${i}.json`]; - if (bankFile) { - const bank = JSON.parse(await bankFile.async('string')); - await kanjiLoaded(index.title, bank, banksTotal, banksLoaded++); - } else { - throw 'missing kanji bank file'; + const buildTermBankName = index => `term_bank_${index + 1}.json`; + const buildTermFreqBankName = index => `termfreq_bank_${index + 1}.json`; + const buildKanjiBankName = index => `kanji_bank_${index + 1}.json`; + const buildKanjiFreqBankName = index => `kanjifreq_bank_${index + 1}.json`; + const buildTagBankName = index => `tag_bank_${index + 1}.json`; + + const countBanks = namer => { + let count = 0; + while (files[namer(count)]) { + ++count; } - } + + return count; + }; + + const termBankCount = countBanks(buildTermBankName); + const kanjiBankCount = countBanks(buildTermBankName); + const termFreqBankCount = countBanks(buildTermBankName); + const kanjiFreqBankCount = countBanks(buildTermBankName); + const tagBankCount = countBanks(buildTermBankName); + + let bankLoadedCount = 0; + const bankTotalCount = + termBankCount + + hanjiBankCount + + termFreqBankCount + + kanjiFreqBankCount + + tagBankCount; + + const loadBank = async (namer, count, callback) => { + if (callback) { + for (let i = 0; i < count; ++i) { + const bankFile = namer(i); + const bank = JSON.parse(await bankFile.async('string')); + await callback(index.title, bank, bankTotalCount, bankLoadedCount++); + } + } + }; + + await loadBank(buildTermBankName, termBankCount, termDataLoaded); + await loadBank(buildTermFreqBankName, termFreqBankCount, termFreqDataLoaded); + await loadBank(buildKanjiBankName, kanjiBankCount, kanjiDataLoaded); + await loadBank(buildKanjiFreqBankName, kanjiFreqBankCount, kanjiFreqDataLoaded); + await loadBank(buildTagBankName, tagBankCount, tagDataLoaded); + + return summary; } } -- cgit v1.2.3 From af93d446de6548eb3753a5ca36c42d9c8c8a3730 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Tue, 12 Sep 2017 13:29:13 -0700 Subject: fix dictionary importing --- ext/bg/js/database.js | 73 +++++++++++++++++++++++++++------------------------ 1 file changed, 39 insertions(+), 34 deletions(-) (limited to 'ext/bg') diff --git a/ext/bg/js/database.js b/ext/bg/js/database.js index c346da4e..71179ed6 100644 --- a/ext/bg/js/database.js +++ b/ext/bg/js/database.js @@ -144,22 +144,6 @@ class Database { return Promise.reject('database not initialized'); } - // const rows = []; - // for (const tag in tagMeta || {}) { - // const meta = tagMeta[tag]; - // const row = dictTagSanitize({ - // name: tag, - // category: meta.category, - // notes: meta.notes, - // order: meta.order, - // dictionary: title - // }); - - // rows.push(row); - // } - - // await this.db.tagMeta.bulkAdd(rows); - const indexDataLoaded = async summary => { const count = await this.db.dictionaries.where('title').equals(summary.title).count(); if (count > 0) { @@ -210,6 +194,27 @@ class Database { await this.db.kanji.bulkAdd(rows); }; + const tagDataLoaded = async (title, entries, total, current) => { + if (callback) { + callback(total, current); + } + + const rows = []; + for (const [name, category, order, notes] of entries) { + const row = dictTagSanitize({ + name, + category, + order, + notes, + dictionary: title + }); + + rows.push(row); + } + + await this.db.tagMeta.bulkAdd(rows); + }; + return await Database.importDictionaryZip( archive, indexDataLoaded, @@ -217,7 +222,7 @@ class Database { null, kanjiDataLoaded, null, - null + tagDataLoaded ); } @@ -247,16 +252,6 @@ class Database { await indexDataLoaded(summary); } - if (tagDataLoaded && index.tagMeta) { - const tags = []; - for (const name of index.tagMeta) { - const tag = index.tagMeta; - tags.push([name, tag.category, tag.order, tag.notes]); - } - - tagDataLoaded(tags); - } - const buildTermBankName = index => `term_bank_${index + 1}.json`; const buildTermFreqBankName = index => `termfreq_bank_${index + 1}.json`; const buildKanjiBankName = index => `kanji_bank_${index + 1}.json`; @@ -273,23 +268,33 @@ class Database { }; const termBankCount = countBanks(buildTermBankName); - const kanjiBankCount = countBanks(buildTermBankName); - const termFreqBankCount = countBanks(buildTermBankName); - const kanjiFreqBankCount = countBanks(buildTermBankName); - const tagBankCount = countBanks(buildTermBankName); + const termFreqBankCount = countBanks(buildTermFreqBankName); + const kanjiBankCount = countBanks(buildKanjiBankName); + const kanjiFreqBankCount = countBanks(buildKanjiFreqBankName); + const tagBankCount = countBanks(buildTagBankName); let bankLoadedCount = 0; - const bankTotalCount = + let bankTotalCount = termBankCount + - hanjiBankCount + termFreqBankCount + + kanjiBankCount + kanjiFreqBankCount + tagBankCount; + if (tagDataLoaded && index.tagMeta) { + const bank = []; + for (const name in index.tagMeta) { + const tag = index.tagMeta[name]; + bank.push([name, tag.category, tag.order, tag.notes]); + } + + tagDataLoaded(index.title, bank, ++bankTotalCount, bankLoadedCount++); + } + const loadBank = async (namer, count, callback) => { if (callback) { for (let i = 0; i < count; ++i) { - const bankFile = namer(i); + const bankFile = files[namer(i)]; const bank = JSON.parse(await bankFile.async('string')); await callback(index.title, bank, bankTotalCount, bankLoadedCount++); } -- cgit v1.2.3 From 28364b97b0dcc72ecde43aad32f8c58561895382 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Tue, 12 Sep 2017 14:12:40 -0700 Subject: hopeful workaround to firefox crash --- ext/bg/js/database.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'ext/bg') diff --git a/ext/bg/js/database.js b/ext/bg/js/database.js index 71179ed6..4a4f5e82 100644 --- a/ext/bg/js/database.js +++ b/ext/bg/js/database.js @@ -171,7 +171,7 @@ class Database { }); } - await this.db.terms.bulkAdd(rows); + await this.db.terms.bulkAdd(utilIsolate(rows)); }; const kanjiDataLoaded = async (title, entries, total, current) => { @@ -191,7 +191,7 @@ class Database { }); } - await this.db.kanji.bulkAdd(rows); + await this.db.kanji.bulkAdd(utilIsolate(rows)); }; const tagDataLoaded = async (title, entries, total, current) => { @@ -212,7 +212,7 @@ class Database { rows.push(row); } - await this.db.tagMeta.bulkAdd(rows); + await this.db.tagMeta.bulkAdd(utilIsolate(rows)); }; return await Database.importDictionaryZip( -- cgit v1.2.3 From 3b29893072b89b75c7fd82b9138b09572ec6248c Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Tue, 12 Sep 2017 18:29:16 -0700 Subject: add frequency table support for terms --- ext/bg/js/database.js | 34 +++++++++++++++++++++++++++++++++- ext/bg/js/translator.js | 7 +++++++ 2 files changed, 40 insertions(+), 1 deletion(-) (limited to 'ext/bg') diff --git a/ext/bg/js/database.js b/ext/bg/js/database.js index 4a4f5e82..ea55416c 100644 --- a/ext/bg/js/database.js +++ b/ext/bg/js/database.js @@ -87,6 +87,21 @@ class Database { return results; } + async findTermFreq(term, titles) { + if (!this.db) { + throw 'database not initialized'; + } + + const results = []; + await this.db.termFreq.where('expression').equals(term).each(row => { + if (titles.includes(row.dictionary)) { + results.push({frequency: row.frequency, dictionary: row.dictionary}); + } + }); + + return results; + } + async findKanji(kanji, titles) { if (!this.db) { return Promise.reject('database not initialized'); @@ -174,6 +189,23 @@ class Database { await this.db.terms.bulkAdd(utilIsolate(rows)); }; + const termFreqDataLoaded = async (title, entries, total, current) => { + if (callback) { + callback(total, current); + } + + const rows = []; + for (const [expression, frequency] of entries) { + rows.push({ + expression, + frequency, + dictionary: title + }); + } + + await this.db.termFreq.bulkAdd(utilIsolate(rows)); + }; + const kanjiDataLoaded = async (title, entries, total, current) => { if (callback) { callback(total, current); @@ -219,7 +251,7 @@ class Database { archive, indexDataLoaded, termDataLoaded, - null, + termFreqDataLoaded, kanjiDataLoaded, null, tagDataLoaded diff --git a/ext/bg/js/translator.js b/ext/bg/js/translator.js index 1be485c7..3b9a1128 100644 --- a/ext/bg/js/translator.js +++ b/ext/bg/js/translator.js @@ -62,7 +62,14 @@ class Translator { for (const definition of deinflection.definitions) { const tags = definition.tags.map(tag => dictTagBuild(tag, definition.tagMeta)); tags.push(dictTagBuildSource(definition.dictionary)); + + let frequencies = await this.database.findTermFreq(definition.expression, titles); + if (frequencies.length === 0) { + frequencies = await this.database.findTermFreq(definition.reading, titles); + } + definitions.push({ + frequencies, source: deinflection.source, reasons: deinflection.reasons, score: definition.score, -- cgit v1.2.3 From 79b99131f69ab778e4c8203caa0894e8accde436 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Tue, 12 Sep 2017 20:20:03 -0700 Subject: add frequency table support for kanji --- ext/bg/js/database.js | 42 +++++++++++++++++++++++++++++++++++++----- ext/bg/js/settings.js | 4 +++- ext/bg/js/translator.js | 1 + 3 files changed, 41 insertions(+), 6 deletions(-) (limited to 'ext/bg') diff --git a/ext/bg/js/database.js b/ext/bg/js/database.js index ea55416c..1760a70a 100644 --- a/ext/bg/js/database.js +++ b/ext/bg/js/database.js @@ -129,6 +129,21 @@ class Database { return results; } + async findKanjiFreq(kanji, titles) { + if (!this.db) { + throw 'database not initialized'; + } + + const results = []; + await this.db.kanjiFreq.where('character').equals(kanji).each(row => { + if (titles.includes(row.dictionary)) { + results.push({frequency: row.frequency, dictionary: row.dictionary}); + } + }); + + return results; + } + async cacheTagMeta(titles) { if (!this.db) { throw 'database not initialized'; @@ -186,7 +201,7 @@ class Database { }); } - await this.db.terms.bulkAdd(utilIsolate(rows)); + await this.db.terms.bulkAdd(rows); }; const termFreqDataLoaded = async (title, entries, total, current) => { @@ -203,7 +218,7 @@ class Database { }); } - await this.db.termFreq.bulkAdd(utilIsolate(rows)); + await this.db.termFreq.bulkAdd(rows); }; const kanjiDataLoaded = async (title, entries, total, current) => { @@ -223,7 +238,24 @@ class Database { }); } - await this.db.kanji.bulkAdd(utilIsolate(rows)); + await this.db.kanji.bulkAdd(rows); + }; + + const kanjiFreqDataLoaded = async (title, entries, total, current) => { + if (callback) { + callback(total, current); + } + + const rows = []; + for (const [character, frequency] of entries) { + rows.push({ + character, + frequency, + dictionary: title + }); + } + + await this.db.kanjiFreq.bulkAdd(rows); }; const tagDataLoaded = async (title, entries, total, current) => { @@ -244,7 +276,7 @@ class Database { rows.push(row); } - await this.db.tagMeta.bulkAdd(utilIsolate(rows)); + await this.db.tagMeta.bulkAdd(rows); }; return await Database.importDictionaryZip( @@ -253,7 +285,7 @@ class Database { termDataLoaded, termFreqDataLoaded, kanjiDataLoaded, - null, + kanjiFreqDataLoaded, tagDataLoaded ); } diff --git a/ext/bg/js/settings.js b/ext/bg/js/settings.js index 55b469d0..b5ac8c8b 100644 --- a/ext/bg/js/settings.js +++ b/ext/bg/js/settings.js @@ -82,7 +82,9 @@ function formUpdateVisibility(options) { const debug = $('#debug'); if (options.general.debugInfo) { - const text = JSON.stringify(options, null, 4); + const temp = utilIsolate(options); + temp.anki.fieldTemplates = '...'; + const text = JSON.stringify(temp, null, 4); debug.html(handlebarsEscape(text)); debug.show(); } else { diff --git a/ext/bg/js/translator.js b/ext/bg/js/translator.js index 3b9a1128..1e79b6fc 100644 --- a/ext/bg/js/translator.js +++ b/ext/bg/js/translator.js @@ -127,6 +127,7 @@ class Translator { const tags = definition.tags.map(tag => dictTagBuild(tag, definition.tagMeta)); tags.push(dictTagBuildSource(definition.dictionary)); definition.tags = dictTagsSort(tags); + definition.frequencies = await this.database.findKanjiFreq(definition.character, titles); } return definitions; -- cgit v1.2.3 From 219eeb6e81aba136af109770974f42b703bdae60 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Wed, 13 Sep 2017 15:41:06 -0700 Subject: cleanup --- ext/bg/js/database.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'ext/bg') diff --git a/ext/bg/js/database.js b/ext/bg/js/database.js index 1760a70a..cd53f681 100644 --- a/ext/bg/js/database.js +++ b/ext/bg/js/database.js @@ -20,7 +20,6 @@ class Database { constructor() { this.db = null; - this.version = 2; this.tagCache = {}; } @@ -177,7 +176,7 @@ class Database { const indexDataLoaded = async summary => { const count = await this.db.dictionaries.where('title').equals(summary.title).count(); if (count > 0) { - throw `dictionary "${title}" is already imported`; + throw `dictionary "${summary.title}" is already imported`; } await this.db.dictionaries.add(summary); @@ -299,9 +298,9 @@ class Database { kanjiFreqDataLoaded, tagDataLoaded ) { - const files = (await JSZip.loadAsync(archive)).files; + const zip = await JSZip.loadAsync(archive); - const indexFile = files['index.json']; + const indexFile = zip.files['index.json']; if (!indexFile) { throw 'no dictionary index found in archive'; } @@ -324,7 +323,7 @@ class Database { const countBanks = namer => { let count = 0; - while (files[namer(count)]) { + while (zip.files[namer(count)]) { ++count; } @@ -358,7 +357,7 @@ class Database { const loadBank = async (namer, count, callback) => { if (callback) { for (let i = 0; i < count; ++i) { - const bankFile = files[namer(i)]; + const bankFile = zip.files[namer(i)]; const bank = JSON.parse(await bankFile.async('string')); await callback(index.title, bank, bankTotalCount, bankLoadedCount++); } -- cgit v1.2.3 From ba8451f429d1055f91f79473f32204efb2c041db Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Wed, 13 Sep 2017 15:45:53 -0700 Subject: cleanup --- ext/bg/js/translator.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'ext/bg') diff --git a/ext/bg/js/translator.js b/ext/bg/js/translator.js index 1e79b6fc..a2322e36 100644 --- a/ext/bg/js/translator.js +++ b/ext/bg/js/translator.js @@ -51,10 +51,10 @@ class Translator { const cache = {}; const titles = Object.keys(dictionaries); - let deinflections = await this.findTermsDeinflected(text, titles, cache); + let deinflections = await this.findTermDeinflections(text, titles, cache); const textHiragana = jpKatakanaToHiragana(text); if (text !== textHiragana) { - deinflections = deinflections.concat(await this.findTermsDeinflected(textHiragana, titles, cache)); + deinflections = deinflections.concat(await this.findTermDeinflections(textHiragana, titles, cache)); } let definitions = []; @@ -94,7 +94,7 @@ class Translator { return {length, definitions}; } - async findTermsDeinflected(text, titles, cache) { + async findTermDeinflections(text, titles, cache) { const definer = async term => { if (cache.hasOwnProperty(term)) { return cache[term]; -- cgit v1.2.3 From 13961e6a10554fdc43c5b1b66f28ea72d2fc21b6 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Wed, 13 Sep 2017 16:42:04 -0700 Subject: better tag handling --- ext/bg/js/database.js | 32 +++++++++----------------------- ext/bg/js/translator.js | 21 +++++++++++++++++++-- 2 files changed, 28 insertions(+), 25 deletions(-) (limited to 'ext/bg') diff --git a/ext/bg/js/database.js b/ext/bg/js/database.js index cd53f681..6ae36db2 100644 --- a/ext/bg/js/database.js +++ b/ext/bg/js/database.js @@ -20,7 +20,6 @@ class Database { constructor() { this.db = null; - this.tagCache = {}; } async prepare() { @@ -38,7 +37,7 @@ class Database { this.db.version(3).stores({ termFreq: '++,dictionary,expression', kanjiFreq: '++,dictionary,character', - tagMeta: '++,dictionary' + tagMeta: '++,dictionary,name' }); await this.db.open(); @@ -52,7 +51,6 @@ class Database { this.db.close(); await this.db.delete(); this.db = null; - this.tagCache = {}; await this.prepare(); } @@ -78,11 +76,6 @@ class Database { } }); - await this.cacheTagMeta(titles); - for (const result of results) { - result.tagMeta = this.tagCache[result.dictionary] || {}; - } - return results; } @@ -120,11 +113,6 @@ class Database { } }); - await this.cacheTagMeta(titles); - for (const result of results) { - result.tagMeta = this.tagCache[result.dictionary] || {}; - } - return results; } @@ -143,21 +131,19 @@ class Database { return results; } - async cacheTagMeta(titles) { + async findTag(name, titles) { if (!this.db) { throw 'database not initialized'; } - for (const title of titles) { - if (!this.tagCache[title]) { - const tagMeta = {}; - await this.db.tagMeta.where('dictionary').equals(title).each(row => { - tagMeta[row.name] = {category: row.category, notes: row.notes, order: row.order}; - }); - - this.tagCache[title] = tagMeta; + let result = null; + await this.db.tagMeta.where('name').equals(name).each(row => { + if (titles.includes(row.dictionary)) { + result = row; } - } + }); + + return result; } async getDictionaries() { diff --git a/ext/bg/js/translator.js b/ext/bg/js/translator.js index a2322e36..99147618 100644 --- a/ext/bg/js/translator.js +++ b/ext/bg/js/translator.js @@ -60,7 +60,7 @@ class Translator { let definitions = []; for (const deinflection of deinflections) { for (const definition of deinflection.definitions) { - const tags = definition.tags.map(tag => dictTagBuild(tag, definition.tagMeta)); + const tags = await this.buildTags(definition.tags, titles); tags.push(dictTagBuildSource(definition.dictionary)); let frequencies = await this.database.findTermFreq(definition.expression, titles); @@ -124,12 +124,29 @@ class Translator { } for (const definition of definitions) { - const tags = definition.tags.map(tag => dictTagBuild(tag, definition.tagMeta)); + const tags = await this.buildTags(definition.tags, titles); tags.push(dictTagBuildSource(definition.dictionary)); + definition.tags = dictTagsSort(tags); definition.frequencies = await this.database.findKanjiFreq(definition.character, titles); } return definitions; } + + async buildTags(names, titles) { + const results = []; + for (const name of names) { + const meta = await this.database.findTag(name.split(':')[0], titles); + + const result = {name}; + for (const prop in meta || {}) { + result[prop] = meta[prop]; + } + + results.push(dictTagSanitize(result)); + } + + return results; + } } -- cgit v1.2.3 From 4d4b819d6c197df6e0f91ba170d0ee909dfcb5c9 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Wed, 13 Sep 2017 17:26:02 -0700 Subject: tag caching --- ext/bg/js/database.js | 22 +++++++++++++++------- ext/bg/js/dictionary.js | 10 ---------- ext/bg/js/translator.js | 8 ++++---- 3 files changed, 19 insertions(+), 21 deletions(-) (limited to 'ext/bg') diff --git a/ext/bg/js/database.js b/ext/bg/js/database.js index 6ae36db2..1b171b03 100644 --- a/ext/bg/js/database.js +++ b/ext/bg/js/database.js @@ -20,6 +20,7 @@ class Database { constructor() { this.db = null; + this.tagCache = {}; } async prepare() { @@ -51,6 +52,7 @@ class Database { this.db.close(); await this.db.delete(); this.db = null; + this.tagCache = {}; await this.prepare(); } @@ -131,17 +133,23 @@ class Database { return results; } - async findTag(name, titles) { + async findTag(name, title) { if (!this.db) { throw 'database not initialized'; } - let result = null; - await this.db.tagMeta.where('name').equals(name).each(row => { - if (titles.includes(row.dictionary)) { - result = row; - } - }); + this.tagCache[title] = this.tagCache[title] || {}; + + let result = this.tagCache[title][name]; + if (!result) { + await this.db.tagMeta.where('name').equals(name).each(row => { + if (title === row.dictionary) { + result = row; + } + }); + + this.tagCache[title][name] = result; + } return result; } diff --git a/ext/bg/js/dictionary.js b/ext/bg/js/dictionary.js index e749390f..1cd1a846 100644 --- a/ext/bg/js/dictionary.js +++ b/ext/bg/js/dictionary.js @@ -148,16 +148,6 @@ function dictTagBuildSource(name) { return dictTagSanitize({name, category: 'dictionary', order: 100}); } -function dictTagBuild(name, meta) { - const tag = {name}; - const symbol = name.split(':')[0]; - for (const prop in meta[symbol] || {}) { - tag[prop] = meta[symbol][prop]; - } - - return dictTagSanitize(tag); -} - function dictTagSanitize(tag) { tag.name = tag.name || 'untitled'; tag.category = tag.category || 'default'; diff --git a/ext/bg/js/translator.js b/ext/bg/js/translator.js index 99147618..5de99e8e 100644 --- a/ext/bg/js/translator.js +++ b/ext/bg/js/translator.js @@ -60,7 +60,7 @@ class Translator { let definitions = []; for (const deinflection of deinflections) { for (const definition of deinflection.definitions) { - const tags = await this.buildTags(definition.tags, titles); + const tags = await this.buildTags(definition.tags, definition.dictionary); tags.push(dictTagBuildSource(definition.dictionary)); let frequencies = await this.database.findTermFreq(definition.expression, titles); @@ -124,7 +124,7 @@ class Translator { } for (const definition of definitions) { - const tags = await this.buildTags(definition.tags, titles); + const tags = await this.buildTags(definition.tags, definition.dictionary); tags.push(dictTagBuildSource(definition.dictionary)); definition.tags = dictTagsSort(tags); @@ -134,10 +134,10 @@ class Translator { return definitions; } - async buildTags(names, titles) { + async buildTags(names, title) { const results = []; for (const name of names) { - const meta = await this.database.findTag(name.split(':')[0], titles); + const meta = await this.database.findTag(name.split(':')[0], title); const result = {name}; for (const prop in meta || {}) { -- cgit v1.2.3 From 04f9a0f54316d123628168aa5a15e8e48907d783 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Wed, 13 Sep 2017 17:30:45 -0700 Subject: cleanup --- ext/bg/js/database.js | 2 +- ext/bg/js/settings.js | 2 +- ext/bg/js/util.js | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'ext/bg') diff --git a/ext/bg/js/database.js b/ext/bg/js/database.js index 1b171b03..630243b2 100644 --- a/ext/bg/js/database.js +++ b/ext/bg/js/database.js @@ -154,7 +154,7 @@ class Database { return result; } - async getDictionaries() { + async getTitles() { if (this.db) { return this.db.dictionaries.toArray(); } else { diff --git a/ext/bg/js/settings.js b/ext/bg/js/settings.js index b5ac8c8b..a2580c35 100644 --- a/ext/bg/js/settings.js +++ b/ext/bg/js/settings.js @@ -213,7 +213,7 @@ async function dictionaryGroupsPopulate(options) { const dictGroups = $('#dict-groups').empty(); const dictWarning = $('#dict-warning').hide(); - const dictRows = await utilDatabaseGetDictionaries(); + const dictRows = await utilDatabaseGetTitles(); if (dictRows.length === 0) { dictWarning.show(); } diff --git a/ext/bg/js/util.js b/ext/bg/js/util.js index a92fd0bc..f44582eb 100644 --- a/ext/bg/js/util.js +++ b/ext/bg/js/util.js @@ -42,8 +42,8 @@ function utilAnkiGetModelFieldNames(modelName) { return utilBackend().anki.getModelFieldNames(modelName); } -function utilDatabaseGetDictionaries() { - return utilBackend().translator.database.getDictionaries(); +function utilDatabaseGetTitles() { + return utilBackend().translator.database.getTitles(); } function utilDatabasePurge() { -- cgit v1.2.3 From 33d9d6ff573d72a8b1600b23b20faf2b0ca4419c Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Wed, 13 Sep 2017 18:03:55 -0700 Subject: cleanup --- ext/bg/js/database.js | 2 +- ext/bg/js/translator.js | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) (limited to 'ext/bg') diff --git a/ext/bg/js/database.js b/ext/bg/js/database.js index 630243b2..b56cf7e2 100644 --- a/ext/bg/js/database.js +++ b/ext/bg/js/database.js @@ -133,7 +133,7 @@ class Database { return results; } - async findTag(name, title) { + async findTagForTitle(name, title) { if (!this.db) { throw 'database not initialized'; } diff --git a/ext/bg/js/translator.js b/ext/bg/js/translator.js index 5de99e8e..0ecae16b 100644 --- a/ext/bg/js/translator.js +++ b/ext/bg/js/translator.js @@ -137,11 +137,13 @@ class Translator { async buildTags(names, title) { const results = []; for (const name of names) { - const meta = await this.database.findTag(name.split(':')[0], title); + const meta = await this.database.findTagForTitle(name.split(':')[0], title); const result = {name}; for (const prop in meta || {}) { - result[prop] = meta[prop]; + if (prop !== 'name') { + result[prop] = meta[prop]; + } } results.push(dictTagSanitize(result)); -- cgit v1.2.3 From f5009cd63ccb9e9d9aed3a1d4994c5c8e011f3a4 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Wed, 13 Sep 2017 23:22:41 -0700 Subject: cleanup --- ext/bg/js/api.js | 2 +- ext/bg/js/translator.js | 33 ++++++++++++++++++++++++++------- 2 files changed, 27 insertions(+), 8 deletions(-) (limited to 'ext/bg') diff --git a/ext/bg/js/api.js b/ext/bg/js/api.js index 5c1aebb6..9f65bb07 100644 --- a/ext/bg/js/api.js +++ b/ext/bg/js/api.js @@ -31,7 +31,7 @@ async function apiTermsFind(text) { const searcher = options.general.groupResults ? translator.findTermsGrouped.bind(translator) : - translator.findTerms.bind(translator); + translator.findTermsSplit.bind(translator); const {definitions, length} = await searcher( text, diff --git a/ext/bg/js/translator.js b/ext/bg/js/translator.js index 0ecae16b..19769536 100644 --- a/ext/bg/js/translator.js +++ b/ext/bg/js/translator.js @@ -37,8 +37,26 @@ class Translator { } async findTermsGrouped(text, dictionaries, alphanumeric) { + const titles = Object.keys(dictionaries); const {length, definitions} = await this.findTerms(text, dictionaries, alphanumeric); - return {length, definitions: dictTermsGroup(definitions, dictionaries)}; + + const definitionsGrouped = dictTermsGroup(definitions, dictionaries); + for (const definition of definitionsGrouped) { + this.buildTermFrequencies(definition, titles); + } + + return {length, definitions: definitionsGrouped}; + } + + async findTermsSplit(text, dictionaries, alphanumeric) { + const titles = Object.keys(dictionaries); + const {length, definitions} = await this.findTerms(text, dictionaries, alphanumeric); + + for (const definition of definitions) { + this.buildTermFrequencies(definition, titles); + } + + return {length, definitions}; } async findTerms(text, dictionaries, alphanumeric) { @@ -63,13 +81,7 @@ class Translator { const tags = await this.buildTags(definition.tags, definition.dictionary); tags.push(dictTagBuildSource(definition.dictionary)); - let frequencies = await this.database.findTermFreq(definition.expression, titles); - if (frequencies.length === 0) { - frequencies = await this.database.findTermFreq(definition.reading, titles); - } - definitions.push({ - frequencies, source: deinflection.source, reasons: deinflection.reasons, score: definition.score, @@ -134,6 +146,13 @@ class Translator { return definitions; } + async buildTermFrequencies(definition, titles) { + definition.frequencies = await this.database.findTermFreq(definition.expression, titles); + if (definition.frequencies.length === 0) { + definition.frequencies = await this.database.findTermFreq(definition.reading, titles); + } + } + async buildTags(names, title) { const results = []; for (const name of names) { -- cgit v1.2.3 From d3d760ed6c779e03713ef4946a76bf89a4647bcb Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Thu, 14 Sep 2017 10:15:54 -0700 Subject: cleanup --- ext/bg/js/translator.js | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'ext/bg') diff --git a/ext/bg/js/translator.js b/ext/bg/js/translator.js index 19769536..0cd49c27 100644 --- a/ext/bg/js/translator.js +++ b/ext/bg/js/translator.js @@ -78,7 +78,7 @@ class Translator { let definitions = []; for (const deinflection of deinflections) { for (const definition of deinflection.definitions) { - const tags = await this.buildTags(definition.tags, definition.dictionary); + const tags = await this.expandTags(definition); tags.push(dictTagBuildSource(definition.dictionary)); definitions.push({ @@ -136,9 +136,8 @@ class Translator { } for (const definition of definitions) { - const tags = await this.buildTags(definition.tags, definition.dictionary); + const tags = await this.expandTags(definition); tags.push(dictTagBuildSource(definition.dictionary)); - definition.tags = dictTagsSort(tags); definition.frequencies = await this.database.findKanjiFreq(definition.character, titles); } @@ -153,21 +152,22 @@ class Translator { } } - async buildTags(names, title) { - const results = []; - for (const name of names) { - const meta = await this.database.findTagForTitle(name.split(':')[0], title); + async expandTags(definition) { + const tags = []; + for (const name of definition.tags) { + const base = name.split(':')[0]; + const meta = await this.database.findTagForTitle(base, definition.dictionary); - const result = {name}; + const tag = {name}; for (const prop in meta || {}) { if (prop !== 'name') { - result[prop] = meta[prop]; + tag[prop] = meta[prop]; } } - results.push(dictTagSanitize(result)); + tags.push(dictTagSanitize(tag)); } - return results; + return tags; } } -- cgit v1.2.3 From 39e38d56657b9b11f49af96d84c819e6b6fcec8d Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Fri, 15 Sep 2017 13:18:21 -0700 Subject: improve kanji template --- ext/bg/js/templates.js | 70 +++++++++++++++++++++++------------------------ tmpl/kanji.html | 73 ++++++++++++++++++++++++++++---------------------- 2 files changed, 74 insertions(+), 69 deletions(-) (limited to 'ext/bg') diff --git a/ext/bg/js/templates.js b/ext/bg/js/templates.js index 1c059365..d26feec8 100644 --- a/ext/bg/js/templates.js +++ b/ext/bg/js/templates.js @@ -29,15 +29,14 @@ templates['kanji.html'] = template({"1":function(container,depth0,helpers,partia + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.source : depth0),{"name":"if","hash":{},"fn":container.program(4, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + " \n \n\n
" + container.escapeExpression(((helper = (helper = helpers.character || (depth0 != null ? depth0.character : depth0)) != null ? helper : helpers.helperMissing),(typeof helper === "function" ? helper.call(alias1,{"name":"character","hash":{},"data":data}) : helper))) - + "
\n\n
\n \n \n \n \n \n \n \n \n \n
Kunyomi:\n" - + ((stack1 = helpers.each.call(alias1,(depth0 != null ? depth0.kunyomi : depth0),{"name":"each","hash":{},"fn":container.program(6, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") - + "
Onyomi:\n" - + ((stack1 = helpers.each.call(alias1,(depth0 != null ? depth0.onyomi : depth0),{"name":"each","hash":{},"fn":container.program(6, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") - + "
\n
\n\n
\n" - + ((stack1 = helpers.each.call(alias1,(depth0 != null ? depth0.tags : depth0),{"name":"each","hash":{},"fn":container.program(9, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") - + "
\n\n
\n" - + ((stack1 = helpers["if"].call(alias1,((stack1 = (depth0 != null ? depth0.glossary : depth0)) != null ? stack1["1"] : stack1),{"name":"if","hash":{},"fn":container.program(11, data, 0),"inverse":container.program(15, data, 0),"data":data})) != null ? stack1 : "") - + "
\n\n" + + "\n\n
\n" + + ((stack1 = helpers.each.call(alias1,(depth0 != null ? depth0.tags : depth0),{"name":"each","hash":{},"fn":container.program(6, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + "
\n\n
\n\n \n \n \n \n \n \n \n \n \n \n \n
ReadingsGlossaryStatistics
\n" + + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.kunyomi : depth0),{"name":"if","hash":{},"fn":container.program(8, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.onyomi : depth0),{"name":"if","hash":{},"fn":container.program(11, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + " \n" + + ((stack1 = helpers["if"].call(alias1,((stack1 = (depth0 != null ? depth0.glossary : depth0)) != null ? stack1["1"] : stack1),{"name":"if","hash":{},"fn":container.program(13, data, 0),"inverse":container.program(16, data, 0),"data":data})) != null ? stack1 : "") + + "
\n\n" + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.debug : depth0),{"name":"if","hash":{},"fn":container.program(18, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + "\n"; },"2":function(container,depth0,helpers,partials,data) { @@ -45,15 +44,6 @@ templates['kanji.html'] = template({"1":function(container,depth0,helpers,partia },"4":function(container,depth0,helpers,partials,data) { return " \n"; },"6":function(container,depth0,helpers,partials,data) { - var stack1; - - return " " - + container.escapeExpression(container.lambda(depth0, depth0)) - + ((stack1 = helpers.unless.call(depth0 != null ? depth0 : (container.nullContext || {}),(data && data.last),{"name":"unless","hash":{},"fn":container.program(7, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") - + "\n"; -},"7":function(container,depth0,helpers,partials,data) { - return ", "; -},"9":function(container,depth0,helpers,partials,data) { var helper, alias1=depth0 != null ? depth0 : (container.nullContext || {}), alias2=helpers.helperMissing, alias3="function", alias4=container.escapeExpression; return " " + alias4(((helper = (helper = helpers.name || (depth0 != null ? depth0.name : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"name","hash":{},"data":data}) : helper))) + "\n"; +},"8":function(container,depth0,helpers,partials,data) { + var stack1; + + return "
\n
Kun
\n" + + ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.kunyomi : depth0),{"name":"each","hash":{},"fn":container.program(9, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + "
\n"; +},"9":function(container,depth0,helpers,partials,data) { + return "
" + + container.escapeExpression(container.lambda(depth0, depth0)) + + "
\n"; },"11":function(container,depth0,helpers,partials,data) { var stack1; - return "
    \n" - + ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.glossary : depth0),{"name":"each","hash":{},"fn":container.program(12, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") - + "
\n"; -},"12":function(container,depth0,helpers,partials,data) { - var stack1, helper, options, buffer = - "
  • "; - stack1 = ((helper = (helper = helpers.multiLine || (depth0 != null ? depth0.multiLine : depth0)) != null ? helper : helpers.helperMissing),(options={"name":"multiLine","hash":{},"fn":container.program(13, data, 0),"inverse":container.noop,"data":data}),(typeof helper === "function" ? helper.call(depth0 != null ? depth0 : (container.nullContext || {}),options) : helper)); - if (!helpers.multiLine) { stack1 = helpers.blockHelperMissing.call(depth0,stack1,options)} - if (stack1 != null) { buffer += stack1; } - return buffer + "
  • \n"; + return "
    \n
    On
    \n" + + ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.onyomi : depth0),{"name":"each","hash":{},"fn":container.program(9, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + "
    \n"; },"13":function(container,depth0,helpers,partials,data) { - return container.escapeExpression(container.lambda(depth0, depth0)); -},"15":function(container,depth0,helpers,partials,data) { - var stack1, helper, options, buffer = - "
    "; - stack1 = ((helper = (helper = helpers.multiLine || (depth0 != null ? depth0.multiLine : depth0)) != null ? helper : helpers.helperMissing),(options={"name":"multiLine","hash":{},"fn":container.program(16, data, 0),"inverse":container.noop,"data":data}),(typeof helper === "function" ? helper.call(depth0 != null ? depth0 : (container.nullContext || {}),options) : helper)); - if (!helpers.multiLine) { stack1 = helpers.blockHelperMissing.call(depth0,stack1,options)} - if (stack1 != null) { buffer += stack1; } - return buffer + "
    \n"; + var stack1; + + return "
      \n" + + ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.glossary : depth0),{"name":"each","hash":{},"fn":container.program(14, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + "
    \n"; +},"14":function(container,depth0,helpers,partials,data) { + return "
  • " + + container.escapeExpression(container.lambda(depth0, depth0)) + + "
  • \n"; },"16":function(container,depth0,helpers,partials,data) { var stack1; - return container.escapeExpression(container.lambda(((stack1 = (depth0 != null ? depth0.glossary : depth0)) != null ? stack1["0"] : stack1), depth0)); + return " " + + container.escapeExpression(container.lambda(((stack1 = (depth0 != null ? depth0.glossary : depth0)) != null ? stack1["0"] : stack1), depth0)) + + "\n"; },"18":function(container,depth0,helpers,partials,data) { var stack1, helper, options, buffer = "
    ";
    diff --git a/tmpl/kanji.html b/tmpl/kanji.html
    index bb62f488..4eb53048 100644
    --- a/tmpl/kanji.html
    +++ b/tmpl/kanji.html
    @@ -13,44 +13,53 @@
     
         
    {{character}}
    -
    - - - - - - - - - -
    Kunyomi: - {{#each kunyomi}} - {{.}}{{#unless @last}}, {{/unless}} - {{/each}} -
    Onyomi: - {{#each onyomi}} - {{.}}{{#unless @last}}, {{/unless}} - {{/each}} -
    -
    -
    {{#each tags}} {{name}} {{/each}}
    -
    - {{#if glossary.[1]}} -
      - {{#each glossary}} -
    1. {{#multiLine}}{{.}}{{/multiLine}}
    2. - {{/each}} -
    - {{else}} -
    {{#multiLine}}{{glossary.[0]}}{{/multiLine}}
    - {{/if}} -
    +
    + + + + + + + + + + + + +
    ReadingsGlossaryStatistics
    + {{#if kunyomi}} +
    +
    Kun
    + {{#each kunyomi}} +
    {{.}}
    + {{/each}} +
    + {{/if}} + {{#if onyomi}} +
    +
    On
    + {{#each onyomi}} +
    {{.}}
    + {{/each}} +
    + {{/if}} +
    + {{#if glossary.[1]}} +
      + {{#each glossary}} +
    1. {{.}}
    2. + {{/each}} +
    + {{else}} + {{glossary.[0]}} + {{/if}} +
    {{#if debug}}
    {{#dumpObject}}{{{.}}}{{/dumpObject}}
    -- cgit v1.2.3 From 7f55f1c8d2b82abda1cbdc353f28ae9136a361f3 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Fri, 15 Sep 2017 13:32:49 -0700 Subject: display term frequencies --- ext/bg/js/templates.js | 46 +++++++++++++++++++++++++++++++--------------- ext/bg/js/translator.js | 4 ++-- ext/mixed/css/display.css | 4 ++++ tmpl/terms.html | 8 ++++++++ 4 files changed, 45 insertions(+), 17 deletions(-) (limited to 'ext/bg') diff --git a/ext/bg/js/templates.js b/ext/bg/js/templates.js index d26feec8..5d9bcf3c 100644 --- a/ext/bg/js/templates.js +++ b/ext/bg/js/templates.js @@ -199,10 +199,12 @@ templates['terms.html'] = template({"1":function(container,depth0,helpers,partia if (stack1 != null) { buffer += stack1; } return buffer + "\n\n" + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.reasons : depth0),{"name":"if","hash":{},"fn":container.program(20, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + "\n" + + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.frequencies : depth0),{"name":"if","hash":{},"fn":container.program(24, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + "\n
    \n" - + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.grouped : depth0),{"name":"if","hash":{},"fn":container.program(24, data, 0),"inverse":container.program(30, data, 0),"data":data})) != null ? stack1 : "") + + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.grouped : depth0),{"name":"if","hash":{},"fn":container.program(27, data, 0),"inverse":container.program(33, data, 0),"data":data})) != null ? stack1 : "") + "
    \n\n" - + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.debug : depth0),{"name":"if","hash":{},"fn":container.program(32, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.debug : depth0),{"name":"if","hash":{},"fn":container.program(35, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + "\n"; },"13":function(container,depth0,helpers,partials,data) { return " \n \n \n"; @@ -238,53 +240,67 @@ templates['terms.html'] = template({"1":function(container,depth0,helpers,partia },"24":function(container,depth0,helpers,partials,data) { var stack1; - return ((stack1 = helpers["if"].call(depth0 != null ? depth0 : (container.nullContext || {}),((stack1 = (depth0 != null ? depth0.definitions : depth0)) != null ? stack1["1"] : stack1),{"name":"if","hash":{},"fn":container.program(25, data, 0),"inverse":container.program(28, data, 0),"data":data})) != null ? stack1 : ""); + return "
    \n" + + ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.frequencies : depth0),{"name":"each","hash":{},"fn":container.program(25, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + "
    \n"; },"25":function(container,depth0,helpers,partials,data) { + var helper, alias1=depth0 != null ? depth0 : (container.nullContext || {}), alias2=helpers.helperMissing, alias3="function", alias4=container.escapeExpression; + + return " " + + alias4(((helper = (helper = helpers.dictionary || (depth0 != null ? depth0.dictionary : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"dictionary","hash":{},"data":data}) : helper))) + + ":" + + alias4(((helper = (helper = helpers.frequency || (depth0 != null ? depth0.frequency : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"frequency","hash":{},"data":data}) : helper))) + + "\n"; +},"27":function(container,depth0,helpers,partials,data) { + var stack1; + + return ((stack1 = helpers["if"].call(depth0 != null ? depth0 : (container.nullContext || {}),((stack1 = (depth0 != null ? depth0.definitions : depth0)) != null ? stack1["1"] : stack1),{"name":"if","hash":{},"fn":container.program(28, data, 0),"inverse":container.program(31, data, 0),"data":data})) != null ? stack1 : ""); +},"28":function(container,depth0,helpers,partials,data) { var stack1; return "
      \n" - + ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.definitions : depth0),{"name":"each","hash":{},"fn":container.program(26, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.definitions : depth0),{"name":"each","hash":{},"fn":container.program(29, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + "
    \n"; -},"26":function(container,depth0,helpers,partials,data) { +},"29":function(container,depth0,helpers,partials,data) { var stack1; return "
  • " + ((stack1 = container.invokePartial(partials.definition,depth0,{"name":"definition","data":data,"helpers":helpers,"partials":partials,"decorators":container.decorators})) != null ? stack1 : "") + "
  • \n"; -},"28":function(container,depth0,helpers,partials,data) { +},"31":function(container,depth0,helpers,partials,data) { var stack1; return ((stack1 = container.invokePartial(partials.definition,((stack1 = (depth0 != null ? depth0.definitions : depth0)) != null ? stack1["0"] : stack1),{"name":"definition","data":data,"indent":" ","helpers":helpers,"partials":partials,"decorators":container.decorators})) != null ? stack1 : ""); -},"30":function(container,depth0,helpers,partials,data) { +},"33":function(container,depth0,helpers,partials,data) { var stack1; return ((stack1 = container.invokePartial(partials.definition,depth0,{"name":"definition","data":data,"indent":" ","helpers":helpers,"partials":partials,"decorators":container.decorators})) != null ? stack1 : ""); -},"32":function(container,depth0,helpers,partials,data) { +},"35":function(container,depth0,helpers,partials,data) { var stack1, helper, options, buffer = "
    ";
       stack1 = ((helper = (helper = helpers.dumpObject || (depth0 != null ? depth0.dumpObject : depth0)) != null ? helper : helpers.helperMissing),(options={"name":"dumpObject","hash":{},"fn":container.program(18, data, 0),"inverse":container.noop,"data":data}),(typeof helper === "function" ? helper.call(depth0 != null ? depth0 : (container.nullContext || {}),options) : helper));
       if (!helpers.dumpObject) { stack1 = helpers.blockHelperMissing.call(depth0,stack1,options)}
       if (stack1 != null) { buffer += stack1; }
       return buffer + "
    \n"; -},"34":function(container,depth0,helpers,partials,data,blockParams,depths) { +},"37":function(container,depth0,helpers,partials,data,blockParams,depths) { var stack1; - return ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.definitions : depth0),{"name":"each","hash":{},"fn":container.program(35, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : ""); -},"35":function(container,depth0,helpers,partials,data,blockParams,depths) { + return ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.definitions : depth0),{"name":"each","hash":{},"fn":container.program(38, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : ""); +},"38":function(container,depth0,helpers,partials,data,blockParams,depths) { var stack1; - return ((stack1 = helpers.unless.call(depth0 != null ? depth0 : (container.nullContext || {}),(data && data.first),{"name":"unless","hash":{},"fn":container.program(36, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "") + return ((stack1 = helpers.unless.call(depth0 != null ? depth0 : (container.nullContext || {}),(data && data.first),{"name":"unless","hash":{},"fn":container.program(39, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "") + "\n" + ((stack1 = container.invokePartial(partials.term,depth0,{"name":"term","hash":{"playback":(depths[1] != null ? depths[1].playback : depths[1]),"addable":(depths[1] != null ? depths[1].addable : depths[1]),"grouped":(depths[1] != null ? depths[1].grouped : depths[1]),"debug":(depths[1] != null ? depths[1].debug : depths[1])},"data":data,"helpers":helpers,"partials":partials,"decorators":container.decorators})) != null ? stack1 : ""); -},"36":function(container,depth0,helpers,partials,data) { +},"39":function(container,depth0,helpers,partials,data) { return "
    "; -},"38":function(container,depth0,helpers,partials,data) { +},"41":function(container,depth0,helpers,partials,data) { return "

    No results found.

    \n"; },"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data,blockParams,depths) { var stack1; return "\n\n" - + ((stack1 = helpers["if"].call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.definitions : depth0),{"name":"if","hash":{},"fn":container.program(34, data, 0, blockParams, depths),"inverse":container.program(38, data, 0, blockParams, depths),"data":data})) != null ? stack1 : ""); + + ((stack1 = helpers["if"].call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.definitions : depth0),{"name":"if","hash":{},"fn":container.program(37, data, 0, blockParams, depths),"inverse":container.program(41, data, 0, blockParams, depths),"data":data})) != null ? stack1 : ""); },"main_d": function(fn, props, container, depth0, data, blockParams, depths) { var decorators = container.decorators; diff --git a/ext/bg/js/translator.js b/ext/bg/js/translator.js index 0cd49c27..3dd482ca 100644 --- a/ext/bg/js/translator.js +++ b/ext/bg/js/translator.js @@ -42,7 +42,7 @@ class Translator { const definitionsGrouped = dictTermsGroup(definitions, dictionaries); for (const definition of definitionsGrouped) { - this.buildTermFrequencies(definition, titles); + await this.buildTermFrequencies(definition, titles); } return {length, definitions: definitionsGrouped}; @@ -53,7 +53,7 @@ class Translator { const {length, definitions} = await this.findTerms(text, dictionaries, alphanumeric); for (const definition of definitions) { - this.buildTermFrequencies(definition, titles); + await this.buildTermFrequencies(definition, titles); } return {length, definitions}; diff --git a/ext/mixed/css/display.css b/ext/mixed/css/display.css index 8b1819bd..6c7148dc 100644 --- a/ext/mixed/css/display.css +++ b/ext/mixed/css/display.css @@ -84,6 +84,10 @@ hr { background-color: #aa66cc; } +.tag-frequency { + background-color: #5cb85c; +} + .actions .disabled { pointer-events: none; cursor: default; diff --git a/tmpl/terms.html b/tmpl/terms.html index ffe52ab8..a130e775 100644 --- a/tmpl/terms.html +++ b/tmpl/terms.html @@ -41,6 +41,14 @@ {{/if}} + {{#if frequencies}} +
    + {{#each frequencies}} + {{dictionary}}:{{frequency}} + {{/each}} +
    + {{/if}} +
    {{#if grouped}} {{#if definitions.[1]}} -- cgit v1.2.3 From e044f0107ab33125f47dac1dde7fe2c673d0ddd6 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Fri, 15 Sep 2017 14:03:05 -0700 Subject: style fixes --- ext/bg/js/templates.js | 2 +- ext/mixed/css/display.css | 4 ++++ tmpl/kanji.html | 4 +--- 3 files changed, 6 insertions(+), 4 deletions(-) (limited to 'ext/bg') diff --git a/ext/bg/js/templates.js b/ext/bg/js/templates.js index 5d9bcf3c..70af31ea 100644 --- a/ext/bg/js/templates.js +++ b/ext/bg/js/templates.js @@ -31,7 +31,7 @@ templates['kanji.html'] = template({"1":function(container,depth0,helpers,partia + container.escapeExpression(((helper = (helper = helpers.character || (depth0 != null ? depth0.character : depth0)) != null ? helper : helpers.helperMissing),(typeof helper === "function" ? helper.call(alias1,{"name":"character","hash":{},"data":data}) : helper))) + "
    \n\n
    \n" + ((stack1 = helpers.each.call(alias1,(depth0 != null ? depth0.tags : depth0),{"name":"each","hash":{},"fn":container.program(6, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") - + "
    \n\n
    \n\n \n \n \n \n \n \n \n - + + + + + + +
    ReadingsGlossaryStatistics
    \n" + + " \n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
    ReadingsGlossaryStatistics
    \n" + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.kunyomi : depth0),{"name":"if","hash":{},"fn":container.program(8, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.onyomi : depth0),{"name":"if","hash":{},"fn":container.program(11, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + " \n" diff --git a/ext/mixed/css/display.css b/ext/mixed/css/display.css index 6c7148dc..92480bab 100644 --- a/ext/mixed/css/display.css +++ b/ext/mixed/css/display.css @@ -148,3 +148,7 @@ hr { padding: 0.01em; vertical-align: top; } + +.glyph-data { + margin-top: 10px; +} diff --git a/tmpl/kanji.html b/tmpl/kanji.html index 4eb53048..f66b707e 100644 --- a/tmpl/kanji.html +++ b/tmpl/kanji.html @@ -19,9 +19,7 @@ {{/each}} -
    - - +
    -- cgit v1.2.3 From 5a531541238b52ba56475ae3f91873bd1b8a9d10 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Fri, 15 Sep 2017 14:06:10 -0700 Subject: style fixes --- ext/bg/js/templates.js | 14 ++++++-------- tmpl/kanji.html | 14 ++++++-------- 2 files changed, 12 insertions(+), 16 deletions(-) (limited to 'ext/bg') diff --git a/ext/bg/js/templates.js b/ext/bg/js/templates.js index 70af31ea..a8fc87b6 100644 --- a/ext/bg/js/templates.js +++ b/ext/bg/js/templates.js @@ -31,10 +31,10 @@ templates['kanji.html'] = template({"1":function(container,depth0,helpers,partia + container.escapeExpression(((helper = (helper = helpers.character || (depth0 != null ? depth0.character : depth0)) != null ? helper : helpers.helperMissing),(typeof helper === "function" ? helper.call(alias1,{"name":"character","hash":{},"data":data}) : helper))) + "\n\n
    \n" + ((stack1 = helpers.each.call(alias1,(depth0 != null ? depth0.tags : depth0),{"name":"each","hash":{},"fn":container.program(6, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") - + "
    \n\n
    Readings Glossary
    \n \n \n \n \n \n \n \n \n \n \n
    ReadingsGlossaryStatistics
    \n" + + " \n\n \n \n \n \n \n \n \n \n \n \n \n \n
    ReadingsGlossaryStatistics
    \n
    \n" + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.kunyomi : depth0),{"name":"if","hash":{},"fn":container.program(8, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.onyomi : depth0),{"name":"if","hash":{},"fn":container.program(11, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") - + "
    \n" + + " \n \n" + ((stack1 = helpers["if"].call(alias1,((stack1 = (depth0 != null ? depth0.glossary : depth0)) != null ? stack1["1"] : stack1),{"name":"if","hash":{},"fn":container.program(13, data, 0),"inverse":container.program(16, data, 0),"data":data})) != null ? stack1 : "") + "
    \n\n" + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.debug : depth0),{"name":"if","hash":{},"fn":container.program(18, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") @@ -56,9 +56,8 @@ templates['kanji.html'] = template({"1":function(container,depth0,helpers,partia },"8":function(container,depth0,helpers,partials,data) { var stack1; - return "
    \n
    Kun
    \n" - + ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.kunyomi : depth0),{"name":"each","hash":{},"fn":container.program(9, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") - + "
    \n"; + return "
    Kun-Yomi
    \n" + + ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.kunyomi : depth0),{"name":"each","hash":{},"fn":container.program(9, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : ""); },"9":function(container,depth0,helpers,partials,data) { return "
    " + container.escapeExpression(container.lambda(depth0, depth0)) @@ -66,9 +65,8 @@ templates['kanji.html'] = template({"1":function(container,depth0,helpers,partia },"11":function(container,depth0,helpers,partials,data) { var stack1; - return "
    \n
    On
    \n" - + ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.onyomi : depth0),{"name":"each","hash":{},"fn":container.program(9, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") - + "
    \n"; + return "
    On-Yomi
    \n" + + ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.onyomi : depth0),{"name":"each","hash":{},"fn":container.program(9, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : ""); },"13":function(container,depth0,helpers,partials,data) { var stack1; diff --git a/tmpl/kanji.html b/tmpl/kanji.html index f66b707e..9ab5b2a8 100644 --- a/tmpl/kanji.html +++ b/tmpl/kanji.html @@ -27,22 +27,20 @@
    - {{#if kunyomi}}
    -
    Kun
    + {{#if kunyomi}} +
    Kun-Yomi
    {{#each kunyomi}}
    {{.}}
    {{/each}} -
    - {{/if}} - {{#if onyomi}} -
    -
    On
    + {{/if}} + {{#if onyomi}} +
    On-Yomi
    {{#each onyomi}}
    {{.}}
    {{/each}} + {{/if}}
    - {{/if}}
    {{#if glossary.[1]}} -- cgit v1.2.3 From 9280985306f5a9c79b9bd2c4daea596a5ec78ae5 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sat, 16 Sep 2017 23:08:43 -0700 Subject: add option to automatically hide search results (fixes #71) --- ext/bg/js/options.js | 1 + ext/bg/js/settings.js | 2 ++ ext/bg/settings.html | 4 ++++ ext/fg/js/frontend.js | 21 ++++++++++----------- ext/fg/js/source.js | 4 ++-- 5 files changed, 19 insertions(+), 13 deletions(-) (limited to 'ext/bg') diff --git a/ext/bg/js/options.js b/ext/bg/js/options.js index dcad97d4..a245da80 100644 --- a/ext/bg/js/options.js +++ b/ext/bg/js/options.js @@ -146,6 +146,7 @@ function optionsSetDefaults(options) { middleMouse: true, selectText: true, alphanumeric: true, + autoHideResults: false, delay: 15, length: 10, modifier: 'shift' diff --git a/ext/bg/js/settings.js b/ext/bg/js/settings.js index a2580c35..d73d7509 100644 --- a/ext/bg/js/settings.js +++ b/ext/bg/js/settings.js @@ -35,6 +35,7 @@ async function formRead() { optionsNew.scanning.middleMouse = $('#middle-mouse-button-scan').prop('checked'); optionsNew.scanning.selectText = $('#select-matched-text').prop('checked'); optionsNew.scanning.alphanumeric = $('#search-alphanumeric').prop('checked'); + optionsNew.scanning.autoHideResults = $('#auto-hide-results').prop('checked'); optionsNew.scanning.delay = parseInt($('#scan-delay').val(), 10); optionsNew.scanning.length = parseInt($('#scan-length').val(), 10); optionsNew.scanning.modifier = $('#scan-modifier-key').val(); @@ -136,6 +137,7 @@ async function onReady() { $('#middle-mouse-button-scan').prop('checked', options.scanning.middleMouse); $('#select-matched-text').prop('checked', options.scanning.selectText); $('#search-alphanumeric').prop('checked', options.scanning.alphanumeric); + $('#auto-hide-results').prop('checked', options.scanning.autoHideResults); $('#scan-delay').val(options.scanning.delay); $('#scan-length').val(options.scanning.length); $('#scan-modifier-key').val(options.scanning.modifier); diff --git a/ext/bg/settings.html b/ext/bg/settings.html index 0a5c205c..c2612967 100644 --- a/ext/bg/settings.html +++ b/ext/bg/settings.html @@ -96,6 +96,10 @@ +
    + +
    +
    diff --git a/ext/fg/js/frontend.js b/ext/fg/js/frontend.js index 41c93f00..e4035289 100644 --- a/ext/fg/js/frontend.js +++ b/ext/fg/js/frontend.js @@ -169,27 +169,21 @@ class Frontend { } async searchAt(point) { - let textSource = null; + const textSource = docRangeFromPoint(point); + let hideResults = false; try { if (this.pendingLookup) { return; } - textSource = docRangeFromPoint(point); - if (!textSource || !textSource.containsPoint(point)) { - docImposterDestroy(); - return; - } - if (this.textSourceLast && this.textSourceLast.equals(textSource)) { return; } - this.pendingLookup = true; - - if (!await this.searchTerms(textSource)) { - await this.searchKanji(textSource); + if (textSource && textSource.containsPoint(point)) { + this.pendingLookup = true; + hideResults = !await this.searchTerms(textSource) && !await this.searchKanji(textSource); } } catch (e) { if (window.yomichan_orphaned) { @@ -201,6 +195,11 @@ class Frontend { } } finally { docImposterDestroy(); + + if (hideResults && this.options.scanning.autoHideResults) { + this.popup.hide(); + } + this.pendingLookup = false; } } diff --git a/ext/fg/js/source.js b/ext/fg/js/source.js index 3b6ecb2a..664dbec7 100644 --- a/ext/fg/js/source.js +++ b/ext/fg/js/source.js @@ -82,7 +82,7 @@ class TextSourceRange { } equals(other) { - return other.range && other.range.compareBoundaryPoints(Range.START_TO_START, this.range) === 0; + return other && other.range && other.range.compareBoundaryPoints(Range.START_TO_START, this.range) === 0; } static shouldEnter(node) { @@ -239,6 +239,6 @@ class TextSourceElement { } equals(other) { - return other.element === this.element && other.content === this.content; + return other && other.element === this.element && other.content === this.content; } } -- cgit v1.2.3 From 5476c100467e31d7dac02a4b1c14e62a4e9b34d0 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sun, 17 Sep 2017 10:09:48 -0700 Subject: more improvements to automatic search result hiding (#71) --- ext/bg/js/options.js | 2 +- ext/fg/js/frontend.js | 23 +++++++++-------------- ext/fg/js/popup.js | 15 +++++++++++++++ 3 files changed, 25 insertions(+), 15 deletions(-) (limited to 'ext/bg') diff --git a/ext/bg/js/options.js b/ext/bg/js/options.js index a245da80..36ab7694 100644 --- a/ext/bg/js/options.js +++ b/ext/bg/js/options.js @@ -147,7 +147,7 @@ function optionsSetDefaults(options) { selectText: true, alphanumeric: true, autoHideResults: false, - delay: 15, + delay: 20, length: 10, modifier: 'shift' }, diff --git a/ext/fg/js/frontend.js b/ext/fg/js/frontend.js index e4035289..63cdc25e 100644 --- a/ext/fg/js/frontend.js +++ b/ext/fg/js/frontend.js @@ -80,7 +80,6 @@ class Frontend { const search = async () => { try { await this.searchAt({x: e.clientX, y: e.clientY}); - this.pendingLookup = false; } catch (e) { this.onError(e); } @@ -169,19 +168,15 @@ class Frontend { } async searchAt(point) { + if (this.pendingLookup || this.popup.containsPoint(point)) { + return; + } + const textSource = docRangeFromPoint(point); - let hideResults = false; + let hideResults = !textSource || !textSource.containsPoint(point); try { - if (this.pendingLookup) { - return; - } - - if (this.textSourceLast && this.textSourceLast.equals(textSource)) { - return; - } - - if (textSource && textSource.containsPoint(point)) { + if (!hideResults && (!this.textSourceLast || !this.textSourceLast.equals(textSource))) { this.pendingLookup = true; hideResults = !await this.searchTerms(textSource) && !await this.searchKanji(textSource); } @@ -194,10 +189,10 @@ class Frontend { this.onError(e); } } finally { - docImposterDestroy(); - if (hideResults && this.options.scanning.autoHideResults) { - this.popup.hide(); + this.searchClear(); + } else { + docImposterDestroy(); } this.pendingLookup = false; diff --git a/ext/fg/js/popup.js b/ext/fg/js/popup.js index 03958832..d1009fe9 100644 --- a/ext/fg/js/popup.js +++ b/ext/fg/js/popup.js @@ -100,6 +100,21 @@ class Popup { return this.injected && this.container.style.visibility !== 'hidden'; } + containsPoint(point) { + if (!this.isVisible()) { + return false; + } + + const rect = this.container.getBoundingClientRect(); + const contained = + point.x >= rect.left && + point.y >= rect.top && + point.x < rect.right && + point.y < rect.bottom; + + return contained; + } + async termsShow(elementRect, definitions, options, context) { await this.show(elementRect, options); this.invokeApi('termsShow', {definitions, options, context}); -- cgit v1.2.3 From ba25fbfd1f6187e75bbf3aa2e36717c081f09e7c Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sun, 17 Sep 2017 12:56:34 -0700 Subject: backwards compat --- ext/bg/js/database.js | 114 +++++++++++++++++++++++++++++++++---------------- ext/bg/js/templates.js | 48 +++++++++++++++------ tmpl/kanji.html | 30 ++++++++++++- 3 files changed, 141 insertions(+), 51 deletions(-) (limited to 'ext/bg') diff --git a/ext/bg/js/database.js b/ext/bg/js/database.js index b56cf7e2..0acf974f 100644 --- a/ext/bg/js/database.js +++ b/ext/bg/js/database.js @@ -110,6 +110,8 @@ class Database { kunyomi: dictFieldSplit(row.kunyomi), tags: dictFieldSplit(row.tags), glossary: row.meanings, + indices: row.indices, + stats: row.stats, dictionary: row.dictionary }); } @@ -168,6 +170,10 @@ class Database { } const indexDataLoaded = async summary => { + if (summary.version > 2) { + throw 'unsupported dictionary version'; + } + const count = await this.db.dictionaries.where('title').equals(summary.title).count(); if (count > 0) { throw `dictionary "${summary.title}" is already imported`; @@ -176,28 +182,42 @@ class Database { await this.db.dictionaries.add(summary); }; - const termDataLoaded = async (title, entries, total, current) => { + const termDataLoaded = async (summary, entries, total, current) => { if (callback) { callback(total, current); } const rows = []; - for (const [expression, reading, tags, rules, score, ...glossary] of entries) { - rows.push({ - expression, - reading, - tags, - rules, - score, - glossary, - dictionary: title - }); + if (summary.version === 1) { + for (const [expression, reading, tags, rules, score, ...glossary] of entries) { + rows.push({ + expression, + reading, + tags, + rules, + score, + glossary, + dictionary: summary.title + }); + } + } else { + for (const [expression, reading, tags, rules, score, glossary] of entries) { + rows.push({ + expression, + reading, + tags, + rules, + score, + glossary, + dictionary: summary.title + }); + } } await this.db.terms.bulkAdd(rows); }; - const termFreqDataLoaded = async (title, entries, total, current) => { + const termFreqDataLoaded = async (summary, entries, total, current) => { if (callback) { callback(total, current); } @@ -207,34 +227,49 @@ class Database { rows.push({ expression, frequency, - dictionary: title + dictionary: summary.title }); } await this.db.termFreq.bulkAdd(rows); }; - const kanjiDataLoaded = async (title, entries, total, current) => { + const kanjiDataLoaded = async (summary, entries, total, current) => { if (callback) { callback(total, current); } const rows = []; - for (const [character, onyomi, kunyomi, tags, ...meanings] of entries) { - rows.push({ - character, - onyomi, - kunyomi, - tags, - meanings, - dictionary: title - }); + if (summary.version === 1) { + for (const [character, onyomi, kunyomi, tags, ...meanings] of entries) { + rows.push({ + character, + onyomi, + kunyomi, + tags, + meanings, + dictionary: summary.title + }); + } + } else { + for (const [character, onyomi, kunyomi, tags, meanings, indices, stats] of entries) { + rows.push({ + character, + onyomi, + kunyomi, + tags, + meanings, + indices, + stats, + dictionary: summary.title + }); + } } await this.db.kanji.bulkAdd(rows); }; - const kanjiFreqDataLoaded = async (title, entries, total, current) => { + const kanjiFreqDataLoaded = async (summary, entries, total, current) => { if (callback) { callback(total, current); } @@ -244,14 +279,14 @@ class Database { rows.push({ character, frequency, - dictionary: title + dictionary: summary.title }); } await this.db.kanjiFreq.bulkAdd(rows); }; - const tagDataLoaded = async (title, entries, total, current) => { + const tagDataLoaded = async (summary, entries, total, current) => { if (callback) { callback(total, current); } @@ -263,7 +298,7 @@ class Database { category, order, notes, - dictionary: title + dictionary: summary.title }); rows.push(row); @@ -300,11 +335,16 @@ class Database { } const index = JSON.parse(await indexFile.async('string')); - if (!index.title || !index.version || !index.revision) { + if (!index.title || !index.revision) { throw 'unrecognized dictionary format'; } - const summary = {title: index.title, version: index.version, revision: index.revision}; + const summary = { + title: index.title, + revision: index.revision, + version: index.format || index.version + }; + if (indexDataLoaded) { await indexDataLoaded(summary); } @@ -345,24 +385,24 @@ class Database { bank.push([name, tag.category, tag.order, tag.notes]); } - tagDataLoaded(index.title, bank, ++bankTotalCount, bankLoadedCount++); + tagDataLoaded(summary, bank, ++bankTotalCount, bankLoadedCount++); } - const loadBank = async (namer, count, callback) => { + const loadBank = async (summary, namer, count, callback) => { if (callback) { for (let i = 0; i < count; ++i) { const bankFile = zip.files[namer(i)]; const bank = JSON.parse(await bankFile.async('string')); - await callback(index.title, bank, bankTotalCount, bankLoadedCount++); + await callback(summary, bank, bankTotalCount, bankLoadedCount++); } } }; - await loadBank(buildTermBankName, termBankCount, termDataLoaded); - await loadBank(buildTermFreqBankName, termFreqBankCount, termFreqDataLoaded); - await loadBank(buildKanjiBankName, kanjiBankCount, kanjiDataLoaded); - await loadBank(buildKanjiFreqBankName, kanjiFreqBankCount, kanjiFreqDataLoaded); - await loadBank(buildTagBankName, tagBankCount, tagDataLoaded); + await loadBank(summary, buildTermBankName, termBankCount, termDataLoaded); + await loadBank(summary, buildTermFreqBankName, termFreqBankCount, termFreqDataLoaded); + await loadBank(summary, buildKanjiBankName, kanjiBankCount, kanjiDataLoaded); + await loadBank(summary, buildKanjiFreqBankName, kanjiFreqBankCount, kanjiFreqDataLoaded); + await loadBank(summary, buildTagBankName, tagBankCount, tagDataLoaded); return summary; } diff --git a/ext/bg/js/templates.js b/ext/bg/js/templates.js index a8fc87b6..0d546909 100644 --- a/ext/bg/js/templates.js +++ b/ext/bg/js/templates.js @@ -36,8 +36,12 @@ templates['kanji.html'] = template({"1":function(container,depth0,helpers,partia + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.onyomi : depth0),{"name":"if","hash":{},"fn":container.program(11, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + " \n
    \n" + ((stack1 = helpers["if"].call(alias1,((stack1 = (depth0 != null ? depth0.glossary : depth0)) != null ? stack1["1"] : stack1),{"name":"if","hash":{},"fn":container.program(13, data, 0),"inverse":container.program(16, data, 0),"data":data})) != null ? stack1 : "") - + "
    \n\n" - + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.debug : depth0),{"name":"if","hash":{},"fn":container.program(18, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + "
    \n
    \n" + + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.stats : depth0),{"name":"if","hash":{},"fn":container.program(18, data, 0),"inverse":container.program(21, data, 0),"data":data})) != null ? stack1 : "") + + "
    \n
    Dictionary Indices
    \n
    \n" + + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.indices : depth0),{"name":"if","hash":{},"fn":container.program(23, data, 0),"inverse":container.program(25, data, 0),"data":data})) != null ? stack1 : "") + + "
    \n
    \n\n" + + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.debug : depth0),{"name":"if","hash":{},"fn":container.program(27, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + "\n"; },"2":function(container,depth0,helpers,partials,data) { return " \n \n"; @@ -84,35 +88,55 @@ templates['kanji.html'] = template({"1":function(container,depth0,helpers,partia + container.escapeExpression(container.lambda(((stack1 = (depth0 != null ? depth0.glossary : depth0)) != null ? stack1["0"] : stack1), depth0)) + "\n"; },"18":function(container,depth0,helpers,partials,data) { + var stack1; + + return ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.stats : depth0),{"name":"each","hash":{},"fn":container.program(19, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : ""); +},"19":function(container,depth0,helpers,partials,data) { + var helper, alias1=container.escapeExpression; + + return "
    " + + alias1(((helper = (helper = helpers.key || (data && data.key)) != null ? helper : helpers.helperMissing),(typeof helper === "function" ? helper.call(depth0 != null ? depth0 : (container.nullContext || {}),{"name":"key","hash":{},"data":data}) : helper))) + + ": " + + alias1(container.lambda(depth0, depth0)) + + "
    \n"; +},"21":function(container,depth0,helpers,partials,data) { + return " No statistical data found\n"; +},"23":function(container,depth0,helpers,partials,data) { + var stack1; + + return ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.indices : depth0),{"name":"each","hash":{},"fn":container.program(19, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : ""); +},"25":function(container,depth0,helpers,partials,data) { + return " No index data found\n"; +},"27":function(container,depth0,helpers,partials,data) { var stack1, helper, options, buffer = "
    ";
    -  stack1 = ((helper = (helper = helpers.dumpObject || (depth0 != null ? depth0.dumpObject : depth0)) != null ? helper : helpers.helperMissing),(options={"name":"dumpObject","hash":{},"fn":container.program(19, data, 0),"inverse":container.noop,"data":data}),(typeof helper === "function" ? helper.call(depth0 != null ? depth0 : (container.nullContext || {}),options) : helper));
    +  stack1 = ((helper = (helper = helpers.dumpObject || (depth0 != null ? depth0.dumpObject : depth0)) != null ? helper : helpers.helperMissing),(options={"name":"dumpObject","hash":{},"fn":container.program(28, data, 0),"inverse":container.noop,"data":data}),(typeof helper === "function" ? helper.call(depth0 != null ? depth0 : (container.nullContext || {}),options) : helper));
       if (!helpers.dumpObject) { stack1 = helpers.blockHelperMissing.call(depth0,stack1,options)}
       if (stack1 != null) { buffer += stack1; }
       return buffer + "
    \n"; -},"19":function(container,depth0,helpers,partials,data) { +},"28":function(container,depth0,helpers,partials,data) { var stack1; return ((stack1 = container.lambda(depth0, depth0)) != null ? stack1 : ""); -},"21":function(container,depth0,helpers,partials,data,blockParams,depths) { +},"30":function(container,depth0,helpers,partials,data,blockParams,depths) { var stack1; - return ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.definitions : depth0),{"name":"each","hash":{},"fn":container.program(22, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : ""); -},"22":function(container,depth0,helpers,partials,data,blockParams,depths) { + return ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.definitions : depth0),{"name":"each","hash":{},"fn":container.program(31, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : ""); +},"31":function(container,depth0,helpers,partials,data,blockParams,depths) { var stack1; - return ((stack1 = helpers.unless.call(depth0 != null ? depth0 : (container.nullContext || {}),(data && data.first),{"name":"unless","hash":{},"fn":container.program(23, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "") + return ((stack1 = helpers.unless.call(depth0 != null ? depth0 : (container.nullContext || {}),(data && data.first),{"name":"unless","hash":{},"fn":container.program(32, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "") + "\n" + ((stack1 = container.invokePartial(partials.kanji,depth0,{"name":"kanji","hash":{"root":(depths[1] != null ? depths[1].root : depths[1]),"source":(depths[1] != null ? depths[1].source : depths[1]),"addable":(depths[1] != null ? depths[1].addable : depths[1]),"debug":(depths[1] != null ? depths[1].debug : depths[1])},"data":data,"helpers":helpers,"partials":partials,"decorators":container.decorators})) != null ? stack1 : ""); -},"23":function(container,depth0,helpers,partials,data) { +},"32":function(container,depth0,helpers,partials,data) { return "
    "; -},"25":function(container,depth0,helpers,partials,data) { - return "

    No results found.

    \n"; +},"34":function(container,depth0,helpers,partials,data) { + return "

    No results found

    \n"; },"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data,blockParams,depths) { var stack1; return "\n" - + ((stack1 = helpers["if"].call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.definitions : depth0),{"name":"if","hash":{},"fn":container.program(21, data, 0, blockParams, depths),"inverse":container.program(25, data, 0, blockParams, depths),"data":data})) != null ? stack1 : ""); + + ((stack1 = helpers["if"].call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.definitions : depth0),{"name":"if","hash":{},"fn":container.program(30, data, 0, blockParams, depths),"inverse":container.program(34, data, 0, blockParams, depths),"data":data})) != null ? stack1 : ""); },"main_d": function(fn, props, container, depth0, data, blockParams, depths) { var decorators = container.decorators; diff --git a/tmpl/kanji.html b/tmpl/kanji.html index 9ab5b2a8..6cea57f9 100644 --- a/tmpl/kanji.html +++ b/tmpl/kanji.html @@ -53,7 +53,33 @@ {{glossary.[0]}} {{/if}}
    +
    + {{#if stats}} + {{#each stats}} +
    {{@key}}: {{.}}
    + {{/each}} + {{else}} + No statistical data found + {{/if}} +
    +
    Dictionary Indices
    +
    + {{#if indices}} + {{#each indices}} +
    {{@key}}: {{.}}
    + {{/each}} + {{else}} + No index data found + {{/if}} +
    +
    @@ -69,5 +95,5 @@ {{> kanji debug=../debug addable=../addable source=../source root=../root}} {{/each}} {{else}} -

    No results found.

    +

    No results found

    {{/if}} -- cgit v1.2.3 From 7c69b4f28a97e727a9f2fd29a2e497d1bc657ccc Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sun, 17 Sep 2017 13:07:15 -0700 Subject: fix sort order --- ext/bg/js/dictionary.js | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'ext/bg') diff --git a/ext/bg/js/dictionary.js b/ext/bg/js/dictionary.js index 1cd1a846..57acbe5e 100644 --- a/ext/bg/js/dictionary.js +++ b/ext/bg/js/dictionary.js @@ -55,14 +55,6 @@ function dictRowsSort(rows, options) { function dictTermsSort(definitions, dictionaries=null) { return definitions.sort((v1, v2) => { - const sl1 = v1.source.length; - const sl2 = v2.source.length; - if (sl1 > sl2) { - return -1; - } else if (sl1 < sl2) { - return 1; - } - if (dictionaries !== null) { const p1 = (dictionaries[v1.dictionary] || {}).priority || 0; const p2 = (dictionaries[v2.dictionary] || {}).priority || 0; @@ -73,11 +65,11 @@ function dictTermsSort(definitions, dictionaries=null) { } } - const s1 = v1.score; - const s2 = v2.score; - if (s1 > s2) { + const sl1 = v1.source.length; + const sl2 = v2.source.length; + if (sl1 > sl2) { return -1; - } else if (s1 < s2) { + } else if (sl1 < sl2) { return 1; } @@ -89,6 +81,14 @@ function dictTermsSort(definitions, dictionaries=null) { return 1; } + const s1 = v1.score; + const s2 = v2.score; + if (s1 > s2) { + return -1; + } else if (s1 < s2) { + return 1; + } + return v2.expression.localeCompare(v1.expression); }); } -- cgit v1.2.3 From 269a4f0b9ba1876bd5a6e72e34537056a75081fc Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sun, 17 Sep 2017 14:17:14 -0700 Subject: template fixups --- ext/bg/js/templates.js | 64 +++++++++++++++++++++----------------------------- tmpl/kanji.html | 6 ----- 2 files changed, 27 insertions(+), 43 deletions(-) (limited to 'ext/bg') diff --git a/ext/bg/js/templates.js b/ext/bg/js/templates.js index 0d546909..41bc58c9 100644 --- a/ext/bg/js/templates.js +++ b/ext/bg/js/templates.js @@ -32,16 +32,16 @@ templates['kanji.html'] = template({"1":function(container,depth0,helpers,partia + "\n\n
    \n" + ((stack1 = helpers.each.call(alias1,(depth0 != null ? depth0.tags : depth0),{"name":"each","hash":{},"fn":container.program(6, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + "
    \n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
    ReadingsGlossaryStatistics
    \n
    \n" - + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.kunyomi : depth0),{"name":"if","hash":{},"fn":container.program(8, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") - + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.onyomi : depth0),{"name":"if","hash":{},"fn":container.program(11, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + ((stack1 = helpers.each.call(alias1,(depth0 != null ? depth0.kunyomi : depth0),{"name":"each","hash":{},"fn":container.program(8, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + ((stack1 = helpers.each.call(alias1,(depth0 != null ? depth0.onyomi : depth0),{"name":"each","hash":{},"fn":container.program(8, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + "
    \n
    \n" - + ((stack1 = helpers["if"].call(alias1,((stack1 = (depth0 != null ? depth0.glossary : depth0)) != null ? stack1["1"] : stack1),{"name":"if","hash":{},"fn":container.program(13, data, 0),"inverse":container.program(16, data, 0),"data":data})) != null ? stack1 : "") + + ((stack1 = helpers["if"].call(alias1,((stack1 = (depth0 != null ? depth0.glossary : depth0)) != null ? stack1["1"] : stack1),{"name":"if","hash":{},"fn":container.program(10, data, 0),"inverse":container.program(13, data, 0),"data":data})) != null ? stack1 : "") + " \n
    \n" - + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.stats : depth0),{"name":"if","hash":{},"fn":container.program(18, data, 0),"inverse":container.program(21, data, 0),"data":data})) != null ? stack1 : "") + + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.stats : depth0),{"name":"if","hash":{},"fn":container.program(15, data, 0),"inverse":container.program(18, data, 0),"data":data})) != null ? stack1 : "") + "
    \n
    Dictionary Indices
    \n
    \n" - + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.indices : depth0),{"name":"if","hash":{},"fn":container.program(23, data, 0),"inverse":container.program(25, data, 0),"data":data})) != null ? stack1 : "") + + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.indices : depth0),{"name":"if","hash":{},"fn":container.program(20, data, 0),"inverse":container.program(22, data, 0),"data":data})) != null ? stack1 : "") + "
    \n
    \n\n" - + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.debug : depth0),{"name":"if","hash":{},"fn":container.program(27, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.debug : depth0),{"name":"if","hash":{},"fn":container.program(24, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + "\n"; },"2":function(container,depth0,helpers,partials,data) { return " \n \n"; @@ -58,40 +58,30 @@ templates['kanji.html'] = template({"1":function(container,depth0,helpers,partia + alias4(((helper = (helper = helpers.name || (depth0 != null ? depth0.name : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"name","hash":{},"data":data}) : helper))) + "\n"; },"8":function(container,depth0,helpers,partials,data) { - var stack1; - - return "
    Kun-Yomi
    \n" - + ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.kunyomi : depth0),{"name":"each","hash":{},"fn":container.program(9, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : ""); -},"9":function(container,depth0,helpers,partials,data) { return "
    " + container.escapeExpression(container.lambda(depth0, depth0)) + "
    \n"; -},"11":function(container,depth0,helpers,partials,data) { - var stack1; - - return "
    On-Yomi
    \n" - + ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.onyomi : depth0),{"name":"each","hash":{},"fn":container.program(9, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : ""); -},"13":function(container,depth0,helpers,partials,data) { +},"10":function(container,depth0,helpers,partials,data) { var stack1; return "
      \n" - + ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.glossary : depth0),{"name":"each","hash":{},"fn":container.program(14, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.glossary : depth0),{"name":"each","hash":{},"fn":container.program(11, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + "
    \n"; -},"14":function(container,depth0,helpers,partials,data) { +},"11":function(container,depth0,helpers,partials,data) { return "
  • " + container.escapeExpression(container.lambda(depth0, depth0)) + "
  • \n"; -},"16":function(container,depth0,helpers,partials,data) { +},"13":function(container,depth0,helpers,partials,data) { var stack1; return " " + container.escapeExpression(container.lambda(((stack1 = (depth0 != null ? depth0.glossary : depth0)) != null ? stack1["0"] : stack1), depth0)) + "\n"; -},"18":function(container,depth0,helpers,partials,data) { +},"15":function(container,depth0,helpers,partials,data) { var stack1; - return ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.stats : depth0),{"name":"each","hash":{},"fn":container.program(19, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : ""); -},"19":function(container,depth0,helpers,partials,data) { + return ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.stats : depth0),{"name":"each","hash":{},"fn":container.program(16, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : ""); +},"16":function(container,depth0,helpers,partials,data) { var helper, alias1=container.escapeExpression; return "
    " @@ -99,44 +89,44 @@ templates['kanji.html'] = template({"1":function(container,depth0,helpers,partia + ": " + alias1(container.lambda(depth0, depth0)) + "
    \n"; -},"21":function(container,depth0,helpers,partials,data) { +},"18":function(container,depth0,helpers,partials,data) { return " No statistical data found\n"; -},"23":function(container,depth0,helpers,partials,data) { +},"20":function(container,depth0,helpers,partials,data) { var stack1; - return ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.indices : depth0),{"name":"each","hash":{},"fn":container.program(19, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : ""); -},"25":function(container,depth0,helpers,partials,data) { + return ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.indices : depth0),{"name":"each","hash":{},"fn":container.program(16, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : ""); +},"22":function(container,depth0,helpers,partials,data) { return " No index data found\n"; -},"27":function(container,depth0,helpers,partials,data) { +},"24":function(container,depth0,helpers,partials,data) { var stack1, helper, options, buffer = "
    ";
    -  stack1 = ((helper = (helper = helpers.dumpObject || (depth0 != null ? depth0.dumpObject : depth0)) != null ? helper : helpers.helperMissing),(options={"name":"dumpObject","hash":{},"fn":container.program(28, data, 0),"inverse":container.noop,"data":data}),(typeof helper === "function" ? helper.call(depth0 != null ? depth0 : (container.nullContext || {}),options) : helper));
    +  stack1 = ((helper = (helper = helpers.dumpObject || (depth0 != null ? depth0.dumpObject : depth0)) != null ? helper : helpers.helperMissing),(options={"name":"dumpObject","hash":{},"fn":container.program(25, data, 0),"inverse":container.noop,"data":data}),(typeof helper === "function" ? helper.call(depth0 != null ? depth0 : (container.nullContext || {}),options) : helper));
       if (!helpers.dumpObject) { stack1 = helpers.blockHelperMissing.call(depth0,stack1,options)}
       if (stack1 != null) { buffer += stack1; }
       return buffer + "
    \n"; -},"28":function(container,depth0,helpers,partials,data) { +},"25":function(container,depth0,helpers,partials,data) { var stack1; return ((stack1 = container.lambda(depth0, depth0)) != null ? stack1 : ""); -},"30":function(container,depth0,helpers,partials,data,blockParams,depths) { +},"27":function(container,depth0,helpers,partials,data,blockParams,depths) { var stack1; - return ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.definitions : depth0),{"name":"each","hash":{},"fn":container.program(31, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : ""); -},"31":function(container,depth0,helpers,partials,data,blockParams,depths) { + return ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.definitions : depth0),{"name":"each","hash":{},"fn":container.program(28, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : ""); +},"28":function(container,depth0,helpers,partials,data,blockParams,depths) { var stack1; - return ((stack1 = helpers.unless.call(depth0 != null ? depth0 : (container.nullContext || {}),(data && data.first),{"name":"unless","hash":{},"fn":container.program(32, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "") + return ((stack1 = helpers.unless.call(depth0 != null ? depth0 : (container.nullContext || {}),(data && data.first),{"name":"unless","hash":{},"fn":container.program(29, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "") + "\n" + ((stack1 = container.invokePartial(partials.kanji,depth0,{"name":"kanji","hash":{"root":(depths[1] != null ? depths[1].root : depths[1]),"source":(depths[1] != null ? depths[1].source : depths[1]),"addable":(depths[1] != null ? depths[1].addable : depths[1]),"debug":(depths[1] != null ? depths[1].debug : depths[1])},"data":data,"helpers":helpers,"partials":partials,"decorators":container.decorators})) != null ? stack1 : ""); -},"32":function(container,depth0,helpers,partials,data) { +},"29":function(container,depth0,helpers,partials,data) { return "
    "; -},"34":function(container,depth0,helpers,partials,data) { +},"31":function(container,depth0,helpers,partials,data) { return "

    No results found

    \n"; },"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data,blockParams,depths) { var stack1; return "\n" - + ((stack1 = helpers["if"].call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.definitions : depth0),{"name":"if","hash":{},"fn":container.program(30, data, 0, blockParams, depths),"inverse":container.program(34, data, 0, blockParams, depths),"data":data})) != null ? stack1 : ""); + + ((stack1 = helpers["if"].call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.definitions : depth0),{"name":"if","hash":{},"fn":container.program(27, data, 0, blockParams, depths),"inverse":container.program(31, data, 0, blockParams, depths),"data":data})) != null ? stack1 : ""); },"main_d": function(fn, props, container, depth0, data, blockParams, depths) { var decorators = container.decorators; diff --git a/tmpl/kanji.html b/tmpl/kanji.html index 6cea57f9..ad6dcb26 100644 --- a/tmpl/kanji.html +++ b/tmpl/kanji.html @@ -28,18 +28,12 @@
    - {{#if kunyomi}} -
    Kun-Yomi
    {{#each kunyomi}}
    {{.}}
    {{/each}} - {{/if}} - {{#if onyomi}} -
    On-Yomi
    {{#each onyomi}}
    {{.}}
    {{/each}} - {{/if}}
    -- cgit v1.2.3 From d9d16613f8aa129de5dc1edb38d66f69d2983091 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sun, 17 Sep 2017 19:16:08 -0700 Subject: wip --- ext/bg/js/templates.js | 118 +++++++++++++++++++++++++++++----------------- ext/bg/js/translator.js | 32 +++++++++++-- ext/mixed/css/display.css | 8 ++++ tmpl/kanji.html | 44 +++++++++++------ 4 files changed, 141 insertions(+), 61 deletions(-) (limited to 'ext/bg') diff --git a/ext/bg/js/templates.js b/ext/bg/js/templates.js index 41bc58c9..55b09dfb 100644 --- a/ext/bg/js/templates.js +++ b/ext/bg/js/templates.js @@ -29,25 +29,47 @@ templates['kanji.html'] = template({"1":function(container,depth0,helpers,partia + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.source : depth0),{"name":"if","hash":{},"fn":container.program(4, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + " \n \n\n
    " + container.escapeExpression(((helper = (helper = helpers.character || (depth0 != null ? depth0.character : depth0)) != null ? helper : helpers.helperMissing),(typeof helper === "function" ? helper.call(alias1,{"name":"character","hash":{},"data":data}) : helper))) - + "
    \n\n
    \n" - + ((stack1 = helpers.each.call(alias1,(depth0 != null ? depth0.tags : depth0),{"name":"each","hash":{},"fn":container.program(6, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") - + "
    \n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
    ReadingsGlossaryStatistics
    \n
    \n" - + ((stack1 = helpers.each.call(alias1,(depth0 != null ? depth0.kunyomi : depth0),{"name":"each","hash":{},"fn":container.program(8, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") - + ((stack1 = helpers.each.call(alias1,(depth0 != null ? depth0.onyomi : depth0),{"name":"each","hash":{},"fn":container.program(8, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + "\n\n" + + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.frequencies : depth0),{"name":"if","hash":{},"fn":container.program(6, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + "\n" + + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.tags : depth0),{"name":"if","hash":{},"fn":container.program(9, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + "\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
    ReadingsGlossaryStatistics
    \n
    \n" + + ((stack1 = helpers.each.call(alias1,(depth0 != null ? depth0.kunyomi : depth0),{"name":"each","hash":{},"fn":container.program(12, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + ((stack1 = helpers.each.call(alias1,(depth0 != null ? depth0.onyomi : depth0),{"name":"each","hash":{},"fn":container.program(12, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + "
    \n
    \n" - + ((stack1 = helpers["if"].call(alias1,((stack1 = (depth0 != null ? depth0.glossary : depth0)) != null ? stack1["1"] : stack1),{"name":"if","hash":{},"fn":container.program(10, data, 0),"inverse":container.program(13, data, 0),"data":data})) != null ? stack1 : "") - + " \n
    \n" - + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.stats : depth0),{"name":"if","hash":{},"fn":container.program(15, data, 0),"inverse":container.program(18, data, 0),"data":data})) != null ? stack1 : "") - + "
    \n
    Dictionary Indices
    \n
    \n" - + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.indices : depth0),{"name":"if","hash":{},"fn":container.program(20, data, 0),"inverse":container.program(22, data, 0),"data":data})) != null ? stack1 : "") - + "
    \n
    \n\n" - + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.debug : depth0),{"name":"if","hash":{},"fn":container.program(24, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + ((stack1 = helpers["if"].call(alias1,((stack1 = (depth0 != null ? depth0.glossary : depth0)) != null ? stack1["1"] : stack1),{"name":"if","hash":{},"fn":container.program(14, data, 0),"inverse":container.program(17, data, 0),"data":data})) != null ? stack1 : "") + + "
    \n" + + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.stats : depth0),{"name":"if","hash":{},"fn":container.program(19, data, 0),"inverse":container.program(25, data, 0),"data":data})) != null ? stack1 : "") + + "
    Dictionary Indices
    \n" + + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.indices : depth0),{"name":"if","hash":{},"fn":container.program(27, data, 0),"inverse":container.program(29, data, 0),"data":data})) != null ? stack1 : "") + + "
    \n\n" + + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.debug : depth0),{"name":"if","hash":{},"fn":container.program(31, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + "\n"; },"2":function(container,depth0,helpers,partials,data) { return " \n \n"; },"4":function(container,depth0,helpers,partials,data) { return " \n"; },"6":function(container,depth0,helpers,partials,data) { + var stack1; + + return "
    \n" + + ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.frequencies : depth0),{"name":"each","hash":{},"fn":container.program(7, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + "
    \n"; +},"7":function(container,depth0,helpers,partials,data) { + var helper, alias1=depth0 != null ? depth0 : (container.nullContext || {}), alias2=helpers.helperMissing, alias3="function", alias4=container.escapeExpression; + + return " " + + alias4(((helper = (helper = helpers.dictionary || (depth0 != null ? depth0.dictionary : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"dictionary","hash":{},"data":data}) : helper))) + + ":" + + alias4(((helper = (helper = helpers.frequency || (depth0 != null ? depth0.frequency : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"frequency","hash":{},"data":data}) : helper))) + + "\n"; +},"9":function(container,depth0,helpers,partials,data) { + var stack1; + + return "
    \n" + + ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.tags : depth0),{"name":"each","hash":{},"fn":container.program(10, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + "
    \n"; +},"10":function(container,depth0,helpers,partials,data) { var helper, alias1=depth0 != null ? depth0 : (container.nullContext || {}), alias2=helpers.helperMissing, alias3="function", alias4=container.escapeExpression; return " " + alias4(((helper = (helper = helpers.name || (depth0 != null ? depth0.name : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"name","hash":{},"data":data}) : helper))) + "\n"; -},"8":function(container,depth0,helpers,partials,data) { +},"12":function(container,depth0,helpers,partials,data) { return "
    " + container.escapeExpression(container.lambda(depth0, depth0)) + "
    \n"; -},"10":function(container,depth0,helpers,partials,data) { +},"14":function(container,depth0,helpers,partials,data) { var stack1; return "
      \n" - + ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.glossary : depth0),{"name":"each","hash":{},"fn":container.program(11, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.glossary : depth0),{"name":"each","hash":{},"fn":container.program(15, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + "
    \n"; -},"11":function(container,depth0,helpers,partials,data) { +},"15":function(container,depth0,helpers,partials,data) { return "
  • " + container.escapeExpression(container.lambda(depth0, depth0)) + "
  • \n"; -},"13":function(container,depth0,helpers,partials,data) { +},"17":function(container,depth0,helpers,partials,data) { var stack1; return " " + container.escapeExpression(container.lambda(((stack1 = (depth0 != null ? depth0.glossary : depth0)) != null ? stack1["0"] : stack1), depth0)) + "\n"; -},"15":function(container,depth0,helpers,partials,data) { +},"19":function(container,depth0,helpers,partials,data) { var stack1; - return ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.stats : depth0),{"name":"each","hash":{},"fn":container.program(16, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : ""); -},"16":function(container,depth0,helpers,partials,data) { - var helper, alias1=container.escapeExpression; - - return "
    " - + alias1(((helper = (helper = helpers.key || (data && data.key)) != null ? helper : helpers.helperMissing),(typeof helper === "function" ? helper.call(depth0 != null ? depth0 : (container.nullContext || {}),{"name":"key","hash":{},"data":data}) : helper))) - + ": " - + alias1(container.lambda(depth0, depth0)) - + "
    \n"; -},"18":function(container,depth0,helpers,partials,data) { - return " No statistical data found\n"; + return " \n" + + ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.stats : depth0),{"name":"each","hash":{},"fn":container.program(20, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + "
    \n"; },"20":function(container,depth0,helpers,partials,data) { + var stack1, helper, alias1=depth0 != null ? depth0 : (container.nullContext || {}); + + return " \n " + + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.notes : depth0),{"name":"if","hash":{},"fn":container.program(21, data, 0),"inverse":container.program(23, data, 0),"data":data})) != null ? stack1 : "") + + "\n " + + container.escapeExpression(((helper = (helper = helpers.value || (depth0 != null ? depth0.value : depth0)) != null ? helper : helpers.helperMissing),(typeof helper === "function" ? helper.call(alias1,{"name":"value","hash":{},"data":data}) : helper))) + + "\n \n"; +},"21":function(container,depth0,helpers,partials,data) { + var helper; + + return container.escapeExpression(((helper = (helper = helpers.notes || (depth0 != null ? depth0.notes : depth0)) != null ? helper : helpers.helperMissing),(typeof helper === "function" ? helper.call(depth0 != null ? depth0 : (container.nullContext || {}),{"name":"notes","hash":{},"data":data}) : helper))); +},"23":function(container,depth0,helpers,partials,data) { + var helper; + + return container.escapeExpression(((helper = (helper = helpers.name || (depth0 != null ? depth0.name : depth0)) != null ? helper : helpers.helperMissing),(typeof helper === "function" ? helper.call(depth0 != null ? depth0 : (container.nullContext || {}),{"name":"name","hash":{},"data":data}) : helper))); +},"25":function(container,depth0,helpers,partials,data) { + return " No statistical data found\n"; +},"27":function(container,depth0,helpers,partials,data) { var stack1; - return ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.indices : depth0),{"name":"each","hash":{},"fn":container.program(16, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : ""); -},"22":function(container,depth0,helpers,partials,data) { - return " No index data found\n"; -},"24":function(container,depth0,helpers,partials,data) { + return " \n" + + ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.indices : depth0),{"name":"each","hash":{},"fn":container.program(20, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + "
    \n"; +},"29":function(container,depth0,helpers,partials,data) { + return " No index data found\n"; +},"31":function(container,depth0,helpers,partials,data) { var stack1, helper, options, buffer = "
    ";
    -  stack1 = ((helper = (helper = helpers.dumpObject || (depth0 != null ? depth0.dumpObject : depth0)) != null ? helper : helpers.helperMissing),(options={"name":"dumpObject","hash":{},"fn":container.program(25, data, 0),"inverse":container.noop,"data":data}),(typeof helper === "function" ? helper.call(depth0 != null ? depth0 : (container.nullContext || {}),options) : helper));
    +  stack1 = ((helper = (helper = helpers.dumpObject || (depth0 != null ? depth0.dumpObject : depth0)) != null ? helper : helpers.helperMissing),(options={"name":"dumpObject","hash":{},"fn":container.program(32, data, 0),"inverse":container.noop,"data":data}),(typeof helper === "function" ? helper.call(depth0 != null ? depth0 : (container.nullContext || {}),options) : helper));
       if (!helpers.dumpObject) { stack1 = helpers.blockHelperMissing.call(depth0,stack1,options)}
       if (stack1 != null) { buffer += stack1; }
       return buffer + "
    \n"; -},"25":function(container,depth0,helpers,partials,data) { +},"32":function(container,depth0,helpers,partials,data) { var stack1; return ((stack1 = container.lambda(depth0, depth0)) != null ? stack1 : ""); -},"27":function(container,depth0,helpers,partials,data,blockParams,depths) { +},"34":function(container,depth0,helpers,partials,data,blockParams,depths) { var stack1; - return ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.definitions : depth0),{"name":"each","hash":{},"fn":container.program(28, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : ""); -},"28":function(container,depth0,helpers,partials,data,blockParams,depths) { + return ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.definitions : depth0),{"name":"each","hash":{},"fn":container.program(35, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : ""); +},"35":function(container,depth0,helpers,partials,data,blockParams,depths) { var stack1; - return ((stack1 = helpers.unless.call(depth0 != null ? depth0 : (container.nullContext || {}),(data && data.first),{"name":"unless","hash":{},"fn":container.program(29, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "") + return ((stack1 = helpers.unless.call(depth0 != null ? depth0 : (container.nullContext || {}),(data && data.first),{"name":"unless","hash":{},"fn":container.program(36, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "") + "\n" + ((stack1 = container.invokePartial(partials.kanji,depth0,{"name":"kanji","hash":{"root":(depths[1] != null ? depths[1].root : depths[1]),"source":(depths[1] != null ? depths[1].source : depths[1]),"addable":(depths[1] != null ? depths[1].addable : depths[1]),"debug":(depths[1] != null ? depths[1].debug : depths[1])},"data":data,"helpers":helpers,"partials":partials,"decorators":container.decorators})) != null ? stack1 : ""); -},"29":function(container,depth0,helpers,partials,data) { +},"36":function(container,depth0,helpers,partials,data) { return "
    "; -},"31":function(container,depth0,helpers,partials,data) { +},"38":function(container,depth0,helpers,partials,data) { return "

    No results found

    \n"; },"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data,blockParams,depths) { var stack1; return "\n" - + ((stack1 = helpers["if"].call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.definitions : depth0),{"name":"if","hash":{},"fn":container.program(27, data, 0, blockParams, depths),"inverse":container.program(31, data, 0, blockParams, depths),"data":data})) != null ? stack1 : ""); + + ((stack1 = helpers["if"].call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.definitions : depth0),{"name":"if","hash":{},"fn":container.program(34, data, 0, blockParams, depths),"inverse":container.program(38, data, 0, blockParams, depths),"data":data})) != null ? stack1 : ""); },"main_d": function(fn, props, container, depth0, data, blockParams, depths) { var decorators = container.decorators; diff --git a/ext/bg/js/translator.js b/ext/bg/js/translator.js index 3dd482ca..ef2227ea 100644 --- a/ext/bg/js/translator.js +++ b/ext/bg/js/translator.js @@ -78,7 +78,7 @@ class Translator { let definitions = []; for (const deinflection of deinflections) { for (const definition of deinflection.definitions) { - const tags = await this.expandTags(definition); + const tags = await this.expandTags(definition.tags, definition.dictionary); tags.push(dictTagBuildSource(definition.dictionary)); definitions.push({ @@ -136,9 +136,12 @@ class Translator { } for (const definition of definitions) { - const tags = await this.expandTags(definition); + const tags = await this.expandTags(definition.tags, definition.dictionary); tags.push(dictTagBuildSource(definition.dictionary)); + definition.tags = dictTagsSort(tags); + definition.stats = await this.expandTaggedValues(definition.stats, definition.dictionary); + definition.indices = await this.expandTaggedValues(definition.indices, definition.dictionary); definition.frequencies = await this.database.findKanjiFreq(definition.character, titles); } @@ -152,11 +155,11 @@ class Translator { } } - async expandTags(definition) { + async expandTags(names, title) { const tags = []; - for (const name of definition.tags) { + for (const name of names) { const base = name.split(':')[0]; - const meta = await this.database.findTagForTitle(base, definition.dictionary); + const meta = await this.database.findTagForTitle(base, title); const tag = {name}; for (const prop in meta || {}) { @@ -170,4 +173,23 @@ class Translator { return tags; } + + async expandTaggedValues(items, title) { + const tags = []; + for (const name in items) { + const base = name.split(':')[0]; + const meta = await this.database.findTagForTitle(base, title); + + const tag = {name, value: items[name]}; + for (const prop in meta || {}) { + if (prop !== 'name') { + tag[prop] = meta[prop]; + } + } + + tags.push(dictTagSanitize(tag)); + } + + return tags; + } } diff --git a/ext/mixed/css/display.css b/ext/mixed/css/display.css index 92480bab..cdc1be8c 100644 --- a/ext/mixed/css/display.css +++ b/ext/mixed/css/display.css @@ -152,3 +152,11 @@ hr { .glyph-data { margin-top: 10px; } + +.info-output { + width: 100%; +} + +.info-output td { + text-align: right; +} diff --git a/tmpl/kanji.html b/tmpl/kanji.html index ad6dcb26..57b6b7dc 100644 --- a/tmpl/kanji.html +++ b/tmpl/kanji.html @@ -13,11 +13,21 @@
    {{character}}
    + {{#if frequencies}} +
    + {{#each frequencies}} + {{dictionary}}:{{frequency}} + {{/each}} +
    + {{/if}} + + {{#if tags}}
    {{#each tags}} {{name}} {{/each}}
    + {{/if}} @@ -48,15 +58,18 @@ {{/if}} @@ -64,15 +77,18 @@
    -
    - {{#if stats}} + {{#if stats}} + {{#each stats}} -
    {{@key}}: {{.}}
    + + + + {{/each}} - {{else}} - No statistical data found - {{/if}} - +
    {{#if notes}}{{notes}}{{else}}{{name}}{{/if}}{{value}}
    + {{else}} + No statistical data found + {{/if}}
    -
    - {{#if indices}} + {{#if indices}} + {{#each indices}} -
    {{@key}}: {{.}}
    + + + + {{/each}} - {{else}} - No index data found - {{/if}} - +
    {{#if notes}}{{notes}}{{else}}{{name}}{{/if}}{{value}}
    + {{else}} + No index data found + {{/if}}
    -- cgit v1.2.3 From e90274519a57d43e77e864ed3259d1b6c73654be Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sun, 17 Sep 2017 19:57:39 -0700 Subject: combine indices and stats --- ext/bg/js/database.js | 4 +--- ext/bg/js/translator.js | 15 +++++++-------- 2 files changed, 8 insertions(+), 11 deletions(-) (limited to 'ext/bg') diff --git a/ext/bg/js/database.js b/ext/bg/js/database.js index 0acf974f..f94c572e 100644 --- a/ext/bg/js/database.js +++ b/ext/bg/js/database.js @@ -110,7 +110,6 @@ class Database { kunyomi: dictFieldSplit(row.kunyomi), tags: dictFieldSplit(row.tags), glossary: row.meanings, - indices: row.indices, stats: row.stats, dictionary: row.dictionary }); @@ -252,14 +251,13 @@ class Database { }); } } else { - for (const [character, onyomi, kunyomi, tags, meanings, indices, stats] of entries) { + for (const [character, onyomi, kunyomi, tags, meanings, stats] of entries) { rows.push({ character, onyomi, kunyomi, tags, meanings, - indices, stats, dictionary: summary.title }); diff --git a/ext/bg/js/translator.js b/ext/bg/js/translator.js index ef2227ea..7583d39a 100644 --- a/ext/bg/js/translator.js +++ b/ext/bg/js/translator.js @@ -140,8 +140,7 @@ class Translator { tags.push(dictTagBuildSource(definition.dictionary)); definition.tags = dictTagsSort(tags); - definition.stats = await this.expandTaggedValues(definition.stats, definition.dictionary); - definition.indices = await this.expandTaggedValues(definition.indices, definition.dictionary); + definition.stats = await this.expandStats(definition.stats, definition.dictionary); definition.frequencies = await this.database.findKanjiFreq(definition.character, titles); } @@ -174,22 +173,22 @@ class Translator { return tags; } - async expandTaggedValues(items, title) { - const tags = []; + async expandStats(items, title) { + const stats = []; for (const name in items) { const base = name.split(':')[0]; const meta = await this.database.findTagForTitle(base, title); - const tag = {name, value: items[name]}; + const stat = {name, value: items[name]}; for (const prop in meta || {}) { if (prop !== 'name') { - tag[prop] = meta[prop]; + stat[prop] = meta[prop]; } } - tags.push(dictTagSanitize(tag)); + stats.push(dictTagSanitize(stat)); } - return tags; + return stats; } } -- cgit v1.2.3 From 119def2bebc9adea3a29e9152c7e4747d81d54fa Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Wed, 20 Sep 2017 23:15:02 -0700 Subject: wip --- ext/bg/js/templates.js | 38 ++++++++++++++------------------------ ext/bg/js/translator.js | 5 +++-- tmpl/kanji.html | 19 +++---------------- 3 files changed, 20 insertions(+), 42 deletions(-) (limited to 'ext/bg') diff --git a/ext/bg/js/templates.js b/ext/bg/js/templates.js index 55b09dfb..d501e5d8 100644 --- a/ext/bg/js/templates.js +++ b/ext/bg/js/templates.js @@ -38,12 +38,10 @@ templates['kanji.html'] = template({"1":function(container,depth0,helpers,partia + ((stack1 = helpers.each.call(alias1,(depth0 != null ? depth0.onyomi : depth0),{"name":"each","hash":{},"fn":container.program(12, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + " \n \n \n" + ((stack1 = helpers["if"].call(alias1,((stack1 = (depth0 != null ? depth0.glossary : depth0)) != null ? stack1["1"] : stack1),{"name":"if","hash":{},"fn":container.program(14, data, 0),"inverse":container.program(17, data, 0),"data":data})) != null ? stack1 : "") - + " \n \n" - + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.stats : depth0),{"name":"if","hash":{},"fn":container.program(19, data, 0),"inverse":container.program(25, data, 0),"data":data})) != null ? stack1 : "") - + " \n \n \n Dictionary Indices\n \n \n \n" - + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.indices : depth0),{"name":"if","hash":{},"fn":container.program(27, data, 0),"inverse":container.program(29, data, 0),"data":data})) != null ? stack1 : "") + + " \n \n \n \n Dictionary Indices\n \n \n \n" + + ((stack1 = helpers["if"].call(alias1,((stack1 = (depth0 != null ? depth0.stats : depth0)) != null ? stack1.indices : stack1),{"name":"if","hash":{},"fn":container.program(19, data, 0),"inverse":container.program(25, data, 0),"data":data})) != null ? stack1 : "") + " \n \n \n\n" - + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.debug : depth0),{"name":"if","hash":{},"fn":container.program(31, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.debug : depth0),{"name":"if","hash":{},"fn":container.program(27, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + "\n"; },"2":function(container,depth0,helpers,partials,data) { return " \n \n"; @@ -103,7 +101,7 @@ templates['kanji.html'] = template({"1":function(container,depth0,helpers,partia var stack1; return " \n" - + ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.stats : depth0),{"name":"each","hash":{},"fn":container.program(20, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),((stack1 = (depth0 != null ? depth0.stats : depth0)) != null ? stack1.indices : stack1),{"name":"each","hash":{},"fn":container.program(20, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + "
    \n"; },"20":function(container,depth0,helpers,partials,data) { var stack1, helper, alias1=depth0 != null ? depth0 : (container.nullContext || {}); @@ -122,45 +120,37 @@ templates['kanji.html'] = template({"1":function(container,depth0,helpers,partia return container.escapeExpression(((helper = (helper = helpers.name || (depth0 != null ? depth0.name : depth0)) != null ? helper : helpers.helperMissing),(typeof helper === "function" ? helper.call(depth0 != null ? depth0 : (container.nullContext || {}),{"name":"name","hash":{},"data":data}) : helper))); },"25":function(container,depth0,helpers,partials,data) { - return " No statistical data found\n"; -},"27":function(container,depth0,helpers,partials,data) { - var stack1; - - return " \n" - + ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.indices : depth0),{"name":"each","hash":{},"fn":container.program(20, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") - + "
    \n"; -},"29":function(container,depth0,helpers,partials,data) { return " No index data found\n"; -},"31":function(container,depth0,helpers,partials,data) { +},"27":function(container,depth0,helpers,partials,data) { var stack1, helper, options, buffer = "
    ";
    -  stack1 = ((helper = (helper = helpers.dumpObject || (depth0 != null ? depth0.dumpObject : depth0)) != null ? helper : helpers.helperMissing),(options={"name":"dumpObject","hash":{},"fn":container.program(32, data, 0),"inverse":container.noop,"data":data}),(typeof helper === "function" ? helper.call(depth0 != null ? depth0 : (container.nullContext || {}),options) : helper));
    +  stack1 = ((helper = (helper = helpers.dumpObject || (depth0 != null ? depth0.dumpObject : depth0)) != null ? helper : helpers.helperMissing),(options={"name":"dumpObject","hash":{},"fn":container.program(28, data, 0),"inverse":container.noop,"data":data}),(typeof helper === "function" ? helper.call(depth0 != null ? depth0 : (container.nullContext || {}),options) : helper));
       if (!helpers.dumpObject) { stack1 = helpers.blockHelperMissing.call(depth0,stack1,options)}
       if (stack1 != null) { buffer += stack1; }
       return buffer + "
    \n"; -},"32":function(container,depth0,helpers,partials,data) { +},"28":function(container,depth0,helpers,partials,data) { var stack1; return ((stack1 = container.lambda(depth0, depth0)) != null ? stack1 : ""); -},"34":function(container,depth0,helpers,partials,data,blockParams,depths) { +},"30":function(container,depth0,helpers,partials,data,blockParams,depths) { var stack1; - return ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.definitions : depth0),{"name":"each","hash":{},"fn":container.program(35, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : ""); -},"35":function(container,depth0,helpers,partials,data,blockParams,depths) { + return ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.definitions : depth0),{"name":"each","hash":{},"fn":container.program(31, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : ""); +},"31":function(container,depth0,helpers,partials,data,blockParams,depths) { var stack1; - return ((stack1 = helpers.unless.call(depth0 != null ? depth0 : (container.nullContext || {}),(data && data.first),{"name":"unless","hash":{},"fn":container.program(36, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "") + return ((stack1 = helpers.unless.call(depth0 != null ? depth0 : (container.nullContext || {}),(data && data.first),{"name":"unless","hash":{},"fn":container.program(32, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "") + "\n" + ((stack1 = container.invokePartial(partials.kanji,depth0,{"name":"kanji","hash":{"root":(depths[1] != null ? depths[1].root : depths[1]),"source":(depths[1] != null ? depths[1].source : depths[1]),"addable":(depths[1] != null ? depths[1].addable : depths[1]),"debug":(depths[1] != null ? depths[1].debug : depths[1])},"data":data,"helpers":helpers,"partials":partials,"decorators":container.decorators})) != null ? stack1 : ""); -},"36":function(container,depth0,helpers,partials,data) { +},"32":function(container,depth0,helpers,partials,data) { return "
    "; -},"38":function(container,depth0,helpers,partials,data) { +},"34":function(container,depth0,helpers,partials,data) { return "

    No results found

    \n"; },"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data,blockParams,depths) { var stack1; return "\n" - + ((stack1 = helpers["if"].call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.definitions : depth0),{"name":"if","hash":{},"fn":container.program(34, data, 0, blockParams, depths),"inverse":container.program(38, data, 0, blockParams, depths),"data":data})) != null ? stack1 : ""); + + ((stack1 = helpers["if"].call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.definitions : depth0),{"name":"if","hash":{},"fn":container.program(30, data, 0, blockParams, depths),"inverse":container.program(34, data, 0, blockParams, depths),"data":data})) != null ? stack1 : ""); },"main_d": function(fn, props, container, depth0, data, blockParams, depths) { var decorators = container.decorators; diff --git a/ext/bg/js/translator.js b/ext/bg/js/translator.js index 7583d39a..454799a3 100644 --- a/ext/bg/js/translator.js +++ b/ext/bg/js/translator.js @@ -174,10 +174,11 @@ class Translator { } async expandStats(items, title) { - const stats = []; + const stats = {}; for (const name in items) { const base = name.split(':')[0]; const meta = await this.database.findTagForTitle(base, title); + const group = stats[meta.category] || []; const stat = {name, value: items[name]}; for (const prop in meta || {}) { @@ -186,7 +187,7 @@ class Translator { } } - stats.push(dictTagSanitize(stat)); + group.push(dictTagSanitize(stat)); } return stats; diff --git a/tmpl/kanji.html b/tmpl/kanji.html index 57b6b7dc..354e097d 100644 --- a/tmpl/kanji.html +++ b/tmpl/kanji.html @@ -57,29 +57,16 @@ {{glossary.[0]}} {{/if}} - - {{#if stats}} - - {{#each stats}} - - - - - {{/each}} -
    {{#if notes}}{{notes}}{{else}}{{name}}{{/if}}{{value}}
    - {{else}} - No statistical data found - {{/if}} - + Dictionary Indices - {{#if indices}} + {{#if stats.indices}} - {{#each indices}} + {{#each stats.indices}} -- cgit v1.2.3 From 65ce976423e241b50baa69b4d074b981d4de1f3e Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Thu, 21 Sep 2017 09:21:32 -0700 Subject: wip --- ext/bg/js/templates.js | 4 ++-- ext/bg/js/translator.js | 2 +- tmpl/kanji.html | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) (limited to 'ext/bg') diff --git a/ext/bg/js/templates.js b/ext/bg/js/templates.js index d501e5d8..ddf9740a 100644 --- a/ext/bg/js/templates.js +++ b/ext/bg/js/templates.js @@ -39,7 +39,7 @@ templates['kanji.html'] = template({"1":function(container,depth0,helpers,partia + " \n \n \n \n \n \n \n \n \n \n \n
    {{#if notes}}{{notes}}{{else}}{{name}}{{/if}} {{value}}\n" + ((stack1 = helpers["if"].call(alias1,((stack1 = (depth0 != null ? depth0.glossary : depth0)) != null ? stack1["1"] : stack1),{"name":"if","hash":{},"fn":container.program(14, data, 0),"inverse":container.program(17, data, 0),"data":data})) != null ? stack1 : "") + "
    Dictionary Indices
    \n" - + ((stack1 = helpers["if"].call(alias1,((stack1 = (depth0 != null ? depth0.stats : depth0)) != null ? stack1.indices : stack1),{"name":"if","hash":{},"fn":container.program(19, data, 0),"inverse":container.program(25, data, 0),"data":data})) != null ? stack1 : "") + + ((stack1 = helpers["if"].call(alias1,((stack1 = (depth0 != null ? depth0.stats : depth0)) != null ? stack1["default"] : stack1),{"name":"if","hash":{},"fn":container.program(19, data, 0),"inverse":container.program(25, data, 0),"data":data})) != null ? stack1 : "") + "
    \n\n" + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.debug : depth0),{"name":"if","hash":{},"fn":container.program(27, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + "\n"; @@ -101,7 +101,7 @@ templates['kanji.html'] = template({"1":function(container,depth0,helpers,partia var stack1; return " \n" - + ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),((stack1 = (depth0 != null ? depth0.stats : depth0)) != null ? stack1.indices : stack1),{"name":"each","hash":{},"fn":container.program(20, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),((stack1 = (depth0 != null ? depth0.stats : depth0)) != null ? stack1["default"] : stack1),{"name":"each","hash":{},"fn":container.program(20, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + "
    \n"; },"20":function(container,depth0,helpers,partials,data) { var stack1, helper, alias1=depth0 != null ? depth0 : (container.nullContext || {}); diff --git a/ext/bg/js/translator.js b/ext/bg/js/translator.js index 454799a3..cc0336e7 100644 --- a/ext/bg/js/translator.js +++ b/ext/bg/js/translator.js @@ -178,7 +178,7 @@ class Translator { for (const name in items) { const base = name.split(':')[0]; const meta = await this.database.findTagForTitle(base, title); - const group = stats[meta.category] || []; + const group = stats[meta.category] = stats[meta.category] || []; const stat = {name, value: items[name]}; for (const prop in meta || {}) { diff --git a/tmpl/kanji.html b/tmpl/kanji.html index 354e097d..02fe8e92 100644 --- a/tmpl/kanji.html +++ b/tmpl/kanji.html @@ -64,9 +64,9 @@ - {{#if stats.indices}} + {{#if stats.default}} - {{#each stats.indices}} + {{#each stats.default}} -- cgit v1.2.3 From 2ba01d2910fb0992b372d74854e2624541233127 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Thu, 21 Sep 2017 11:14:17 -0700 Subject: fix dictionary indices --- ext/bg/js/templates.js | 4 ++-- tmpl/kanji.html | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'ext/bg') diff --git a/ext/bg/js/templates.js b/ext/bg/js/templates.js index ddf9740a..aa98b3cf 100644 --- a/ext/bg/js/templates.js +++ b/ext/bg/js/templates.js @@ -39,7 +39,7 @@ templates['kanji.html'] = template({"1":function(container,depth0,helpers,partia + " \n \n \n \n \n \n \n \n \n \n \n
    {{#if notes}}{{notes}}{{else}}{{name}}{{/if}} {{value}}\n" + ((stack1 = helpers["if"].call(alias1,((stack1 = (depth0 != null ? depth0.glossary : depth0)) != null ? stack1["1"] : stack1),{"name":"if","hash":{},"fn":container.program(14, data, 0),"inverse":container.program(17, data, 0),"data":data})) != null ? stack1 : "") + "
    Dictionary Indices
    \n" - + ((stack1 = helpers["if"].call(alias1,((stack1 = (depth0 != null ? depth0.stats : depth0)) != null ? stack1["default"] : stack1),{"name":"if","hash":{},"fn":container.program(19, data, 0),"inverse":container.program(25, data, 0),"data":data})) != null ? stack1 : "") + + ((stack1 = helpers["if"].call(alias1,((stack1 = (depth0 != null ? depth0.stats : depth0)) != null ? stack1.index : stack1),{"name":"if","hash":{},"fn":container.program(19, data, 0),"inverse":container.program(25, data, 0),"data":data})) != null ? stack1 : "") + "
    \n\n" + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.debug : depth0),{"name":"if","hash":{},"fn":container.program(27, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + "\n"; @@ -101,7 +101,7 @@ templates['kanji.html'] = template({"1":function(container,depth0,helpers,partia var stack1; return " \n" - + ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),((stack1 = (depth0 != null ? depth0.stats : depth0)) != null ? stack1["default"] : stack1),{"name":"each","hash":{},"fn":container.program(20, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),((stack1 = (depth0 != null ? depth0.stats : depth0)) != null ? stack1.index : stack1),{"name":"each","hash":{},"fn":container.program(20, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + "
    \n"; },"20":function(container,depth0,helpers,partials,data) { var stack1, helper, alias1=depth0 != null ? depth0 : (container.nullContext || {}); diff --git a/tmpl/kanji.html b/tmpl/kanji.html index 02fe8e92..c46ce6a7 100644 --- a/tmpl/kanji.html +++ b/tmpl/kanji.html @@ -64,9 +64,9 @@ - {{#if stats.default}} + {{#if stats.index}} - {{#each stats.default}} + {{#each stats.index}} -- cgit v1.2.3 From a55576260a3f2d5acfd256ac93a58302dd761624 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Thu, 21 Sep 2017 20:52:18 -0700 Subject: work on kanji page --- ext/bg/js/templates.js | 150 ++++++++++++++++++++++++++----------------------- tmpl/kanji.html | 67 +++++++++++----------- 2 files changed, 116 insertions(+), 101 deletions(-) (limited to 'ext/bg') diff --git a/ext/bg/js/templates.js b/ext/bg/js/templates.js index aa98b3cf..4320acb7 100644 --- a/ext/bg/js/templates.js +++ b/ext/bg/js/templates.js @@ -22,38 +22,73 @@ templates['dictionary.html'] = template({"1":function(container,depth0,helpers,p + "\" class=\"form-control dict-priority\">\n \n\n"; },"useData":true}); templates['kanji.html'] = template({"1":function(container,depth0,helpers,partials,data) { + var stack1; + + return ((stack1 = helpers["if"].call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.data : depth0),{"name":"if","hash":{},"fn":container.program(2, data, 0),"inverse":container.program(8, data, 0),"data":data})) != null ? stack1 : ""); +},"2":function(container,depth0,helpers,partials,data) { + var stack1; + + return "
    {{#if notes}}{{notes}}{{else}}{{name}}{{/if}} {{value}}
    \n" + + ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.data : depth0),{"name":"each","hash":{},"fn":container.program(3, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + "
    \n"; +},"3":function(container,depth0,helpers,partials,data) { + var stack1, helper, alias1=depth0 != null ? depth0 : (container.nullContext || {}); + + return " \n " + + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.notes : depth0),{"name":"if","hash":{},"fn":container.program(4, data, 0),"inverse":container.program(6, data, 0),"data":data})) != null ? stack1 : "") + + "\n " + + container.escapeExpression(((helper = (helper = helpers.value || (depth0 != null ? depth0.value : depth0)) != null ? helper : helpers.helperMissing),(typeof helper === "function" ? helper.call(alias1,{"name":"value","hash":{},"data":data}) : helper))) + + "\n \n"; +},"4":function(container,depth0,helpers,partials,data) { + var helper; + + return container.escapeExpression(((helper = (helper = helpers.notes || (depth0 != null ? depth0.notes : depth0)) != null ? helper : helpers.helperMissing),(typeof helper === "function" ? helper.call(depth0 != null ? depth0 : (container.nullContext || {}),{"name":"notes","hash":{},"data":data}) : helper))); +},"6":function(container,depth0,helpers,partials,data) { + var helper; + + return container.escapeExpression(((helper = (helper = helpers.name || (depth0 != null ? depth0.name : depth0)) != null ? helper : helpers.helperMissing),(typeof helper === "function" ? helper.call(depth0 != null ? depth0 : (container.nullContext || {}),{"name":"name","hash":{},"data":data}) : helper))); +},"8":function(container,depth0,helpers,partials,data) { + return "No data found\n"; +},"10":function(container,depth0,helpers,partials,data) { var stack1, helper, alias1=depth0 != null ? depth0 : (container.nullContext || {}); return "
    \n
    \n" - + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.addable : depth0),{"name":"if","hash":{},"fn":container.program(2, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") - + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.source : depth0),{"name":"if","hash":{},"fn":container.program(4, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.addable : depth0),{"name":"if","hash":{},"fn":container.program(11, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.source : depth0),{"name":"if","hash":{},"fn":container.program(13, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + " \n
    \n\n
    " + container.escapeExpression(((helper = (helper = helpers.character || (depth0 != null ? depth0.character : depth0)) != null ? helper : helpers.helperMissing),(typeof helper === "function" ? helper.call(alias1,{"name":"character","hash":{},"data":data}) : helper))) + "
    \n\n" - + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.frequencies : depth0),{"name":"if","hash":{},"fn":container.program(6, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.frequencies : depth0),{"name":"if","hash":{},"fn":container.program(15, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + "\n" - + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.tags : depth0),{"name":"if","hash":{},"fn":container.program(9, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") - + "\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
    ReadingsGlossaryStatistics
    \n
    \n" - + ((stack1 = helpers.each.call(alias1,(depth0 != null ? depth0.kunyomi : depth0),{"name":"each","hash":{},"fn":container.program(12, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") - + ((stack1 = helpers.each.call(alias1,(depth0 != null ? depth0.onyomi : depth0),{"name":"each","hash":{},"fn":container.program(12, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") - + "
    \n
    \n" - + ((stack1 = helpers["if"].call(alias1,((stack1 = (depth0 != null ? depth0.glossary : depth0)) != null ? stack1["1"] : stack1),{"name":"if","hash":{},"fn":container.program(14, data, 0),"inverse":container.program(17, data, 0),"data":data})) != null ? stack1 : "") - + "
    Dictionary Indices
    \n" - + ((stack1 = helpers["if"].call(alias1,((stack1 = (depth0 != null ? depth0.stats : depth0)) != null ? stack1.index : stack1),{"name":"if","hash":{},"fn":container.program(19, data, 0),"inverse":container.program(25, data, 0),"data":data})) != null ? stack1 : "") - + "
    \n\n" - + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.debug : depth0),{"name":"if","hash":{},"fn":container.program(27, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.tags : depth0),{"name":"if","hash":{},"fn":container.program(18, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + "\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
    GlossaryOn'YomiKun'Yomi
    \n" + + ((stack1 = helpers["if"].call(alias1,((stack1 = (depth0 != null ? depth0.glossary : depth0)) != null ? stack1["1"] : stack1),{"name":"if","hash":{},"fn":container.program(21, data, 0),"inverse":container.program(24, data, 0),"data":data})) != null ? stack1 : "") + + " \n
    " + + ((stack1 = helpers.each.call(alias1,(depth0 != null ? depth0.onyomi : depth0),{"name":"each","hash":{},"fn":container.program(26, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + "
    \n
    \n
    " + + ((stack1 = helpers.each.call(alias1,(depth0 != null ? depth0.kunyomi : depth0),{"name":"each","hash":{},"fn":container.program(26, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + "
    \n
    StatsQueryCode
    " + + ((stack1 = container.invokePartial(partials.table,depth0,{"name":"table","hash":{"data":((stack1 = (depth0 != null ? depth0.stats : depth0)) != null ? stack1.misc : stack1)},"data":data,"helpers":helpers,"partials":partials,"decorators":container.decorators})) != null ? stack1 : "") + + "" + + ((stack1 = container.invokePartial(partials.table,depth0,{"name":"table","hash":{"data":((stack1 = (depth0 != null ? depth0.stats : depth0)) != null ? stack1.query : stack1)},"data":data,"helpers":helpers,"partials":partials,"decorators":container.decorators})) != null ? stack1 : "") + + "" + + ((stack1 = container.invokePartial(partials.table,depth0,{"name":"table","hash":{"data":((stack1 = (depth0 != null ? depth0.stats : depth0)) != null ? stack1.code : stack1)},"data":data,"helpers":helpers,"partials":partials,"decorators":container.decorators})) != null ? stack1 : "") + + "
    Dictionary Indices
    " + + ((stack1 = container.invokePartial(partials.table,depth0,{"name":"table","hash":{"data":((stack1 = (depth0 != null ? depth0.stats : depth0)) != null ? stack1.index : stack1)},"data":data,"helpers":helpers,"partials":partials,"decorators":container.decorators})) != null ? stack1 : "") + + "
    \n\n" + + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.debug : depth0),{"name":"if","hash":{},"fn":container.program(28, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + "
    \n"; -},"2":function(container,depth0,helpers,partials,data) { +},"11":function(container,depth0,helpers,partials,data) { return " \n \n"; -},"4":function(container,depth0,helpers,partials,data) { +},"13":function(container,depth0,helpers,partials,data) { return " \n"; -},"6":function(container,depth0,helpers,partials,data) { +},"15":function(container,depth0,helpers,partials,data) { var stack1; return "
    \n" - + ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.frequencies : depth0),{"name":"each","hash":{},"fn":container.program(7, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.frequencies : depth0),{"name":"each","hash":{},"fn":container.program(16, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + "
    \n"; -},"7":function(container,depth0,helpers,partials,data) { +},"16":function(container,depth0,helpers,partials,data) { var helper, alias1=depth0 != null ? depth0 : (container.nullContext || {}), alias2=helpers.helperMissing, alias3="function", alias4=container.escapeExpression; return " " @@ -61,13 +96,13 @@ templates['kanji.html'] = template({"1":function(container,depth0,helpers,partia + ":" + alias4(((helper = (helper = helpers.frequency || (depth0 != null ? depth0.frequency : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"frequency","hash":{},"data":data}) : helper))) + "\n"; -},"9":function(container,depth0,helpers,partials,data) { +},"18":function(container,depth0,helpers,partials,data) { var stack1; return "
    \n" - + ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.tags : depth0),{"name":"each","hash":{},"fn":container.program(10, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.tags : depth0),{"name":"each","hash":{},"fn":container.program(19, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + "
    \n"; -},"10":function(container,depth0,helpers,partials,data) { +},"19":function(container,depth0,helpers,partials,data) { var helper, alias1=depth0 != null ? depth0 : (container.nullContext || {}), alias2=helpers.helperMissing, alias3="function", alias4=container.escapeExpression; return " " + alias4(((helper = (helper = helpers.name || (depth0 != null ? depth0.name : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"name","hash":{},"data":data}) : helper))) + "\n"; -},"12":function(container,depth0,helpers,partials,data) { - return "
    " - + container.escapeExpression(container.lambda(depth0, depth0)) - + "
    \n"; -},"14":function(container,depth0,helpers,partials,data) { +},"21":function(container,depth0,helpers,partials,data) { var stack1; - return "
      \n" - + ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.glossary : depth0),{"name":"each","hash":{},"fn":container.program(15, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") - + "
    \n"; -},"15":function(container,depth0,helpers,partials,data) { - return "
  • " + return "
      " + + ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.glossary : depth0),{"name":"each","hash":{},"fn":container.program(22, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + "
    \n"; +},"22":function(container,depth0,helpers,partials,data) { + return "
  • " + container.escapeExpression(container.lambda(depth0, depth0)) - + "
  • \n"; -},"17":function(container,depth0,helpers,partials,data) { + + ""; +},"24":function(container,depth0,helpers,partials,data) { var stack1; return " " + container.escapeExpression(container.lambda(((stack1 = (depth0 != null ? depth0.glossary : depth0)) != null ? stack1["0"] : stack1), depth0)) + "\n"; -},"19":function(container,depth0,helpers,partials,data) { - var stack1; - - return " \n" - + ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),((stack1 = (depth0 != null ? depth0.stats : depth0)) != null ? stack1.index : stack1),{"name":"each","hash":{},"fn":container.program(20, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") - + "
    \n"; -},"20":function(container,depth0,helpers,partials,data) { - var stack1, helper, alias1=depth0 != null ? depth0 : (container.nullContext || {}); - - return " \n " - + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.notes : depth0),{"name":"if","hash":{},"fn":container.program(21, data, 0),"inverse":container.program(23, data, 0),"data":data})) != null ? stack1 : "") - + "\n " - + container.escapeExpression(((helper = (helper = helpers.value || (depth0 != null ? depth0.value : depth0)) != null ? helper : helpers.helperMissing),(typeof helper === "function" ? helper.call(alias1,{"name":"value","hash":{},"data":data}) : helper))) - + "\n \n"; -},"21":function(container,depth0,helpers,partials,data) { - var helper; - - return container.escapeExpression(((helper = (helper = helpers.notes || (depth0 != null ? depth0.notes : depth0)) != null ? helper : helpers.helperMissing),(typeof helper === "function" ? helper.call(depth0 != null ? depth0 : (container.nullContext || {}),{"name":"notes","hash":{},"data":data}) : helper))); -},"23":function(container,depth0,helpers,partials,data) { - var helper; - - return container.escapeExpression(((helper = (helper = helpers.name || (depth0 != null ? depth0.name : depth0)) != null ? helper : helpers.helperMissing),(typeof helper === "function" ? helper.call(depth0 != null ? depth0 : (container.nullContext || {}),{"name":"name","hash":{},"data":data}) : helper))); -},"25":function(container,depth0,helpers,partials,data) { - return " No index data found\n"; -},"27":function(container,depth0,helpers,partials,data) { +},"26":function(container,depth0,helpers,partials,data) { + return "
    " + + container.escapeExpression(container.lambda(depth0, depth0)) + + "
    "; +},"28":function(container,depth0,helpers,partials,data) { var stack1, helper, options, buffer = "
    ";
    -  stack1 = ((helper = (helper = helpers.dumpObject || (depth0 != null ? depth0.dumpObject : depth0)) != null ? helper : helpers.helperMissing),(options={"name":"dumpObject","hash":{},"fn":container.program(28, data, 0),"inverse":container.noop,"data":data}),(typeof helper === "function" ? helper.call(depth0 != null ? depth0 : (container.nullContext || {}),options) : helper));
    +  stack1 = ((helper = (helper = helpers.dumpObject || (depth0 != null ? depth0.dumpObject : depth0)) != null ? helper : helpers.helperMissing),(options={"name":"dumpObject","hash":{},"fn":container.program(29, data, 0),"inverse":container.noop,"data":data}),(typeof helper === "function" ? helper.call(depth0 != null ? depth0 : (container.nullContext || {}),options) : helper));
       if (!helpers.dumpObject) { stack1 = helpers.blockHelperMissing.call(depth0,stack1,options)}
       if (stack1 != null) { buffer += stack1; }
       return buffer + "
    \n"; -},"28":function(container,depth0,helpers,partials,data) { +},"29":function(container,depth0,helpers,partials,data) { var stack1; return ((stack1 = container.lambda(depth0, depth0)) != null ? stack1 : ""); -},"30":function(container,depth0,helpers,partials,data,blockParams,depths) { +},"31":function(container,depth0,helpers,partials,data,blockParams,depths) { var stack1; - return ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.definitions : depth0),{"name":"each","hash":{},"fn":container.program(31, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : ""); -},"31":function(container,depth0,helpers,partials,data,blockParams,depths) { + return ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.definitions : depth0),{"name":"each","hash":{},"fn":container.program(32, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : ""); +},"32":function(container,depth0,helpers,partials,data,blockParams,depths) { var stack1; - return ((stack1 = helpers.unless.call(depth0 != null ? depth0 : (container.nullContext || {}),(data && data.first),{"name":"unless","hash":{},"fn":container.program(32, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "") + return ((stack1 = helpers.unless.call(depth0 != null ? depth0 : (container.nullContext || {}),(data && data.first),{"name":"unless","hash":{},"fn":container.program(33, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "") + "\n" + ((stack1 = container.invokePartial(partials.kanji,depth0,{"name":"kanji","hash":{"root":(depths[1] != null ? depths[1].root : depths[1]),"source":(depths[1] != null ? depths[1].source : depths[1]),"addable":(depths[1] != null ? depths[1].addable : depths[1]),"debug":(depths[1] != null ? depths[1].debug : depths[1])},"data":data,"helpers":helpers,"partials":partials,"decorators":container.decorators})) != null ? stack1 : ""); -},"32":function(container,depth0,helpers,partials,data) { +},"33":function(container,depth0,helpers,partials,data) { return "
    "; -},"34":function(container,depth0,helpers,partials,data) { +},"35":function(container,depth0,helpers,partials,data) { return "

    No results found

    \n"; },"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data,blockParams,depths) { var stack1; - return "\n" - + ((stack1 = helpers["if"].call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.definitions : depth0),{"name":"if","hash":{},"fn":container.program(30, data, 0, blockParams, depths),"inverse":container.program(34, data, 0, blockParams, depths),"data":data})) != null ? stack1 : ""); + return "\n\n" + + ((stack1 = helpers["if"].call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.definitions : depth0),{"name":"if","hash":{},"fn":container.program(31, data, 0, blockParams, depths),"inverse":container.program(35, data, 0, blockParams, depths),"data":data})) != null ? stack1 : ""); },"main_d": function(fn, props, container, depth0, data, blockParams, depths) { var decorators = container.decorators; - fn = decorators.inline(fn,props,container,{"name":"inline","hash":{},"fn":container.program(1, data, 0, blockParams, depths),"inverse":container.noop,"args":["kanji"],"data":data}) || fn; + fn = decorators.inline(fn,props,container,{"name":"inline","hash":{},"fn":container.program(1, data, 0, blockParams, depths),"inverse":container.noop,"args":["table"],"data":data}) || fn; + fn = decorators.inline(fn,props,container,{"name":"inline","hash":{},"fn":container.program(10, data, 0, blockParams, depths),"inverse":container.noop,"args":["kanji"],"data":data}) || fn; return fn; } diff --git a/tmpl/kanji.html b/tmpl/kanji.html index c46ce6a7..7c801355 100644 --- a/tmpl/kanji.html +++ b/tmpl/kanji.html @@ -1,3 +1,18 @@ +{{#*inline "table"}} +{{#if data}} + + {{#each data}} + + + + + {{/each}} +
    {{#if notes}}{{notes}}{{else}}{{name}}{{/if}}{{value}}
    +{{else}} +No data found +{{/if}} +{{/inline}} + {{#*inline "kanji"}}
    @@ -31,52 +46,40 @@ - - + + - - + + + + + + + + + + + + - +
    Readings GlossaryStatisticsOn'YomiKun'Yomi
    -
    - {{#each kunyomi}} -
    {{.}}
    - {{/each}} - {{#each onyomi}} -
    {{.}}
    - {{/each}} -
    -
    {{#if glossary.[1]}} -
      - {{#each glossary}} -
    1. {{.}}
    2. - {{/each}} -
    +
      {{#each glossary}}
    1. {{.}}
    2. {{/each}}
    {{else}} {{glossary.[0]}} {{/if}}
    +
    {{#each onyomi}}
    {{.}}
    {{/each}}
    +
    +
    {{#each kunyomi}}
    {{.}}
    {{/each}}
    +
    StatsQueryCode
    {{> table data=stats.misc}}{{> table data=stats.query}}{{> table data=stats.code}}
    Dictionary Indices
    - {{#if stats.index}} - - {{#each stats.index}} - - - - - {{/each}} -
    {{#if notes}}{{notes}}{{else}}{{name}}{{/if}}{{value}}
    - {{else}} - No index data found - {{/if}} -
    {{> table data=stats.index}}
    -- cgit v1.2.3 From f22a6990122007f2db0292c7e26aba0d5328de9d Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Thu, 21 Sep 2017 20:59:43 -0700 Subject: wip --- ext/bg/js/templates.js | 10 +++++----- tmpl/kanji.html | 11 +++++------ 2 files changed, 10 insertions(+), 11 deletions(-) (limited to 'ext/bg') diff --git a/ext/bg/js/templates.js b/ext/bg/js/templates.js index 4320acb7..dc5df96a 100644 --- a/ext/bg/js/templates.js +++ b/ext/bg/js/templates.js @@ -61,17 +61,17 @@ templates['kanji.html'] = template({"1":function(container,depth0,helpers,partia + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.frequencies : depth0),{"name":"if","hash":{},"fn":container.program(15, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + "\n" + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.tags : depth0),{"name":"if","hash":{},"fn":container.program(18, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") - + "\n \n \n \n \n \n \n \n
    GlossaryOn'YomiKun'Yomi
    \n" + + "\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
    GlossaryReadingsStats
    \n" + ((stack1 = helpers["if"].call(alias1,((stack1 = (depth0 != null ? depth0.glossary : depth0)) != null ? stack1["1"] : stack1),{"name":"if","hash":{},"fn":container.program(21, data, 0),"inverse":container.program(24, data, 0),"data":data})) != null ? stack1 : "") + " \n
    " + ((stack1 = helpers.each.call(alias1,(depth0 != null ? depth0.onyomi : depth0),{"name":"each","hash":{},"fn":container.program(26, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") - + "
    \n
    \n
    " + + "
    \n
    " + ((stack1 = helpers.each.call(alias1,(depth0 != null ? depth0.kunyomi : depth0),{"name":"each","hash":{},"fn":container.program(26, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") - + "
    \n
    StatsQueryCode
    " + + "\n " + ((stack1 = container.invokePartial(partials.table,depth0,{"name":"table","hash":{"data":((stack1 = (depth0 != null ? depth0.stats : depth0)) != null ? stack1.misc : stack1)},"data":data,"helpers":helpers,"partials":partials,"decorators":container.decorators})) != null ? stack1 : "") - + "" + + "
    QueryCode
    " + ((stack1 = container.invokePartial(partials.table,depth0,{"name":"table","hash":{"data":((stack1 = (depth0 != null ? depth0.stats : depth0)) != null ? stack1.query : stack1)},"data":data,"helpers":helpers,"partials":partials,"decorators":container.decorators})) != null ? stack1 : "") - + "" + + "" + ((stack1 = container.invokePartial(partials.table,depth0,{"name":"table","hash":{"data":((stack1 = (depth0 != null ? depth0.stats : depth0)) != null ? stack1.code : stack1)},"data":data,"helpers":helpers,"partials":partials,"decorators":container.decorators})) != null ? stack1 : "") + "
    Dictionary Indices
    " + ((stack1 = container.invokePartial(partials.table,depth0,{"name":"table","hash":{"data":((stack1 = (depth0 != null ? depth0.stats : depth0)) != null ? stack1.index : stack1)},"data":data,"helpers":helpers,"partials":partials,"decorators":container.decorators})) != null ? stack1 : "") diff --git a/tmpl/kanji.html b/tmpl/kanji.html index 7c801355..405e0d0e 100644 --- a/tmpl/kanji.html +++ b/tmpl/kanji.html @@ -47,8 +47,8 @@ No data found - - + + - + - + - + -- cgit v1.2.3 From fe859a96cdcd6964898bfd492be034c95fd90285 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Thu, 21 Sep 2017 23:10:43 -0700 Subject: kanji layout --- ext/bg/js/templates.js | 50 +++++++++++++++++++++++++++++++------------------- tmpl/kanji.html | 20 +++++++++++--------- 2 files changed, 42 insertions(+), 28 deletions(-) (limited to 'ext/bg') diff --git a/ext/bg/js/templates.js b/ext/bg/js/templates.js index dc5df96a..c9f987e1 100644 --- a/ext/bg/js/templates.js +++ b/ext/bg/js/templates.js @@ -61,22 +61,22 @@ templates['kanji.html'] = template({"1":function(container,depth0,helpers,partia + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.frequencies : depth0),{"name":"if","hash":{},"fn":container.program(15, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + "\n" + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.tags : depth0),{"name":"if","hash":{},"fn":container.program(18, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") - + "\n
    GlossaryOn'YomiKun'YomiReadingsStats
    @@ -60,19 +60,18 @@ No data found
    {{#each onyomi}}
    {{.}}
    {{/each}}
    -
    {{#each kunyomi}}
    {{.}}
    {{/each}}
    {{> table data=stats.misc}}
    Stats Query Code
    {{> table data=stats.misc}} {{> table data=stats.query}} {{> table data=stats.code}}
    \n \n \n \n \n \n \n - + - - - + - - - + + + + + + + -- cgit v1.2.3 From 3d876159178d39736cc8e5f1711b9c0828b43882 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Thu, 21 Sep 2017 23:20:51 -0700 Subject: sort stats --- ext/bg/js/translator.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'ext/bg') diff --git a/ext/bg/js/translator.js b/ext/bg/js/translator.js index cc0336e7..ede89fc6 100644 --- a/ext/bg/js/translator.js +++ b/ext/bg/js/translator.js @@ -190,6 +190,18 @@ class Translator { group.push(dictTagSanitize(stat)); } + for (const category in stats) { + stats[category].sort((a, b) => { + if (a.notes < b.notes) { + return -1; + } else if (a.notes > b.notes) { + return 1; + } else { + return 0; + } + }); + } + return stats; } } -- cgit v1.2.3 From 27296de9f5c8283e81620999d8acedcdf9c117a5 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Thu, 21 Sep 2017 23:22:49 -0700 Subject: wip --- ext/bg/js/templates.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ext/bg') diff --git a/ext/bg/js/templates.js b/ext/bg/js/templates.js index c9f987e1..b5d352fc 100644 --- a/ext/bg/js/templates.js +++ b/ext/bg/js/templates.js @@ -70,7 +70,7 @@ templates['kanji.html'] = template({"1":function(container,depth0,helpers,partia + "\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
    GlossaryReadingsStats
    \n" + + "\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
    GlossaryReadingsStatistics
    \n" + ((stack1 = helpers["if"].call(alias1,((stack1 = (depth0 != null ? depth0.glossary : depth0)) != null ? stack1["1"] : stack1),{"name":"if","hash":{},"fn":container.program(21, data, 0),"inverse":container.program(24, data, 0),"data":data})) != null ? stack1 : "") - + " \n
    " - + ((stack1 = helpers.each.call(alias1,(depth0 != null ? depth0.onyomi : depth0),{"name":"each","hash":{},"fn":container.program(26, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") - + "
    \n
    " - + ((stack1 = helpers.each.call(alias1,(depth0 != null ? depth0.kunyomi : depth0),{"name":"each","hash":{},"fn":container.program(26, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") - + "
    \n
    " + + " \n " + + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.onyomi : depth0),{"name":"if","hash":{},"fn":container.program(26, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + "\n " + + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.kunyomi : depth0),{"name":"if","hash":{},"fn":container.program(29, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + "\n " + ((stack1 = container.invokePartial(partials.table,depth0,{"name":"table","hash":{"data":((stack1 = (depth0 != null ? depth0.stats : depth0)) != null ? stack1.misc : stack1)},"data":data,"helpers":helpers,"partials":partials,"decorators":container.decorators})) != null ? stack1 : "") - + "
    QueryCode
    " + + "
    Classifications
    " + ((stack1 = container.invokePartial(partials.table,depth0,{"name":"table","hash":{"data":((stack1 = (depth0 != null ? depth0.stats : depth0)) != null ? stack1.query : stack1)},"data":data,"helpers":helpers,"partials":partials,"decorators":container.decorators})) != null ? stack1 : "") - + "" + + "
    Codepoints
    " + ((stack1 = container.invokePartial(partials.table,depth0,{"name":"table","hash":{"data":((stack1 = (depth0 != null ? depth0.stats : depth0)) != null ? stack1.code : stack1)},"data":data,"helpers":helpers,"partials":partials,"decorators":container.decorators})) != null ? stack1 : "") + "
    Dictionary Indices
    " + ((stack1 = container.invokePartial(partials.table,depth0,{"name":"table","hash":{"data":((stack1 = (depth0 != null ? depth0.stats : depth0)) != null ? stack1.index : stack1)},"data":data,"helpers":helpers,"partials":partials,"decorators":container.decorators})) != null ? stack1 : "") + "
    \n\n" - + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.debug : depth0),{"name":"if","hash":{},"fn":container.program(28, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.debug : depth0),{"name":"if","hash":{},"fn":container.program(31, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + "\n"; },"11":function(container,depth0,helpers,partials,data) { return " \n \n"; @@ -129,39 +129,51 @@ templates['kanji.html'] = template({"1":function(container,depth0,helpers,partia + container.escapeExpression(container.lambda(((stack1 = (depth0 != null ? depth0.glossary : depth0)) != null ? stack1["0"] : stack1), depth0)) + "\n"; },"26":function(container,depth0,helpers,partials,data) { + var stack1; + + return "
    " + + ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.onyomi : depth0),{"name":"each","hash":{},"fn":container.program(27, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + "
    "; +},"27":function(container,depth0,helpers,partials,data) { return "
    " + container.escapeExpression(container.lambda(depth0, depth0)) + "
    "; -},"28":function(container,depth0,helpers,partials,data) { +},"29":function(container,depth0,helpers,partials,data) { + var stack1; + + return "
    " + + ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.kunyomi : depth0),{"name":"each","hash":{},"fn":container.program(27, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + "
    "; +},"31":function(container,depth0,helpers,partials,data) { var stack1, helper, options, buffer = "
    ";
    -  stack1 = ((helper = (helper = helpers.dumpObject || (depth0 != null ? depth0.dumpObject : depth0)) != null ? helper : helpers.helperMissing),(options={"name":"dumpObject","hash":{},"fn":container.program(29, data, 0),"inverse":container.noop,"data":data}),(typeof helper === "function" ? helper.call(depth0 != null ? depth0 : (container.nullContext || {}),options) : helper));
    +  stack1 = ((helper = (helper = helpers.dumpObject || (depth0 != null ? depth0.dumpObject : depth0)) != null ? helper : helpers.helperMissing),(options={"name":"dumpObject","hash":{},"fn":container.program(32, data, 0),"inverse":container.noop,"data":data}),(typeof helper === "function" ? helper.call(depth0 != null ? depth0 : (container.nullContext || {}),options) : helper));
       if (!helpers.dumpObject) { stack1 = helpers.blockHelperMissing.call(depth0,stack1,options)}
       if (stack1 != null) { buffer += stack1; }
       return buffer + "
    \n"; -},"29":function(container,depth0,helpers,partials,data) { +},"32":function(container,depth0,helpers,partials,data) { var stack1; return ((stack1 = container.lambda(depth0, depth0)) != null ? stack1 : ""); -},"31":function(container,depth0,helpers,partials,data,blockParams,depths) { +},"34":function(container,depth0,helpers,partials,data,blockParams,depths) { var stack1; - return ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.definitions : depth0),{"name":"each","hash":{},"fn":container.program(32, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : ""); -},"32":function(container,depth0,helpers,partials,data,blockParams,depths) { + return ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.definitions : depth0),{"name":"each","hash":{},"fn":container.program(35, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : ""); +},"35":function(container,depth0,helpers,partials,data,blockParams,depths) { var stack1; - return ((stack1 = helpers.unless.call(depth0 != null ? depth0 : (container.nullContext || {}),(data && data.first),{"name":"unless","hash":{},"fn":container.program(33, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "") + return ((stack1 = helpers.unless.call(depth0 != null ? depth0 : (container.nullContext || {}),(data && data.first),{"name":"unless","hash":{},"fn":container.program(36, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "") + "\n" + ((stack1 = container.invokePartial(partials.kanji,depth0,{"name":"kanji","hash":{"root":(depths[1] != null ? depths[1].root : depths[1]),"source":(depths[1] != null ? depths[1].source : depths[1]),"addable":(depths[1] != null ? depths[1].addable : depths[1]),"debug":(depths[1] != null ? depths[1].debug : depths[1])},"data":data,"helpers":helpers,"partials":partials,"decorators":container.decorators})) != null ? stack1 : ""); -},"33":function(container,depth0,helpers,partials,data) { +},"36":function(container,depth0,helpers,partials,data) { return "
    "; -},"35":function(container,depth0,helpers,partials,data) { +},"38":function(container,depth0,helpers,partials,data) { return "

    No results found

    \n"; },"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data,blockParams,depths) { var stack1; return "\n\n" - + ((stack1 = helpers["if"].call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.definitions : depth0),{"name":"if","hash":{},"fn":container.program(31, data, 0, blockParams, depths),"inverse":container.program(35, data, 0, blockParams, depths),"data":data})) != null ? stack1 : ""); + + ((stack1 = helpers["if"].call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.definitions : depth0),{"name":"if","hash":{},"fn":container.program(34, data, 0, blockParams, depths),"inverse":container.program(38, data, 0, blockParams, depths),"data":data})) != null ? stack1 : ""); },"main_d": function(fn, props, container, depth0, data, blockParams, depths) { var decorators = container.decorators; diff --git a/tmpl/kanji.html b/tmpl/kanji.html index 405e0d0e..e3d0f275 100644 --- a/tmpl/kanji.html +++ b/tmpl/kanji.html @@ -48,7 +48,7 @@ No data found
    Glossary ReadingsStatsStatistics
    @@ -59,20 +59,22 @@ No data found {{/if}} -
    {{#each onyomi}}
    {{.}}
    {{/each}}
    -
    {{#each kunyomi}}
    {{.}}
    {{/each}}
    + {{#if onyomi}}
    {{#each onyomi}}
    {{.}}
    {{/each}}
    {{/if}} + {{#if kunyomi}}
    {{#each kunyomi}}
    {{.}}
    {{/each}}
    {{/if}}
    {{> table data=stats.misc}}
    QueryCodeClassifications
    {{> table data=stats.query}}{{> table data=stats.code}}{{> table data=stats.query}}
    Codepoints
    {{> table data=stats.code}}
    Dictionary Indices" + ((stack1 = container.invokePartial(partials.table,depth0,{"name":"table","hash":{"data":((stack1 = (depth0 != null ? depth0.stats : depth0)) != null ? stack1.misc : stack1)},"data":data,"helpers":helpers,"partials":partials,"decorators":container.decorators})) != null ? stack1 : "") + "
    Classifications
    " - + ((stack1 = container.invokePartial(partials.table,depth0,{"name":"table","hash":{"data":((stack1 = (depth0 != null ? depth0.stats : depth0)) != null ? stack1.query : stack1)},"data":data,"helpers":helpers,"partials":partials,"decorators":container.decorators})) != null ? stack1 : "") + + ((stack1 = container.invokePartial(partials.table,depth0,{"name":"table","hash":{"data":((stack1 = (depth0 != null ? depth0.stats : depth0)) != null ? stack1["class"] : stack1)},"data":data,"helpers":helpers,"partials":partials,"decorators":container.decorators})) != null ? stack1 : "") + "
    Codepoints
    " + ((stack1 = container.invokePartial(partials.table,depth0,{"name":"table","hash":{"data":((stack1 = (depth0 != null ? depth0.stats : depth0)) != null ? stack1.code : stack1)},"data":data,"helpers":helpers,"partials":partials,"decorators":container.decorators})) != null ? stack1 : "") + "
    Dictionary Indices
    " -- cgit v1.2.3 From 8ba8397170c99e1d4416277e26d91ebb4b8cfed1 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Fri, 22 Sep 2017 19:39:05 -0700 Subject: update error handling --- ext/bg/js/anki.js | 2 +- ext/bg/js/audio.js | 4 ++-- ext/bg/js/database.js | 26 +++++++++++++------------- ext/bg/js/request.js | 4 ++-- ext/bg/js/settings.js | 8 ++++---- ext/bg/settings.html | 23 ++++++----------------- ext/mixed/js/display.js | 6 +++--- 7 files changed, 31 insertions(+), 42 deletions(-) (limited to 'ext/bg') diff --git a/ext/bg/js/anki.js b/ext/bg/js/anki.js index c327969f..183f37bc 100644 --- a/ext/bg/js/anki.js +++ b/ext/bg/js/anki.js @@ -62,7 +62,7 @@ class AnkiConnect { if (this.remoteVersion < this.localVersion) { this.remoteVersion = await this.ankiInvoke('version'); if (this.remoteVersion < this.localVersion) { - throw 'extension and plugin versions incompatible'; + throw 'Extension and plugin versions incompatible'; } } } diff --git a/ext/bg/js/audio.js b/ext/bg/js/audio.js index 0952887e..ce47490c 100644 --- a/ext/bg/js/audio.js +++ b/ext/bg/js/audio.js @@ -57,7 +57,7 @@ async function audioBuildUrl(definition, mode, cache={}) { const xhr = new XMLHttpRequest(); xhr.open('POST', 'https://www.japanesepod101.com/learningcenter/reference/dictionary_post'); xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); - xhr.addEventListener('error', () => reject('failed to scrape audio data')); + xhr.addEventListener('error', () => reject('Failed to scrape audio data')); xhr.addEventListener('load', () => { cache[definition.expression] = xhr.responseText; resolve(xhr.responseText); @@ -87,7 +87,7 @@ async function audioBuildUrl(definition, mode, cache={}) { } else { const xhr = new XMLHttpRequest(); xhr.open('GET', `http://jisho.org/search/${definition.expression}`); - xhr.addEventListener('error', () => reject('failed to scrape audio data')); + xhr.addEventListener('error', () => reject('Failed to scrape audio data')); xhr.addEventListener('load', () => { cache[definition.expression] = xhr.responseText; resolve(xhr.responseText); diff --git a/ext/bg/js/database.js b/ext/bg/js/database.js index f94c572e..e7316b3a 100644 --- a/ext/bg/js/database.js +++ b/ext/bg/js/database.js @@ -25,7 +25,7 @@ class Database { async prepare() { if (this.db) { - throw 'database already initialized'; + throw 'Database already initialized'; } this.db = new Dexie('dict'); @@ -46,7 +46,7 @@ class Database { async purge() { if (!this.db) { - throw 'database not initialized'; + throw 'Database not initialized'; } this.db.close(); @@ -59,7 +59,7 @@ class Database { async findTerms(term, titles) { if (!this.db) { - throw 'database not initialized'; + throw 'Database not initialized'; } const results = []; @@ -83,7 +83,7 @@ class Database { async findTermFreq(term, titles) { if (!this.db) { - throw 'database not initialized'; + throw 'Database not initialized'; } const results = []; @@ -98,7 +98,7 @@ class Database { async findKanji(kanji, titles) { if (!this.db) { - return Promise.reject('database not initialized'); + throw 'Database not initialized'; } const results = []; @@ -121,7 +121,7 @@ class Database { async findKanjiFreq(kanji, titles) { if (!this.db) { - throw 'database not initialized'; + throw 'Database not initialized'; } const results = []; @@ -136,7 +136,7 @@ class Database { async findTagForTitle(name, title) { if (!this.db) { - throw 'database not initialized'; + throw 'Database not initialized'; } this.tagCache[title] = this.tagCache[title] || {}; @@ -159,23 +159,23 @@ class Database { if (this.db) { return this.db.dictionaries.toArray(); } else { - throw 'database not initialized'; + throw 'Database not initialized'; } } async importDictionary(archive, callback) { if (!this.db) { - return Promise.reject('database not initialized'); + throw 'Database not initialized'; } const indexDataLoaded = async summary => { if (summary.version > 2) { - throw 'unsupported dictionary version'; + throw 'Unsupported dictionary version'; } const count = await this.db.dictionaries.where('title').equals(summary.title).count(); if (count > 0) { - throw `dictionary "${summary.title}" is already imported`; + throw 'Dictionary is already imported'; } await this.db.dictionaries.add(summary); @@ -329,12 +329,12 @@ class Database { const indexFile = zip.files['index.json']; if (!indexFile) { - throw 'no dictionary index found in archive'; + throw 'No dictionary index found in archive'; } const index = JSON.parse(await indexFile.async('string')); if (!index.title || !index.revision) { - throw 'unrecognized dictionary format'; + throw 'Unrecognized dictionary format'; } const summary = { diff --git a/ext/bg/js/request.js b/ext/bg/js/request.js index 94fd135a..e4359863 100644 --- a/ext/bg/js/request.js +++ b/ext/bg/js/request.js @@ -22,7 +22,7 @@ function requestJson(url, action, params) { const xhr = new XMLHttpRequest(); xhr.overrideMimeType('application/json'); xhr.addEventListener('load', () => resolve(xhr.responseText)); - xhr.addEventListener('error', () => reject('failed to execute network request')); + xhr.addEventListener('error', () => reject('Failed to connect')); xhr.open(action, url); if (params) { xhr.send(JSON.stringify(params)); @@ -34,7 +34,7 @@ function requestJson(url, action, params) { return JSON.parse(responseText); } catch (e) { - return Promise.reject('invalid JSON response'); + return Promise.reject('Invalid response'); } }); } diff --git a/ext/bg/js/settings.js b/ext/bg/js/settings.js index d73d7509..161e9abe 100644 --- a/ext/bg/js/settings.js +++ b/ext/bg/js/settings.js @@ -142,7 +142,7 @@ async function onReady() { $('#scan-length').val(options.scanning.length); $('#scan-modifier-key').val(options.scanning.modifier); - $('#dict-purge').click(utilAsync(onDictionaryPurge)); + $('#dict-purge-link').click(utilAsync(onDictionaryPurge)); $('#dict-file').change(utilAsync(onDictionaryImport)); $('#anki-enable').prop('checked', options.anki.enable); @@ -179,7 +179,7 @@ $(document).ready(utilAsync(onReady)); function dictionaryErrorShow(error) { const dialog = $('#dict-error'); if (error) { - dialog.show().find('span').text(error); + dialog.show().text(error); } else { dialog.hide(); } @@ -245,7 +245,7 @@ async function onDictionaryPurge(e) { e.preventDefault(); const dictControls = $('#dict-importer, #dict-groups').hide(); - const dictProgress = $('#dict-purge-progress').show(); + const dictProgress = $('#dict-purge').show(); try { dictionaryErrorShow(); @@ -314,7 +314,7 @@ function ankiSpinnerShow(show) { function ankiErrorShow(error) { const dialog = $('#anki-error'); if (error) { - dialog.show().find('span').text(error); + dialog.show().text(error); } else { dialog.hide(); diff --git a/ext/bg/settings.html b/ext/bg/settings.html index c2612967..4315d74b 100644 --- a/ext/bg/settings.html +++ b/ext/bg/settings.html @@ -7,7 +7,7 @@