Template patcher updates (#1766)
* Don't append anything if the additions is empty * Simplify update list
This commit is contained in:
parent
e7ba321eb9
commit
6b8cd5e623
@ -77,6 +77,7 @@ class TemplatePatcher {
|
|||||||
// Private
|
// Private
|
||||||
|
|
||||||
_addFieldTemplatesBeforeEnd(template, addition) {
|
_addFieldTemplatesBeforeEnd(template, addition) {
|
||||||
|
if (addition.length === 0) { return template; }
|
||||||
const newline = '\n';
|
const newline = '\n';
|
||||||
let replaced = false;
|
let replaced = false;
|
||||||
template = template.replace(this._lookupMarkerPattern, (g0) => {
|
template = template.replace(this._lookupMarkerPattern, (g0) => {
|
||||||
|
@ -649,12 +649,23 @@ async function testFieldTemplatesUpdate(extDir) {
|
|||||||
const content = fs.readFileSync(path.join(extDir, fileName), {encoding: 'utf8'});
|
const content = fs.readFileSync(path.join(extDir, fileName), {encoding: 'utf8'});
|
||||||
return templatePatcher.parsePatch(content).addition;
|
return templatePatcher.parsePatch(content).addition;
|
||||||
};
|
};
|
||||||
const update2 = loadDataFile('data/templates/anki-field-templates-upgrade-v2.handlebars');
|
const updates = [
|
||||||
const update4 = loadDataFile('data/templates/anki-field-templates-upgrade-v4.handlebars');
|
{version: 2, changes: loadDataFile('data/templates/anki-field-templates-upgrade-v2.handlebars')},
|
||||||
const update6 = loadDataFile('data/templates/anki-field-templates-upgrade-v6.handlebars');
|
{version: 4, changes: loadDataFile('data/templates/anki-field-templates-upgrade-v4.handlebars')},
|
||||||
const update8 = loadDataFile('data/templates/anki-field-templates-upgrade-v8.handlebars');
|
{version: 6, changes: loadDataFile('data/templates/anki-field-templates-upgrade-v6.handlebars')},
|
||||||
const update10 = loadDataFile('data/templates/anki-field-templates-upgrade-v10.handlebars');
|
{version: 8, changes: loadDataFile('data/templates/anki-field-templates-upgrade-v8.handlebars')},
|
||||||
const update12 = loadDataFile('data/templates/anki-field-templates-upgrade-v12.handlebars');
|
{version: 10, changes: loadDataFile('data/templates/anki-field-templates-upgrade-v10.handlebars')},
|
||||||
|
{version: 12, changes: loadDataFile('data/templates/anki-field-templates-upgrade-v12.handlebars')}
|
||||||
|
];
|
||||||
|
const getUpdateAdditions = (startVersion=0) => {
|
||||||
|
let value = '';
|
||||||
|
for (const {version, changes} of updates) {
|
||||||
|
if (version < startVersion || changes.length === 0) { continue; }
|
||||||
|
if (value.length > 0) { value += '\n'; }
|
||||||
|
value += changes;
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
};
|
||||||
|
|
||||||
const data = [
|
const data = [
|
||||||
// Standard format
|
// Standard format
|
||||||
@ -671,12 +682,7 @@ async function testFieldTemplatesUpdate(extDir) {
|
|||||||
{{~definition.character~}}
|
{{~definition.character~}}
|
||||||
{{/inline}}
|
{{/inline}}
|
||||||
|
|
||||||
${update2}
|
${getUpdateAdditions()}
|
||||||
${update4}
|
|
||||||
${update6}
|
|
||||||
${update8}
|
|
||||||
${update10}
|
|
||||||
${update12}
|
|
||||||
{{~> (lookup . "marker") ~}}`.trimStart()
|
{{~> (lookup . "marker") ~}}`.trimStart()
|
||||||
},
|
},
|
||||||
// Non-standard marker format
|
// Non-standard marker format
|
||||||
@ -694,12 +700,7 @@ ${update12}
|
|||||||
{{/inline}}
|
{{/inline}}
|
||||||
|
|
||||||
{{~> (lookup . "marker2") ~}}
|
{{~> (lookup . "marker2") ~}}
|
||||||
${update2}
|
${getUpdateAdditions()}`.trimStart()
|
||||||
${update4}
|
|
||||||
${update6}
|
|
||||||
${update8}
|
|
||||||
${update10}
|
|
||||||
${update12}`.trimStart()
|
|
||||||
},
|
},
|
||||||
// Empty test
|
// Empty test
|
||||||
{
|
{
|
||||||
@ -707,12 +708,7 @@ ${update12}`.trimStart()
|
|||||||
{{~> (lookup . "marker") ~}}`.trimStart(),
|
{{~> (lookup . "marker") ~}}`.trimStart(),
|
||||||
|
|
||||||
expected: `
|
expected: `
|
||||||
${update2}
|
${getUpdateAdditions()}
|
||||||
${update4}
|
|
||||||
${update6}
|
|
||||||
${update8}
|
|
||||||
${update10}
|
|
||||||
${update12}
|
|
||||||
{{~> (lookup . "marker") ~}}`.trimStart()
|
{{~> (lookup . "marker") ~}}`.trimStart()
|
||||||
},
|
},
|
||||||
// Definition tags update
|
// Definition tags update
|
||||||
@ -782,12 +778,7 @@ ${update12}
|
|||||||
{{~> glossary-single definition brief=brief compactGlossaries=../compactGlossaries data=../.~}}
|
{{~> glossary-single definition brief=brief compactGlossaries=../compactGlossaries data=../.~}}
|
||||||
{{/inline}}
|
{{/inline}}
|
||||||
|
|
||||||
${update2}
|
${getUpdateAdditions()}
|
||||||
${update4}
|
|
||||||
${update6}
|
|
||||||
${update8}
|
|
||||||
${update10}
|
|
||||||
${update12}
|
|
||||||
{{~> (lookup . "marker") ~}}
|
{{~> (lookup . "marker") ~}}
|
||||||
`.trimStart()
|
`.trimStart()
|
||||||
},
|
},
|
||||||
@ -927,9 +918,7 @@ ${update12}
|
|||||||
{{~> glossary brief=true ~}}
|
{{~> glossary brief=true ~}}
|
||||||
{{/inline}}
|
{{/inline}}
|
||||||
|
|
||||||
${update8}
|
${getUpdateAdditions(7)}
|
||||||
${update10}
|
|
||||||
${update12}
|
|
||||||
{{~> (lookup . "marker") ~}}`.trimStart()
|
{{~> (lookup . "marker") ~}}`.trimStart()
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
Loading…
Reference in New Issue
Block a user