aboutsummaryrefslogtreecommitdiff
path: root/ext/js/templates/template-patcher.js
diff options
context:
space:
mode:
Diffstat (limited to 'ext/js/templates/template-patcher.js')
-rw-r--r--ext/js/templates/template-patcher.js18
1 files changed, 18 insertions, 0 deletions
diff --git a/ext/js/templates/template-patcher.js b/ext/js/templates/template-patcher.js
index 6bc012bc..33abb08e 100644
--- a/ext/js/templates/template-patcher.js
+++ b/ext/js/templates/template-patcher.js
@@ -18,12 +18,20 @@
export class TemplatePatcher {
constructor() {
+ /** @type {RegExp} */
this._diffPattern1 = /\n?\{\{<<<<<<<\}\}\n/g;
+ /** @type {RegExp} */
this._diffPattern2 = /\n\{\{=======\}\}\n/g;
+ /** @type {RegExp} */
this._diffPattern3 = /\n\{\{>>>>>>>\}\}\n*/g;
+ /** @type {RegExp} */
this._lookupMarkerPattern = /[ \t]*\{\{~?>\s*\(\s*lookup\s*\.\s*"marker"\s*\)\s*~?\}\}/g;
}
+ /**
+ * @param {string} content
+ * @returns {import('template-patcher').Patch}
+ */
parsePatch(content) {
const diffPattern1 = this._diffPattern1;
const diffPattern2 = this._diffPattern2;
@@ -61,6 +69,11 @@ export class TemplatePatcher {
return {addition: content, modifications};
}
+ /**
+ * @param {string} template
+ * @param {import('template-patcher').Patch} patch
+ * @returns {string}
+ */
applyPatch(template, patch) {
for (const {current, replacement} of patch.modifications) {
let fromIndex = 0;
@@ -77,6 +90,11 @@ export class TemplatePatcher {
// Private
+ /**
+ * @param {string} template
+ * @param {string} addition
+ * @returns {string}
+ */
_addFieldTemplatesBeforeEnd(template, addition) {
if (addition.length === 0) { return template; }
const newline = '\n';