Skip to content

Commit 5386288

Browse files
committed
refactor: enabled fileendings separated with more than one dot
1 parent 9935c0b commit 5386288

File tree

5 files changed

+37
-17
lines changed

5 files changed

+37
-17
lines changed

packages/core/src/lib/object_factory.js

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,31 @@ const Pattern = function (
4141
*/
4242
const pathObj = path.parse(this.relPath);
4343

44+
// We need to check for templates with a fileextension that contains multiple dots like e.g. .html.twig
45+
if (
46+
patternlab?.config?.patternExtension?.includes('.') &&
47+
this.relPath.endsWith('.' + patternlab.config.patternExtension)
48+
) {
49+
this.fileName = path.basename(
50+
this.relPath,
51+
'.' + patternlab.config.patternExtension
52+
); // e.g. 'colors'
53+
} else {
54+
this.fileName = pathObj.name; // e.g. 'colors'
55+
}
56+
this.subdir = pathObj.dir; // 'atoms/global'
57+
this.fileExtension = pathObj.ext; // '.hbs'
58+
4459
const info = this.getPatternInfo(
4560
pathObj,
4661
patternlab,
4762
isPromoteToFlatPatternRun ||
4863
(patternlab &&
4964
patternlab.config &&
50-
patternlab.config.allPatternsAreDeeplyNested)
65+
patternlab.config.allPatternsAreDeeplyNested),
66+
this.fileName
5167
);
5268

53-
this.fileName = pathObj.name; // 'colors'
54-
this.subdir = pathObj.dir; // 'atoms/global'
55-
this.fileExtension = pathObj.ext; // '.mustache'
56-
5769
// TODO: Remove if block when dropping ordering by prefix and keep else code
5870
// (When we drop the info about the old ordering is deprecated)
5971
if (
@@ -345,15 +357,20 @@ Pattern.prototype = {
345357
*
346358
* @param pathObj path.parse() object containing useful path information
347359
*/
348-
getPatternInfo: (pathObj, patternlab, isPromoteToFlatPatternRun) => {
360+
getPatternInfo: (
361+
pathObj,
362+
patternlab,
363+
isPromoteToFlatPatternRun,
364+
filename
365+
) => {
349366
const info = {
350367
// colors(.mustache) is deeply nested in atoms-/global/colors
351368
patternlab: patternlab,
352369
patternHasOwnDir: isPromoteToFlatPatternRun
353370
? path.basename(pathObj.dir).replace(prefixMatcher, '') ===
354-
pathObj.name.replace(prefixMatcher, '') ||
371+
filename.replace(prefixMatcher, '') ||
355372
path.basename(pathObj.dir).replace(prefixMatcher, '') ===
356-
pathObj.name.split('~')[0].replace(prefixMatcher, '')
373+
filename.split('~')[0].replace(prefixMatcher, '')
357374
: false,
358375
};
359376

packages/engine-handlebars/lib/engine_handlebars.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,8 @@ const engine_handlebars = {
129129
* assume it's already present
130130
*/
131131
spawnMeta: function (config) {
132-
this.spawnFile(config, '_head.hbs');
133-
this.spawnFile(config, '_foot.hbs');
132+
this.spawnFile(config, '_head.' + config.patternExtension);
133+
this.spawnFile(config, '_foot.' + config.patternExtension);
134134
},
135135

136136
/**

packages/engine-mustache/lib/engine_mustache.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ const engine_mustache = {
104104
* assume it's already present
105105
*/
106106
spawnMeta: function (config) {
107-
this.spawnFile(config, '_head.mustache');
108-
this.spawnFile(config, '_foot.mustache');
107+
this.spawnFile(config, '_head.' + config.patternExtension);
108+
this.spawnFile(config, '_foot.' + config.patternExtension);
109109
},
110110

111111
// find and return any {{> template-name }} within pattern

packages/engine-twig-php/lib/engine_twig_php.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ let patternLabConfig = {};
2525
const engine_twig_php = {
2626
engine: TwigRenderer,
2727
engineName: 'twig-php',
28-
engineFileExtension: '.twig',
28+
engineFileExtension: ['.twig', '.html.twig'],
2929
expandPartials: false,
3030
findPartialsRE:
3131
/{%\s*(?:extends|include|embed)\s+('[^']+'|"[^"]+").*?(with|%}|\s*%})/g,
@@ -120,7 +120,10 @@ const engine_twig_php = {
120120
*/
121121
spawnMeta(config) {
122122
const { paths } = config;
123-
['_head.twig', '_foot.twig'].forEach((fileName) => {
123+
[
124+
'_head.' + config.patternExtension,
125+
'_foot.' + config.patternExtension,
126+
].forEach((fileName) => {
124127
const metaFilePath = path.resolve(paths.source.meta, fileName);
125128
try {
126129
fs.statSync(metaFilePath);

packages/engine-twig/lib/engine_twig.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ var metaPath;
121121
var engine_twig = {
122122
engine: twing,
123123
engineName: 'twig',
124-
engineFileExtension: '.twig',
124+
engineFileExtension: ['.twig', '.html.twig'],
125125

126126
// regexes, stored here so they're only compiled once
127127
findPartialsRE:
@@ -203,8 +203,8 @@ var engine_twig = {
203203
* assume it's already present
204204
*/
205205
spawnMeta: function (config) {
206-
this.spawnFile(config, '_head.twig');
207-
this.spawnFile(config, '_foot.twig');
206+
this.spawnFile(config, '_head.' + config.patternExtension);
207+
this.spawnFile(config, '_foot.' + config.patternExtension);
208208
},
209209

210210
/**

0 commit comments

Comments
 (0)