diff --git a/pages/_.vue b/pages/_.vue
index 6d306f1b1..0008f5d83 100644
--- a/pages/_.vue
+++ b/pages/_.vue
@@ -14,7 +14,10 @@
- ({{selectedTemplate.description}})
+ ({{Array.isArray(selectedTemplate.description)
+ ? ('Formy wymienne: ' + selectedTemplate.description.join(' lub '))
+ : selectedTemplate.description
+ }})
@@ -29,7 +32,7 @@
-
- {{selectedTemplate.morphemes[part.str]}}
+ {{selectedTemplate.getMorpheme(part.str, counter)}}
{{part.str}}
@@ -75,6 +78,13 @@
getTemplate: getTemplate,
selectedTemplate: buildTemplate(templates, this.$route.path.substr(1)),
+
+ counter: 0,
+ }
+ },
+ mounted() {
+ if (process.client) {
+ setInterval(_ => this.counter++, 1000);
}
},
head() {
diff --git a/src/buildTemplate.js b/src/buildTemplate.js
index c306fdc53..633d3cae0 100644
--- a/src/buildTemplate.js
+++ b/src/buildTemplate.js
@@ -24,10 +24,18 @@ export const buildTemplate = (templates, path) => {
const templatesWithAliases = addAliasesToTemplates(templates);
const templateStr = path.split(',');
- const base = templatesWithAliases[templateStr[0]]
+
+ let base = null;
+ for (let option of templateStr[0].split('&')) {
+ if (!base) {
+ base = templatesWithAliases[option]
+ } else {
+ base = base.merge(templatesWithAliases[option])
+ }
+ }
return templateStr.length === 1
- ? templatesWithAliases[templateStr[0]]
+ ? base
: Template.from(Compressor.uncompress(templateStr, base ? base.toArray() : null));
}
diff --git a/src/classes.js b/src/classes.js
index ba3f1f8bf..fa5d0ee44 100644
--- a/src/classes.js
+++ b/src/classes.js
@@ -1,3 +1,5 @@
+import {buildDict} from "./helpers";
+
export class ExamplePart {
constructor(variable, str) {
this.variable = variable;
@@ -106,14 +108,16 @@ export const MORPHEMES = [
];
const escape = s => {
+ if (Array.isArray(s)) {
+ s = s.join('&');
+ }
return (s || '')
.replace(/,/g, '')
.replace(/!/g, '')
.replace(/\./g, '')
//.replace(/\/', '%2F')
.replace(/#/g, '%23')
- .replace(/\?/g, '%3F')
- .replace(/&/g, '%26');
+ .replace(/\?/g, '%3F');
}
export class Template {
@@ -131,8 +135,19 @@ export class Template {
return this.morphemes['pronoun_n'];
}
- name() {
- return this.morphemes['pronoun_n'] + '/' + this.morphemes['pronoun_g'];
+ nameOptions() {
+ const options = new Set();
+ const optionsN = this.morphemes.pronoun_n.split('&');
+ const optionsG = this.morphemes.pronoun_g.split('&');
+ for (let i in optionsN) {
+ options.add(optionsN[i] + '/' + optionsG[i < optionsG.length - 1 ? i : optionsG.length - 1]);
+ }
+
+ return [...options]
+ }
+
+ name(glue = ' lub ') {
+ return this.nameOptions().join(glue)
}
clone() {
@@ -143,6 +158,34 @@ export class Template {
return this.toString() === other.toString();
}
+ merge(other) {
+ if (this.plural !== other.plural || this.pluralHonorific !== other.pluralHonorific) {
+ // Cannot mix plurality
+ return null;
+ }
+
+ return new Template(
+ Array.isArray(this.description) ? [...this.description, other.description] : [this.description, other.description],
+ buildDict(function* (that, other) {
+ for (let morpheme of MORPHEMES) {
+ yield [morpheme, (that.morphemes[morpheme] || '') + '&' + (other.morphemes[morpheme] || '')]
+ }
+ }, this, other),
+ this.plural,
+ this.pluralHonorific,
+ );
+ }
+
+ getMorpheme(morpheme, counter = 0) {
+ if (!this.morphemes[morpheme]) {
+ return null;
+ }
+
+ const options = this.morphemes[morpheme].split('&');
+
+ return options[counter % options.length]
+ }
+
toArray() {
return [
...Object.values(this.morphemes).map(s => escape(s)),