From 4ed949364564f00a8b871095d030af516fc2ed6d Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sun, 10 Jan 2021 19:28:50 -0500 Subject: Refactor anki note building (#1223) * Move TemplateRendererProxy creation into AnkiNoteBuilder * Simplify _stringReplaceAsync * Organize note generation * Rename API * Make the template rendering function more generic --- ext/bg/js/settings/anki-controller.js | 4 +--- ext/bg/js/settings/anki-templates-controller.js | 12 ++---------- 2 files changed, 3 insertions(+), 13 deletions(-) (limited to 'ext/bg/js/settings') diff --git a/ext/bg/js/settings/anki-controller.js b/ext/bg/js/settings/anki-controller.js index 4fba77a6..fbd058ee 100644 --- a/ext/bg/js/settings/anki-controller.js +++ b/ext/bg/js/settings/anki-controller.js @@ -26,9 +26,7 @@ class AnkiController { constructor(settingsController) { this._settingsController = settingsController; this._ankiConnect = new AnkiConnect(); - this._ankiNoteBuilder = new AnkiNoteBuilder({ - renderTemplate: null - }); + this._ankiNoteBuilder = new AnkiNoteBuilder(false); this._selectorObserver = new SelectorObserver({ selector: '.anki-card', ignoreSelector: null, diff --git a/ext/bg/js/settings/anki-templates-controller.js b/ext/bg/js/settings/anki-templates-controller.js index 72f1a175..dd07c391 100644 --- a/ext/bg/js/settings/anki-templates-controller.js +++ b/ext/bg/js/settings/anki-templates-controller.js @@ -17,7 +17,6 @@ /* global * AnkiNoteBuilder - * TemplateRendererProxy * api */ @@ -34,7 +33,7 @@ class AnkiTemplatesController { this._renderFieldInput = null; this._renderResult = null; this._fieldTemplateResetModal = null; - this._templateRenderer = new TemplateRendererProxy(); + this._ankiNoteBuilder = new AnkiNoteBuilder(true); } async prepare() { @@ -180,11 +179,8 @@ class AnkiTemplatesController { }; let templates = options.anki.fieldTemplates; if (typeof templates !== 'string') { templates = this._defaultFieldTemplates; } - const ankiNoteBuilder = new AnkiNoteBuilder({ - renderTemplate: this._renderTemplate.bind(this) - }); const {general: {resultOutputMode, glossaryLayoutMode, compactTags}} = options; - const note = await ankiNoteBuilder.createNote({ + const note = await this._ankiNoteBuilder.createNote({ definition, mode, context, @@ -213,8 +209,4 @@ class AnkiTemplatesController { this._fieldTemplatesTextarea.dataset.invalid = `${hasException}`; } } - - async _renderTemplate(template, data, marker) { - return await this._templateRenderer.render(template, data, marker); - } } -- cgit v1.2.3