aboutsummaryrefslogtreecommitdiff
path: root/ext/bg/data/anki-field-templates-upgrade-v2.handlebars
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-08-01 16:23:33 -0400
committerGitHub <noreply@github.com>2020-08-01 16:23:33 -0400
commit838fd211c6737ce7e2b6802a43837cf4300b60d2 (patch)
tree24fb7fd7d8e6c494a3e51defc7f32a6c3aa73107 /ext/bg/data/anki-field-templates-upgrade-v2.handlebars
parent1e839cd230e53f822478f945cb415a8af2b09aef (diff)
Pitch accent Anki field templates (#701)
* Template helper updates * Add pitch data to exported field formatting data * Reuse note data * Add no-op * Set up pitch accent templates * Refactor version update functions * Implement upgrade process for new Anki templates * Consistency * Update README and anki.js to have matching markers
Diffstat (limited to 'ext/bg/data/anki-field-templates-upgrade-v2.handlebars')
-rw-r--r--ext/bg/data/anki-field-templates-upgrade-v2.handlebars109
1 files changed, 109 insertions, 0 deletions
diff --git a/ext/bg/data/anki-field-templates-upgrade-v2.handlebars b/ext/bg/data/anki-field-templates-upgrade-v2.handlebars
new file mode 100644
index 00000000..c018094e
--- /dev/null
+++ b/ext/bg/data/anki-field-templates-upgrade-v2.handlebars
@@ -0,0 +1,109 @@
+{{! Pitch Accents }}
+{{#*inline "pitch-accent-item-downstep-notation"}}
+ {{~#scope~}}
+ <span>
+ {{~#set "style1a"~}}display:inline-block;position:relative;{{~/set~}}
+ {{~#set "style1b"~}}padding-right:0.1em;margin-right:0.1em;{{~/set~}}
+ {{~#set "style2a"~}}display:block;user-select:none;pointer-events:none;position:absolute;top:0.1em;left:0;right:0;height:0;border-top:0.1em solid;{{~/set~}}
+ {{~#set "style2b"~}}right:-0.1em;height:0.4em;border-right:0.1em solid;{{~/set~}}
+ {{~#each (getKanaMorae reading)~}}
+ {{~#set "style1"}}{{#get "style1a"}}{{/get}}{{/set~}}
+ {{~#set "style2"}}{{/set~}}
+ {{~#if (isMoraPitchHigh @index ../position)}}
+ {{~#set "style2"}}{{#get "style2a"}}{{/get}}{{/set~}}
+ {{~#if (op "!" (isMoraPitchHigh (op "+" @index 1) ../position))~}}
+ {{~#set "style1" (op "+" (get "style1") (get "style1b"))}}{{/set~}}
+ {{~#set "style2" (op "+" (get "style2") (get "style2b"))}}{{/set~}}
+ {{~/if~}}
+ {{~/if~}}
+ <span style="{{#get "style1"}}{{/get}}">{{{.}}}<span style="{{#get "style2"}}{{/get}}"></span></span>
+ {{~/each~}}
+ </span>
+ {{~/scope~}}
+{{/inline}}
+
+{{#*inline "pitch-accent-item-graph-position-x"}}{{#op "+" 25 (op "*" index 50)}}{{/op}}{{/inline}}
+{{#*inline "pitch-accent-item-graph-position-y"}}{{#op "+" 25 (op "?:" (isMoraPitchHigh index position) 0 50)}}{{/op}}{{/inline}}
+{{#*inline "pitch-accent-item-graph-position"}}{{> pitch-accent-item-graph-position-x index=index position=position}} {{> pitch-accent-item-graph-position-y index=index position=position}}{{/inline}}
+{{#*inline "pitch-accent-item-graph"}}
+ {{~#scope~}}
+ {{~#set "morae" (getKanaMorae reading)}}{{/set~}}
+ {{~#set "morae-count" (property (get "morae") "length")}}{{/set~}}
+<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 {{#op "+" 50 (op "*" 50 (get "morae-count"))}}{{/op}} 100" style="display:inline-block;height:2em;">
+ <defs>
+ <g id="term-pitch-accent-graph-dot"><circle cx="0" cy="0" r="15" style="fill:#000;stroke:#000;stroke-width:5;" /></g>
+ <g id="term-pitch-accent-graph-dot-downstep"><circle cx="0" cy="0" r="15" style="fill:none;stroke:#000;stroke-width:5;" /><circle cx="0" cy="0" r="5" style="fill:none;stroke:#000;stroke-width:5;" /></g>
+ <g id="term-pitch-accent-graph-triangle"><path d="M0 13 L15 -13 L-15 -13 Z" style="fill:none;stroke:#000;stroke-width:5;" /></g>
+ </defs>
+ <path style="fill:none;stroke:#000;stroke-width:5;" d="
+ {{~#set "cmd" "M"}}{{/set~}}
+ {{~#each (get "morae")~}}
+ {{~#get "cmd"}}{{/get~}}
+ {{~> pitch-accent-item-graph-position index=@index position=../position~}}
+ {{~#set "cmd" "L"}}{{/set~}}
+ {{~/each~}}
+ "></path>
+ <path style="fill:none;stroke:#000;stroke-width:5;stroke-dasharray:5 5;" d="M{{> pitch-accent-item-graph-position index=(op "-" (get "morae-count") 1) position=position}} L{{> pitch-accent-item-graph-position index=(get "morae-count") position=position}}"></path>
+ {{#each (get "morae")}}
+ <use href="{{#if (op "&&" (isMoraPitchHigh @index ../position) (op "!" (isMoraPitchHigh (op "+" @index 1) ../position)))}}#term-pitch-accent-graph-dot-downstep{{else}}#term-pitch-accent-graph-dot{{/if}}" x="{{> pitch-accent-item-graph-position-x index=@index position=../position}}" y="{{> pitch-accent-item-graph-position-y index=@index position=../position}}"></use>
+ {{/each}}
+ <use href="#term-pitch-accent-graph-triangle" x="{{> pitch-accent-item-graph-position-x index=(get "morae-count") position=position}}" y="{{> pitch-accent-item-graph-position-y index=(get "morae-count") position=position}}"></use>
+</svg>
+ {{~/scope~}}
+{{/inline}}
+
+{{#*inline "pitch-accent-item-position"~}}
+ <span>[{{position}}]</span>
+{{~/inline}}
+
+{{#*inline "pitch-accent-item"}}
+ {{~#if (op "==" format "downstep-notation")~}}
+ {{~> pitch-accent-item-downstep-notation~}}
+ {{~else if (op "==" format "graph")~}}
+ {{~> pitch-accent-item-graph~}}
+ {{~else if (op "==" format "position")~}}
+ {{~> pitch-accent-item-position~}}
+ {{~/if~}}
+{{/inline}}
+
+{{#*inline "pitch-accent-item-disambiguation"}}
+ {{~#scope~}}
+ {{~#set "exclusive" (spread exclusiveExpressions exclusiveReadings)}}{{/set~}}
+ {{~#if (op ">" (property (get "exclusive") "length") 0)~}}
+ {{~#set "separator" ""~}}{{/set~}}
+ <em>({{#each (get "exclusive")~}}
+ {{~#get "separator"}}{{/get~}}{{{.}}}
+ {{~/each}} only) </em>
+ {{~/if~}}
+ {{~/scope~}}
+{{/inline}}
+
+{{#*inline "pitch-accent-list"}}
+ {{~#if (op ">" pitchCount 0)~}}
+ {{~#if (op ">" pitchCount 1)~}}<ol>{{~/if~}}
+ {{~#each pitches~}}
+ {{~#each pitches~}}
+ {{~#if (op ">" ../../pitchCount 1)~}}<li>{{~/if~}}
+ {{~> pitch-accent-item-disambiguation~}}
+ {{~> pitch-accent-item format=../../format~}}
+ {{~#if (op ">" ../../pitchCount 1)~}}</li>{{~/if~}}
+ {{~/each~}}
+ {{~/each~}}
+ {{~#if (op ">" pitchCount 1)~}}</ol>{{~/if~}}
+ {{~else~}}
+ No pitch accent data
+ {{~/if~}}
+{{/inline}}
+
+{{#*inline "pitch-accents"}}
+ {{~> pitch-accent-list format='downstep-notation'~}}
+{{/inline}}
+
+{{#*inline "pitch-accent-graphs"}}
+ {{~> pitch-accent-list format='graph'~}}
+{{/inline}}
+
+{{#*inline "pitch-accent-positions"}}
+ {{~> pitch-accent-list format='position'~}}
+{{/inline}}
+{{! End Pitch Accents }}