diff options
author | praschke <stel@comfy.monster> | 2023-10-17 22:25:30 +0100 |
---|---|---|
committer | praschke <stel@comfy.monster> | 2023-10-17 22:25:30 +0100 |
commit | 9b798601b48a40b65e38b433924a99d155872ba7 (patch) | |
tree | 02ada4e52d83b4febfbf763b9cf1f1348c65e5cd | |
parent | 9f8269606fdf51765f6d13de4caac709691b0fea (diff) |
update: hasMedia and getMedia
-rw-r--r-- | docs/templates.md | 18 | ||||
-rw-r--r-- | ext/data/templates/anki-field-templates-upgrade-v21.handlebars | 36 | ||||
-rw-r--r-- | ext/data/templates/default-anki-field-templates.handlebars | 12 | ||||
-rw-r--r-- | test/test-options-util.js | 82 |
4 files changed, 133 insertions, 15 deletions
diff --git a/docs/templates.md b/docs/templates.md index e19309a7..0aa26b84 100644 --- a/docs/templates.md +++ b/docs/templates.md @@ -686,8 +686,8 @@ These functions are used together in order to request media and other types of o <details> <summary>Syntax:</summary> - <code>{{#hasMedia <i>type</i> <i>args</i>...}}{{/hasMedia}}</code><br> - <code>{{#getMedia <i>type</i> <i>args</i>... <i>[escape=true|false]</i>}}{{/getMedia}}</code><br> + <code>{{hasMedia <i>type</i> <i>args</i>...}}</code><br> + <code>{{getMedia <i>type</i> <i>args</i>... <i>[escape=true|false]</i>}}</code><br> * _`type`_ <br> The type of media to check for. @@ -710,19 +710,19 @@ These functions are used together in order to request media and other types of o <summary>Examples:</summary> ```handlebars - {{#if (hasMedia "audio")}}The audio file name is: {{#getMedia "audio"}}{{/getMedia}}{{/if}} + {{#if (hasMedia "audio")}}The audio file name is: {{getMedia "audio"}}{{/if}} - {{#if (hasMedia "screenshot")}}The screenshot file name is: {{#getMedia "screenshot"}}{{/getMedia}}{{/if}} + {{#if (hasMedia "screenshot")}}The screenshot file name is: {{getMedia "screenshot"}}{{/if}} - {{#if (hasMedia "clipboardImage")}}The clipboard image file name is: {{#getMedia "clipboardImage"}}{{/getMedia}}{{/if}} + {{#if (hasMedia "clipboardImage")}}The clipboard image file name is: {{getMedia "clipboardImage"}}{{/if}} - {{#if (hasMedia "clipboardText")}}The clipboard text is: {{#getMedia "clipboardText"}}{{/getMedia}}{{/if}} + {{#if (hasMedia "clipboardText")}}The clipboard text is: {{getMedia "clipboardText"}}{{/if}} - {{#if (hasMedia "selectionText")}}The selection text is: {{#getMedia "selectionText"}}{{/getMedia}}{{/if}} + {{#if (hasMedia "selectionText")}}The selection text is: {{getMedia "selectionText"}}{{/if}} - {{#if (hasMedia "textFurigana" "日本語")}}This is an example of text with generated furigana: {{#getMedia "textFurigana" "日本語" escape=false}}{{/getMedia}}{{/if}} + {{#if (hasMedia "textFurigana" "日本語")}}This is an example of text with generated furigana: {{getMedia "textFurigana" "日本語" escape=false}}{{/if}} - {{#if (hasMedia "dictionaryMedia" "image.png" dictionary="Example Dictionary")}}The remapped file name for image.png is: {{#getMedia "dictionaryMedia" "image.png" dictionary="Example Dictionary"}}{{/getMedia}}{{/if}} + {{#if (hasMedia "dictionaryMedia" "image.png" dictionary="Example Dictionary")}}The remapped file name for image.png is: {{getMedia "dictionaryMedia" "image.png" dictionary="Example Dictionary"}}{{/if}} ``` Output: diff --git a/ext/data/templates/anki-field-templates-upgrade-v21.handlebars b/ext/data/templates/anki-field-templates-upgrade-v21.handlebars index 2fa0f0aa..0bfd95a5 100644 --- a/ext/data/templates/anki-field-templates-upgrade-v21.handlebars +++ b/ext/data/templates/anki-field-templates-upgrade-v21.handlebars @@ -35,6 +35,12 @@ {{>>>>>>>}} {{<<<<<<<}} +[sound:{{#getMedia "audio"}}{{/getMedia}}] +{{=======}} +[sound:{{getMedia "audio"}}] +{{>>>>>>>}} + +{{<<<<<<<}} <span class="expression-{{termFrequency}}">{{~#furigana}}{{{.}}}{{/furigana~}}</span> {{=======}} <span class="expression-{{termFrequency}}">{{~furigana .~}}</span> @@ -59,6 +65,24 @@ {{>>>>>>>}} {{<<<<<<<}} +<img src="{{#getMedia "screenshot"}}{{/getMedia}}" /> +{{=======}} +<img src="{{getMedia "screenshot"}}" /> +{{>>>>>>>}} + +{{<<<<<<<}} +<img src="{{#getMedia "clipboardImage"}}{{/getMedia}}" /> +{{=======}} +<img src="{{getMedia "clipboardImage"}}" /> +{{>>>>>>>}} + +{{<<<<<<<}} +{{~#if (hasMedia "clipboardText")}}{{#getMedia "clipboardText"}}{{/getMedia}}{{/if~}} +{{=======}} +{{~#if (hasMedia "clipboardText")}}{{getMedia "clipboardText"}}{{/if~}} +{{>>>>>>>}} + +{{<<<<<<<}} {{~#furigana expression reading~}}{{~/furigana~}} {{=======}} {{~furigana expression reading~}} @@ -107,3 +131,15 @@ {{~set (concat "used_" .) true~}} {{~set "first" false~}} {{>>>>>>>}} + +{{<<<<<<<}} +{{~#if (hasMedia "selectionText")}}{{#getMedia "selectionText"}}{{/getMedia}}{{/if~}} +{{=======}} +{{~#if (hasMedia "selectionText")}}{{getMedia "selectionText"}}{{/if~}} +{{>>>>>>>}} + +{{<<<<<<<}} +{{#getMedia "textFurigana" definition.cloze.sentence escape=false}}{{/getMedia}} +{{=======}} +{{getMedia "textFurigana" definition.cloze.sentence escape=false}} +{{>>>>>>>}} diff --git a/ext/data/templates/default-anki-field-templates.handlebars b/ext/data/templates/default-anki-field-templates.handlebars index 69c7e7a1..08950f78 100644 --- a/ext/data/templates/default-anki-field-templates.handlebars +++ b/ext/data/templates/default-anki-field-templates.handlebars @@ -32,7 +32,7 @@ {{#*inline "audio"}} {{~#if (hasMedia "audio")~}} - [sound:{{#getMedia "audio"}}{{/getMedia}}] + [sound:{{getMedia "audio"}}] {{~/if~}} {{/inline}} @@ -174,7 +174,7 @@ {{#*inline "screenshot"}} {{~#if (hasMedia "screenshot")~}} - <img src="{{#getMedia "screenshot"}}{{/getMedia}}" /> + <img src="{{getMedia "screenshot"}}" /> {{~/if~}} {{/inline}} @@ -231,12 +231,12 @@ {{#*inline "clipboard-image"}} {{~#if (hasMedia "clipboardImage")~}} - <img src="{{#getMedia "clipboardImage"}}{{/getMedia}}" /> + <img src="{{getMedia "clipboardImage"}}" /> {{~/if~}} {{/inline}} {{#*inline "clipboard-text"}} - {{~#if (hasMedia "clipboardText")}}{{#getMedia "clipboardText"}}{{/getMedia}}{{/if~}} + {{~#if (hasMedia "clipboardText")}}{{getMedia "clipboardText"}}{{/if~}} {{/inline}} {{#*inline "conjugation"}} @@ -316,13 +316,13 @@ {{/inline}} {{#*inline "selection-text"}} - {{~#if (hasMedia "selectionText")}}{{#getMedia "selectionText"}}{{/getMedia}}{{/if~}} + {{~#if (hasMedia "selectionText")}}{{getMedia "selectionText"}}{{/if~}} {{/inline}} {{#*inline "sentence-furigana"}} {{~#if definition.cloze~}} {{~#if (hasMedia "textFurigana" definition.cloze.sentence)~}} - {{#getMedia "textFurigana" definition.cloze.sentence escape=false}}{{/getMedia}} + {{getMedia "textFurigana" definition.cloze.sentence escape=false}} {{~else~}} {{definition.cloze.sentence}} {{~/if~}} diff --git a/test/test-options-util.js b/test/test-options-util.js index 78204de9..23cfc121 100644 --- a/test/test-options-util.js +++ b/test/test-options-util.js @@ -1480,6 +1480,88 @@ async function testFieldTemplatesUpdate(extDir) { {{/inline}} {{~> (lookup . "marker") ~}}`.trimStart() + }, + // block helper update: hasMedia and getMedia + { + oldVersion: 20, + newVersion: 21, + old: ` +{{#*inline "audio"}} + {{~#if (hasMedia "audio")~}} + [sound:{{#getMedia "audio"}}{{/getMedia}}] + {{~/if~}} +{{/inline}} + +{{#*inline "screenshot"}} + {{~#if (hasMedia "screenshot")~}} + <img src="{{#getMedia "screenshot"}}{{/getMedia}}" /> + {{~/if~}} +{{/inline}} + +{{#*inline "clipboard-image"}} + {{~#if (hasMedia "clipboardImage")~}} + <img src="{{#getMedia "clipboardImage"}}{{/getMedia}}" /> + {{~/if~}} +{{/inline}} + +{{#*inline "clipboard-text"}} + {{~#if (hasMedia "clipboardText")}}{{#getMedia "clipboardText"}}{{/getMedia}}{{/if~}} +{{/inline}} + +{{#*inline "selection-text"}} + {{~#if (hasMedia "selectionText")}}{{#getMedia "selectionText"}}{{/getMedia}}{{/if~}} +{{/inline}} + +{{#*inline "sentence-furigana"}} + {{~#if definition.cloze~}} + {{~#if (hasMedia "textFurigana" definition.cloze.sentence)~}} + {{#getMedia "textFurigana" definition.cloze.sentence escape=false}}{{/getMedia}} + {{~else~}} + {{definition.cloze.sentence}} + {{~/if~}} + {{~/if~}} +{{/inline}} + +{{~> (lookup . "marker") ~}}`.trimStart(), + + expected: ` +{{#*inline "audio"}} + {{~#if (hasMedia "audio")~}} + [sound:{{getMedia "audio"}}] + {{~/if~}} +{{/inline}} + +{{#*inline "screenshot"}} + {{~#if (hasMedia "screenshot")~}} + <img src="{{getMedia "screenshot"}}" /> + {{~/if~}} +{{/inline}} + +{{#*inline "clipboard-image"}} + {{~#if (hasMedia "clipboardImage")~}} + <img src="{{getMedia "clipboardImage"}}" /> + {{~/if~}} +{{/inline}} + +{{#*inline "clipboard-text"}} + {{~#if (hasMedia "clipboardText")}}{{getMedia "clipboardText"}}{{/if~}} +{{/inline}} + +{{#*inline "selection-text"}} + {{~#if (hasMedia "selectionText")}}{{getMedia "selectionText"}}{{/if~}} +{{/inline}} + +{{#*inline "sentence-furigana"}} + {{~#if definition.cloze~}} + {{~#if (hasMedia "textFurigana" definition.cloze.sentence)~}} + {{getMedia "textFurigana" definition.cloze.sentence escape=false}} + {{~else~}} + {{definition.cloze.sentence}} + {{~/if~}} + {{~/if~}} +{{/inline}} + +{{~> (lookup . "marker") ~}}`.trimStart() } ]; |