diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2021-07-18 11:20:03 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-18 11:20:03 -0400 |
commit | 10a9da4d31b4837d8c48e3cd1c36a7b760691d74 (patch) | |
tree | 0212b214e749c2c525637e24e837a914a6013822 /test/test-anki-note-builder.js | |
parent | e1230c7934084e1748e70e88b98f67e05cf0cf11 (diff) |
Anki template renderer abstraction (#1839)
* Add AnkiTemplateRenderer abstraction
* Move Anki-specific template functionality into AnkiTemplateRenderer
* Add documentation comments
Diffstat (limited to 'test/test-anki-note-builder.js')
-rw-r--r-- | test/test-anki-note-builder.js | 22 |
1 files changed, 7 insertions, 15 deletions
diff --git a/test/test-anki-note-builder.js b/test/test-anki-note-builder.js index d6b41c3b..b8002c4b 100644 --- a/test/test-anki-note-builder.js +++ b/test/test-anki-note-builder.js @@ -45,6 +45,7 @@ async function createVM() { 'js/data/anki-util.js', 'js/dom/sandbox/css-style-applier.js', 'js/display/sandbox/structured-content-generator.js', + 'js/templates/sandbox/anki-template-renderer.js', 'js/templates/sandbox/template-renderer.js', 'js/templates/sandbox/template-renderer-media-provider.js', 'lib/handlebars.min.js' @@ -52,37 +53,28 @@ async function createVM() { const [ JapaneseUtil, - TemplateRenderer, AnkiNoteBuilder, - CssStyleApplier + AnkiTemplateRenderer ] = vm.get([ 'JapaneseUtil', - 'TemplateRenderer', 'AnkiNoteBuilder', - 'CssStyleApplier' + 'AnkiTemplateRenderer' ]); - const ankiNoteDataCreator = vm.ankiNoteDataCreator; class TemplateRendererProxy { constructor() { this._preparePromise = null; - this._japaneseUtil = new JapaneseUtil(null); - this._cssStyleApplier = new CssStyleApplier('/data/structured-content-style.json'); - this._templateRenderer = new TemplateRenderer(this._japaneseUtil, this._cssStyleApplier); - this._templateRenderer.registerDataType('ankiNote', { - modifier: ({marker, commonData}) => ankiNoteDataCreator.create(marker, commonData), - composeData: (marker, commonData) => ({marker, commonData}) - }); + this._ankiTemplateRenderer = new AnkiTemplateRenderer(); } async render(template, data, type) { await this._prepare(); - return await this._templateRenderer.render(template, data, type); + return await this._ankiTemplateRenderer.templateRenderer.render(template, data, type); } async renderMulti(items) { await this._prepare(); - return await this._serializeMulti(this._templateRenderer.renderMulti(items)); + return await this._serializeMulti(this._ankiTemplateRenderer.templateRenderer.renderMulti(items)); } _prepare() { @@ -93,7 +85,7 @@ async function createVM() { } async _prepareInternal() { - await this._cssStyleApplier.prepare(); + await this._ankiTemplateRenderer.prepare(); } _serializeError(error) { |