(refactor) factor out generation of example parts

This commit is contained in:
Valentyne Stigloher 2023-11-04 00:11:45 +01:00
parent a68a4bad62
commit 89e8ec4576
3 changed files with 9 additions and 8 deletions

View File

@ -1,6 +1,6 @@
<template>
<span>
<span v-for="part in example[(example.isHonorific ? pronoun.isPluralHonorific(counter) : pronoun.isPlural(counter)) ? 'pluralParts' : 'singularParts']">
<span v-for="part in example.parts(pronoun, counter)">
<strong v-if="part.variable"><Spelling escape :text="pronoun.getMorpheme(part.str, counter)"/></strong>
<span v-else><Spelling :text="part.str"/></span>
</span>

View File

@ -85,7 +85,7 @@
<template v-for="isHonorific in [false, true]" v-if="examples.filter(e => e.isHonorific === isHonorific).length">
<ul>
<li v-for="example in examples" v-if="example.isHonorific === isHonorific">
<span v-for="part in clearExampleParts(example[(isHonorific ? selectedPronoun.isPluralHonorific() : selectedPronoun.isPlural()) ? 'pluralParts' : 'singularParts'])">
<span v-for="part in clearExampleParts(example.parts(selectedPronoun))">
<input v-if="part.variable" v-model="selectedPronoun.morphemes[part.str]"
:class="['form-control form-input p-0', {'active': selectedMorpheme === part.str}]"
:size="selectedPronoun.morphemes[part.str] ? selectedPronoun.morphemes[part.str].length : 0"

View File

@ -38,17 +38,18 @@ export class Example {
return parts;
}
format(pronoun) {
const plural = this.isHonorific ? pronoun.pluralHonorific[0] : pronoun.plural[0];
parts(pronoun, counter = 0) {
const plural = this.isHonorific ? pronoun.pluralHonorific[counter] : pronoun.plural[counter];
return this[plural ? 'pluralParts' : 'singularParts'];
}
return capitalise(this[plural ? 'pluralParts' : 'singularParts'].map(part => {
format(pronoun) {
return capitalise(this.parts(pronoun).map(part => {
return part.variable ? pronoun.getMorpheme(part.str) : part.str;
}).join(''));
}
pronounce(pronoun) {
const plural = this.isHonorific ? pronoun.pluralHonorific[0] : pronoun.plural[0];
let interchangable = false;
const buildPronunciation = m => {
@ -73,7 +74,7 @@ export class Example {
);
}
const ssml = '<speak>' + this[plural ? 'pluralParts' : 'singularParts'].map(part => {
const ssml = '<speak>' + this.parts(pronoun).map(part => {
return part.variable
? buildPronunciation(part.str)
: part.str;