aboutsummaryrefslogtreecommitdiff
path: root/ext/bg/js/settings
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-09-10 18:03:46 -0400
committerGitHub <noreply@github.com>2020-09-10 18:03:46 -0400
commita531618c48481a30d63112cf59b7806291f0bda4 (patch)
tree04b185c11406952a179ee229e39847234d592ea4 /ext/bg/js/settings
parent9ce682272c5d665bbbe9cbd1380416c3d22f9b04 (diff)
Use Anki classes directly in Display (#804)
* Add _getTemplates function * Add template renderer to display pages * Add AnkiNoteBuilder to Display * Update AnkiTemplatesController to directly use TemplateRenderer * Remove old APIs
Diffstat (limited to 'ext/bg/js/settings')
-rw-r--r--ext/bg/js/settings/anki-templates-controller.js8
1 files changed, 7 insertions, 1 deletions
diff --git a/ext/bg/js/settings/anki-templates-controller.js b/ext/bg/js/settings/anki-templates-controller.js
index c05301df..c53e4553 100644
--- a/ext/bg/js/settings/anki-templates-controller.js
+++ b/ext/bg/js/settings/anki-templates-controller.js
@@ -17,6 +17,7 @@
/* global
* AnkiNoteBuilder
+ * TemplateRenderer
* api
*/
@@ -27,6 +28,7 @@ class AnkiTemplatesController {
this._cachedDefinitionValue = null;
this._cachedDefinitionText = null;
this._defaultFieldTemplates = null;
+ this._templateRenderer = new TemplateRenderer();
}
async prepare() {
@@ -144,7 +146,7 @@ class AnkiTemplatesController {
let templates = options.anki.fieldTemplates;
if (typeof templates !== 'string') { templates = this._defaultFieldTemplates; }
const ankiNoteBuilder = new AnkiNoteBuilder({
- renderTemplate: api.templateRender.bind(api)
+ renderTemplate: this._renderTemplate.bind(this)
});
const {general: {resultOutputMode, compactGlossaries}} = options;
const note = await ankiNoteBuilder.createNote({
@@ -176,4 +178,8 @@ class AnkiTemplatesController {
input.classList.toggle('is-invalid', hasException);
}
}
+
+ async _renderTemplate(template, data, marker) {
+ return await this._templateRenderer.render(template, data, marker);
+ }
}