From 0f17ecc053407b47bd6654d3d2b37afafb88e48e Mon Sep 17 00:00:00 2001 From: Volodymyr Malyhin Date: Fri, 4 Oct 2024 15:53:36 +0300 Subject: [PATCH 1/2] feat: add tags for removing parts from template --- lib/parse-template.js | 4 +++- lib/template-cutter.js | 16 ++++++++++++++++ tests/template-cutter.js | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+), 1 deletion(-) diff --git a/lib/parse-template.js b/lib/parse-template.js index ed201b5..442f68c 100644 --- a/lib/parse-template.js +++ b/lib/parse-template.js @@ -17,7 +17,9 @@ module.exports = (handledTags, baseTemplatesCacheSize) => { Promise.resolve().then(() => { const templateCutter = new TemplateCutter(); - const cuttedBaseTemplate = templateCutter.cut(baseTemplate); + const cuttedBaseTemplate = templateCutter.cut( + templateCutter.remove(baseTemplate) + ); const chunks = transform.applyTransforms( cuttedBaseTemplate, diff --git a/lib/template-cutter.js b/lib/template-cutter.js index c2c11e2..4be4f0b 100644 --- a/lib/template-cutter.js +++ b/lib/template-cutter.js @@ -4,6 +4,8 @@ const MARKED_PARTS_TO_IGNORE = /.*?/gims; const IGNORED_PART_WITH_INDEX = //gm; +const MARKED_PARTS_TO_REMOVE = + /.*?/gims; function replaceIgnorePart(ignoredPartIndex) { return ``; @@ -31,6 +33,20 @@ class TemplateCutter { }); } + /** + * Remove base templates special parts which marked with the help of special HTML comments: + * and + * before and after a content which you want to remove before parsing + * + * @example
{ 'TailorX can not find an ignored part 100 of the current template during restoring!' ); }); + + it('should remove marked parts from the base template', () => { + const baseTemplate = + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '
' + + '' + + '
' + + '' + + '
' + + '' + + '
' + + '' + + ''; + + const expectedTemplate = + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '
' + + '' + + '
' + + '' + + ''; + + const result = templateCutter.remove(baseTemplate); + assert.equal(result, expectedTemplate); + }); }); From 137d68a99b58b0840075ef9b16375943ff0e2d36 Mon Sep 17 00:00:00 2001 From: Volodymyr Malyhin Date: Mon, 7 Oct 2024 09:00:58 +0300 Subject: [PATCH 2/2] 8.2.0 --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 7da64c6..28d8c0f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@namecheap/tailorx", - "version": "8.1.0", + "version": "8.2.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@namecheap/tailorx", - "version": "8.1.0", + "version": "8.2.0", "license": "Apache-2.0", "dependencies": { "@namecheap/error-extender": "^2.0.0", diff --git a/package.json b/package.json index bb7d293..f17a763 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@namecheap/tailorx", - "version": "8.1.0", + "version": "8.2.0", "description": "Tailor assembles a web page from multiple fragments", "keywords": [ "tailor",