aboutsummaryrefslogtreecommitdiff
path: root/ext/js/templates
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2021-04-28 21:57:49 -0400
committerGitHub <noreply@github.com>2021-04-28 21:57:49 -0400
commit40b29cb0d3ff90094c44dd4cb7abd087a0fd9598 (patch)
tree0723d8cf5c61ffe091a150b9c9a1d2281f7d72a0 /ext/js/templates
parent512391346bd4f67b1933b768c64d4dac1b58b44d (diff)
Add pitch categories template helper (#1636)
* Move utility function * Expose dictionary entry as a hidden property for internal use * Add pitchCategories helper
Diffstat (limited to 'ext/js/templates')
-rw-r--r--ext/js/templates/template-renderer.js20
1 files changed, 19 insertions, 1 deletions
diff --git a/ext/js/templates/template-renderer.js b/ext/js/templates/template-renderer.js
index 9bb7a414..07b2849c 100644
--- a/ext/js/templates/template-renderer.js
+++ b/ext/js/templates/template-renderer.js
@@ -16,6 +16,7 @@
*/
/* global
+ * DictionaryDataUtil
* Handlebars
*/
@@ -146,7 +147,8 @@ class TemplateRenderer {
['getKanaMorae', this._getKanaMorae.bind(this)],
['typeof', this._getTypeof.bind(this)],
['join', this._join.bind(this)],
- ['concat', this._concat.bind(this)]
+ ['concat', this._concat.bind(this)],
+ ['pitchCategories', this._pitchCategories.bind(this)]
];
for (const [name, helper] of helpers) {
@@ -466,4 +468,20 @@ class TemplateRenderer {
}
return result;
}
+
+ _pitchCategories(context, data) {
+ const {pronunciations, headwords} = data.dictionaryEntry;
+ const categories = new Set();
+ for (const {headwordIndex, pitches} of pronunciations) {
+ const {reading, wordClasses} = headwords[headwordIndex];
+ const isVerbOrAdjective = DictionaryDataUtil.isNonNounVerbOrAdjective(wordClasses);
+ for (const {position} of pitches) {
+ const category = this._japaneseUtil.getPitchCategory(reading, position, isVerbOrAdjective);
+ if (category !== null) {
+ categories.add(category);
+ }
+ }
+ }
+ return [...categories];
+ }
}