aboutsummaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2021-01-16 15:29:42 -0500
committerGitHub <noreply@github.com>2021-01-16 15:29:42 -0500
commitb2342945403c27e346446bbe316f075ed2b13eff (patch)
tree690a065de66ece5e0b395dbc2811d3d9fdbe13f9 /ext
parent0ac35771192adb87d76809aff171d60a5d0018c3 (diff)
Stroke count marker (#1251)
* Add stroke-count definition * Update options * Update documentation * Add helper
Diffstat (limited to 'ext')
-rw-r--r--ext/bg/data/anki-field-templates-upgrade-v8.handlebars14
-rw-r--r--ext/bg/data/default-anki-field-templates.handlebars15
-rw-r--r--ext/bg/js/options.js6
-rw-r--r--ext/bg/js/settings/anki-controller.js1
-rw-r--r--ext/bg/js/template-renderer.js9
-rw-r--r--ext/bg/settings2.html4
6 files changed, 46 insertions, 3 deletions
diff --git a/ext/bg/data/anki-field-templates-upgrade-v8.handlebars b/ext/bg/data/anki-field-templates-upgrade-v8.handlebars
new file mode 100644
index 00000000..a5056364
--- /dev/null
+++ b/ext/bg/data/anki-field-templates-upgrade-v8.handlebars
@@ -0,0 +1,14 @@
+{{#*inline "stroke-count"}}
+ {{~#scope~}}
+ {{~#set "found" false}}{{/set~}}
+ {{~#each definition.stats.misc~}}
+ {{~#if (op "===" name "strokes")~}}
+ {{~#set "found" true}}{{/set~}}
+ Stroke count: {{value}}
+ {{~/if~}}
+ {{~/each~}}
+ {{~#if (op "!" (get "found"))~}}
+ Stroke count: Unknown
+ {{~/if~}}
+ {{~/scope~}}
+{{/inline}}
diff --git a/ext/bg/data/default-anki-field-templates.handlebars b/ext/bg/data/default-anki-field-templates.handlebars
index 1024e2e6..a0aff5d2 100644
--- a/ext/bg/data/default-anki-field-templates.handlebars
+++ b/ext/bg/data/default-anki-field-templates.handlebars
@@ -323,4 +323,19 @@
{{~/if~}}
{{/inline}}
+{{#*inline "stroke-count"}}
+ {{~#scope~}}
+ {{~#set "found" false}}{{/set~}}
+ {{~#each definition.stats.misc~}}
+ {{~#if (op "===" name "strokes")~}}
+ {{~#set "found" true}}{{/set~}}
+ Stroke count: {{value}}
+ {{~/if~}}
+ {{~/each~}}
+ {{~#if (op "!" (get "found"))~}}
+ Stroke count: Unknown
+ {{~/if~}}
+ {{~/scope~}}
+{{/inline}}
+
{{~> (lookup . "marker") ~}}
diff --git a/ext/bg/js/options.js b/ext/bg/js/options.js
index 026d75c5..a8cdd885 100644
--- a/ext/bg/js/options.js
+++ b/ext/bg/js/options.js
@@ -487,7 +487,7 @@ class OptionsUtil {
update: this._updateVersion7.bind(this)
},
{
- async: false,
+ async: true,
update: this._updateVersion8.bind(this)
}
];
@@ -680,7 +680,7 @@ class OptionsUtil {
return options;
}
- _updateVersion8(options) {
+ async _updateVersion8(options) {
// Version 8 changes:
// Added translation.textReplacements.
// Moved anki.sentenceExt to sentenceParsing.scanExtent.
@@ -690,6 +690,8 @@ class OptionsUtil {
// Added inputs.hotkeys.
// Added anki.suspendNewCards.
// Added popupWindow.
+ // Updated handlebars templates to include "stroke-count" definition.
+ await this._addFieldTemplatesToOptions(options, '/bg/data/anki-field-templates-upgrade-v8.handlebars');
for (const profile of options.profiles) {
profile.options.translation.textReplacements = {
searchOriginal: true,
diff --git a/ext/bg/js/settings/anki-controller.js b/ext/bg/js/settings/anki-controller.js
index fbd058ee..49bdea60 100644
--- a/ext/bg/js/settings/anki-controller.js
+++ b/ext/bg/js/settings/anki-controller.js
@@ -118,6 +118,7 @@ class AnkiController {
'onyomi',
'screenshot',
'sentence',
+ 'stroke-count',
'tags',
'url'
];
diff --git a/ext/bg/js/template-renderer.js b/ext/bg/js/template-renderer.js
index 4bf9448e..ae39e478 100644
--- a/ext/bg/js/template-renderer.js
+++ b/ext/bg/js/template-renderer.js
@@ -107,7 +107,8 @@ class TemplateRenderer {
['property', this._property.bind(this)],
['noop', this._noop.bind(this)],
['isMoraPitchHigh', this._isMoraPitchHigh.bind(this)],
- ['getKanaMorae', this._getKanaMorae.bind(this)]
+ ['getKanaMorae', this._getKanaMorae.bind(this)],
+ ['typeof', this._getTypeof.bind(this)]
];
for (const [name, helper] of helpers) {
@@ -406,4 +407,10 @@ class TemplateRenderer {
_getKanaMorae(context, text) {
return this._japaneseUtil.getKanaMorae(`${text}`);
}
+
+ _getTypeof(context, ...args) {
+ const ii = args.length - 1;
+ const value = (ii > 0 ? args[0] : args[ii].fn(context));
+ return typeof value;
+ }
}
diff --git a/ext/bg/settings2.html b/ext/bg/settings2.html
index 33edca69..d7d77399 100644
--- a/ext/bg/settings2.html
+++ b/ext/bg/settings2.html
@@ -2602,6 +2602,10 @@
<td><code class="anki-field-marker">{onyomi}</code></td>
<td>Onyomi (Chinese reading) for the kanji, expressed as hiragana.</td>
</tr>
+ <tr>
+ <td><code class="anki-field-marker">{stroke-count}</code></td>
+ <td>Number of strokes that the kanji character has.</td>
+ </tr>
</tbody>
<thead>
<tr>