Skip to content

Commit 4eb79ab

Browse files
committed
fix(1049): Treat folders like patterns only if they're subfolders of pattern groupings
1 parent d1344d3 commit 4eb79ab

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

packages/core/src/lib/object_factory.js

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ const Pattern = function(relPath, data, patternlab) {
3939

4040
// this is the unique name, subDir + fileName (sans extension)
4141
this.name = '';
42-
if (info.hasDir) {
42+
if (info.hasDir && info.dirLevel > 2) {
4343
let variant = '';
4444

4545
if (this.fileName.indexOf('~') !== -1) {
@@ -76,23 +76,24 @@ const Pattern = function(relPath, data, patternlab) {
7676
.trim(); //this is the display name for the ui. strip numeric + hyphen prefixes
7777

7878
//00-atoms if needed
79-
this.patternType = this.getDirLevel(0, info);
79+
this.patternType = this.getDirLevel(0);
8080

8181
// the top-level pattern group this pattern belongs to. 'atoms'
8282
this.patternGroup = this.patternType.replace(patternPrefixMatcher, '');
8383

8484
//00-colors if needed
85-
this.patternSubType = this.getDirLevel(1, info);
85+
this.patternSubType = this.getDirLevel(1);
8686

8787
// the sub-group this pattern belongs to.
8888
this.patternSubGroup = this.patternSubType.replace(patternPrefixMatcher, ''); // 'global'
8989

9090
// the joined pattern group and subgroup directory
91-
this.flatPatternPath = info.hasDir
92-
? this.subdir
93-
.replace(/[/\\]/g, '-')
94-
.replace(new RegExp('-' + info.dir + '$'), '')
95-
: this.subdir.replace(/[\/\\]/g, '-'); // '00-atoms-00-global'
91+
this.flatPatternPath =
92+
info.hasDir && info.dirLevel > 2
93+
? this.subdir
94+
.replace(/[/\\]/g, '-')
95+
.replace(new RegExp('-' + info.dir + '$'), '')
96+
: this.subdir.replace(/[\/\\]/g, '-'); // '00-atoms-00-global'
9697

9798
// calculated path from the root of the public directory to the generated
9899
// (rendered!) html file for this pattern, to be shown in the iframe
@@ -214,11 +215,8 @@ Pattern.prototype = {
214215
return this.engine.findPartial(partialString);
215216
},
216217

217-
getDirLevel: function(level, info) {
218+
getDirLevel: function(level) {
218219
const items = this.subdir.split(path.sep);
219-
if (info.hasDir) {
220-
items.pop();
221-
}
222220

223221
if (items[level]) {
224222
return items[level];

0 commit comments

Comments
 (0)