diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2022-03-14 22:32:08 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-14 22:32:08 -0400 |
commit | 8aa060337cea2bb8fce7864d509d07df4688f1c2 (patch) | |
tree | 7bd73b2328c84cd537f010a5bb6d7ddb269e2545 /ext/js/templates/sandbox/anki-template-renderer.js | |
parent | 4e15f923297599869e9d695940c9c56d81b0307d (diff) |
AnkiTemplateRendererContentManager (#2088)
* Make function private
* Update comments
* Refactor the content manager that is provided to StructuredContentGenerator in AnkiTemplateRenderer
* Update function to not be async, for API parity
Diffstat (limited to 'ext/js/templates/sandbox/anki-template-renderer.js')
-rw-r--r-- | ext/js/templates/sandbox/anki-template-renderer.js | 15 |
1 files changed, 5 insertions, 10 deletions
diff --git a/ext/js/templates/sandbox/anki-template-renderer.js b/ext/js/templates/sandbox/anki-template-renderer.js index 67ea0d81..c75f92d3 100644 --- a/ext/js/templates/sandbox/anki-template-renderer.js +++ b/ext/js/templates/sandbox/anki-template-renderer.js @@ -17,6 +17,7 @@ /* global * AnkiNoteDataCreator + * AnkiTemplateRendererContentManager * CssStyleApplier * DictionaryDataUtil * Handlebars @@ -534,16 +535,10 @@ class AnkiTemplateRenderer { } _createStructuredContentGenerator(data) { - const mediaLoader = { - loadMedia: async (path, dictionary, onLoad, onUnload) => { - const imageUrl = this._mediaProvider.getMedia(data, ['dictionaryMedia', path], {dictionary, format: 'fileName', default: null}); - if (imageUrl !== null) { - onLoad(imageUrl); - this._cleanupCallbacks.push(() => onUnload(true)); - } - } - }; - return new StructuredContentGenerator(mediaLoader, document); + const contentManager = new AnkiTemplateRendererContentManager(this._mediaProvider, data); + const instance = new StructuredContentGenerator(contentManager, document); + this._cleanupCallbacks.push(() => contentManager.unloadAll()); + return instance; } _formatGlossary(context, dictionary, options) { |