From 5386288469c83c0a60992a5415e0cc55afb3c920 Mon Sep 17 00:00:00 2001 From: Maximilian <787658+mfranzke@users.noreply.github.com> Date: Wed, 28 Dec 2022 00:00:12 +0100 Subject: [PATCH 1/3] refactor: enabled fileendings separated with more than one dot --- packages/core/src/lib/object_factory.js | 33 ++++++++++++++----- .../lib/engine_handlebars.js | 4 +-- .../engine-mustache/lib/engine_mustache.js | 4 +-- .../engine-twig-php/lib/engine_twig_php.js | 7 ++-- packages/engine-twig/lib/engine_twig.js | 6 ++-- 5 files changed, 37 insertions(+), 17 deletions(-) diff --git a/packages/core/src/lib/object_factory.js b/packages/core/src/lib/object_factory.js index 704474881..2c258fcf1 100644 --- a/packages/core/src/lib/object_factory.js +++ b/packages/core/src/lib/object_factory.js @@ -41,19 +41,31 @@ const Pattern = function ( */ const pathObj = path.parse(this.relPath); + // We need to check for templates with a fileextension that contains multiple dots like e.g. .html.twig + if ( + patternlab?.config?.patternExtension?.includes('.') && + this.relPath.endsWith('.' + patternlab.config.patternExtension) + ) { + this.fileName = path.basename( + this.relPath, + '.' + patternlab.config.patternExtension + ); // e.g. 'colors' + } else { + this.fileName = pathObj.name; // e.g. 'colors' + } + this.subdir = pathObj.dir; // 'atoms/global' + this.fileExtension = pathObj.ext; // '.hbs' + const info = this.getPatternInfo( pathObj, patternlab, isPromoteToFlatPatternRun || (patternlab && patternlab.config && - patternlab.config.allPatternsAreDeeplyNested) + patternlab.config.allPatternsAreDeeplyNested), + this.fileName ); - this.fileName = pathObj.name; // 'colors' - this.subdir = pathObj.dir; // 'atoms/global' - this.fileExtension = pathObj.ext; // '.mustache' - // TODO: Remove if block when dropping ordering by prefix and keep else code // (When we drop the info about the old ordering is deprecated) if ( @@ -345,15 +357,20 @@ Pattern.prototype = { * * @param pathObj path.parse() object containing useful path information */ - getPatternInfo: (pathObj, patternlab, isPromoteToFlatPatternRun) => { + getPatternInfo: ( + pathObj, + patternlab, + isPromoteToFlatPatternRun, + filename + ) => { const info = { // colors(.mustache) is deeply nested in atoms-/global/colors patternlab: patternlab, patternHasOwnDir: isPromoteToFlatPatternRun ? path.basename(pathObj.dir).replace(prefixMatcher, '') === - pathObj.name.replace(prefixMatcher, '') || + filename.replace(prefixMatcher, '') || path.basename(pathObj.dir).replace(prefixMatcher, '') === - pathObj.name.split('~')[0].replace(prefixMatcher, '') + filename.split('~')[0].replace(prefixMatcher, '') : false, }; diff --git a/packages/engine-handlebars/lib/engine_handlebars.js b/packages/engine-handlebars/lib/engine_handlebars.js index fdd6dbd14..a036f2db3 100644 --- a/packages/engine-handlebars/lib/engine_handlebars.js +++ b/packages/engine-handlebars/lib/engine_handlebars.js @@ -129,8 +129,8 @@ const engine_handlebars = { * assume it's already present */ spawnMeta: function (config) { - this.spawnFile(config, '_head.hbs'); - this.spawnFile(config, '_foot.hbs'); + this.spawnFile(config, '_head.' + config.patternExtension); + this.spawnFile(config, '_foot.' + config.patternExtension); }, /** diff --git a/packages/engine-mustache/lib/engine_mustache.js b/packages/engine-mustache/lib/engine_mustache.js index e39359490..fa9674eb0 100644 --- a/packages/engine-mustache/lib/engine_mustache.js +++ b/packages/engine-mustache/lib/engine_mustache.js @@ -104,8 +104,8 @@ const engine_mustache = { * assume it's already present */ spawnMeta: function (config) { - this.spawnFile(config, '_head.mustache'); - this.spawnFile(config, '_foot.mustache'); + this.spawnFile(config, '_head.' + config.patternExtension); + this.spawnFile(config, '_foot.' + config.patternExtension); }, // find and return any {{> template-name }} within pattern diff --git a/packages/engine-twig-php/lib/engine_twig_php.js b/packages/engine-twig-php/lib/engine_twig_php.js index c4ab2af72..923ae1279 100644 --- a/packages/engine-twig-php/lib/engine_twig_php.js +++ b/packages/engine-twig-php/lib/engine_twig_php.js @@ -25,7 +25,7 @@ let patternLabConfig = {}; const engine_twig_php = { engine: TwigRenderer, engineName: 'twig-php', - engineFileExtension: '.twig', + engineFileExtension: ['.twig', '.html.twig'], expandPartials: false, findPartialsRE: /{%\s*(?:extends|include|embed)\s+('[^']+'|"[^"]+").*?(with|%}|\s*%})/g, @@ -120,7 +120,10 @@ const engine_twig_php = { */ spawnMeta(config) { const { paths } = config; - ['_head.twig', '_foot.twig'].forEach((fileName) => { + [ + '_head.' + config.patternExtension, + '_foot.' + config.patternExtension, + ].forEach((fileName) => { const metaFilePath = path.resolve(paths.source.meta, fileName); try { fs.statSync(metaFilePath); diff --git a/packages/engine-twig/lib/engine_twig.js b/packages/engine-twig/lib/engine_twig.js index 6a2aedeca..356a331b5 100644 --- a/packages/engine-twig/lib/engine_twig.js +++ b/packages/engine-twig/lib/engine_twig.js @@ -121,7 +121,7 @@ var metaPath; var engine_twig = { engine: twing, engineName: 'twig', - engineFileExtension: '.twig', + engineFileExtension: ['.twig', '.html.twig'], // regexes, stored here so they're only compiled once findPartialsRE: @@ -203,8 +203,8 @@ var engine_twig = { * assume it's already present */ spawnMeta: function (config) { - this.spawnFile(config, '_head.twig'); - this.spawnFile(config, '_foot.twig'); + this.spawnFile(config, '_head.' + config.patternExtension); + this.spawnFile(config, '_foot.' + config.patternExtension); }, /** From 452ad5ec792505df78b874d8360fcac1e9c1ae1a Mon Sep 17 00:00:00 2001 From: Maximilian <787658+mfranzke@users.noreply.github.com> Date: Wed, 28 Dec 2022 10:13:41 +0100 Subject: [PATCH 2/3] refactor: we also want the pattern extension to include the full "extension" --- packages/core/src/lib/object_factory.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/packages/core/src/lib/object_factory.js b/packages/core/src/lib/object_factory.js index 2c258fcf1..a42ee51c3 100644 --- a/packages/core/src/lib/object_factory.js +++ b/packages/core/src/lib/object_factory.js @@ -46,15 +46,13 @@ const Pattern = function ( patternlab?.config?.patternExtension?.includes('.') && this.relPath.endsWith('.' + patternlab.config.patternExtension) ) { - this.fileName = path.basename( - this.relPath, - '.' + patternlab.config.patternExtension - ); // e.g. 'colors' + this.fileExtension = '.' + patternlab.config.patternExtension; // e.g. '.html.twig' + this.fileName = path.basename(this.relPath, this.fileExtension); // e.g. 'colors' } else { + this.fileExtension = pathObj.ext; // e.g. '.hbs' this.fileName = pathObj.name; // e.g. 'colors' } this.subdir = pathObj.dir; // 'atoms/global' - this.fileExtension = pathObj.ext; // '.hbs' const info = this.getPatternInfo( pathObj, From 4cf86b610721b55dec8390d08771528dbc20952d Mon Sep 17 00:00:00 2001 From: Maximilian <787658+mfranzke@users.noreply.github.com> Date: Wed, 28 Dec 2022 12:19:52 +0100 Subject: [PATCH 3/3] docs: added entry regarding a multi dotted fileextension --- packages/docs/src/docs/advanced-config-options.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/docs/src/docs/advanced-config-options.md b/packages/docs/src/docs/advanced-config-options.md index 7f2b5384c..ff51ae18b 100644 --- a/packages/docs/src/docs/advanced-config-options.md +++ b/packages/docs/src/docs/advanced-config-options.md @@ -57,7 +57,7 @@ Possibility to define whether the initial viewport width on opening pattern lab Sets default active pattern info code panel by file extension - if unset, uses the value out of _patternExtension_ config value, or instead use value `html` to display the html code initially, or the value defined for the _patternExtension_. -**default**: _patternExtension_ value (`"hbs"` | `"mustache"` | `"twig"` | `"html"`) +**default**: _patternExtension_ value (`"hbs"` | `"mustache"` | `"twig"` | `"html.twig"` | `"html"`) ## ishControlsHide