Skip to content

Commit e73ac24

Browse files
authored
Merge pull request #1054 from kmonahan/feature/fix-directory-naming
fix(1049): Treat folders like patterns only if they're subfolders of …
2 parents a93e552 + bfef44d commit e73ac24

11 files changed

+38
-29
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];

packages/core/test/object_factory_tests.js

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ tap.test('test Pattern capitalizes patternDisplayName correctly', function(
178178
test.end();
179179
});
180180

181-
tap.test('test Pattern get dir level no sepatated pattern directory', function(
181+
tap.test('test Pattern get dir level no separated pattern directory', function(
182182
test
183183
) {
184184
var p = new Pattern('00-atoms/00-global/00-colors-alt.mustache', { d: 123 });
@@ -198,24 +198,36 @@ tap.test('test Pattern get dir level no sepatated pattern directory', function(
198198
});
199199

200200
tap.test(
201-
'test Pattern get dir level with sepatated pattern directory',
201+
'test Pattern get dir level with separated pattern directory',
202202
function(test) {
203203
var p = new Pattern(
204204
'00-atoms/00-global/00-colors-alt/colors-alt.mustache',
205205
{ d: 123 }
206206
);
207207
test.equals(p.getDirLevel(0, { hasDir: true, dirLevel: 3 }), '00-atoms');
208208
test.equals(p.getDirLevel(1, { hasDir: true, dirLevel: 3 }), '00-global');
209-
test.equals(p.getDirLevel(3, { hasDir: true, dirLevel: 3 }), '');
209+
test.equals(
210+
p.getDirLevel(3, { hasDir: true, dirLevel: 3 }),
211+
'00-colors-alt'
212+
);
210213
var p = new Pattern('00-atoms/00-colors-alt/colors-alt.mustache', {
211214
d: 123,
212215
});
213216
test.equals(p.getDirLevel(0, { hasDir: true, dirLevel: 2 }), '00-atoms');
214-
test.equals(p.getDirLevel(1, { hasDir: true, dirLevel: 2 }), '00-atoms');
217+
test.equals(
218+
p.getDirLevel(1, { hasDir: true, dirLevel: 2 }),
219+
'00-colors-alt'
220+
);
215221
test.equals(p.getDirLevel(3, { hasDir: true, dirLevel: 2 }), '');
216222
var p = new Pattern('00-colors-alt/colors-alt.mustache', { d: 123 });
217-
test.equals(p.getDirLevel(0, { hasDir: true, dirLevel: 1 }), '');
218-
test.equals(p.getDirLevel(1, { hasDir: true, dirLevel: 1 }), '');
223+
test.equals(
224+
p.getDirLevel(0, { hasDir: true, dirLevel: 1 }),
225+
'00-colors-alt'
226+
);
227+
test.equals(
228+
p.getDirLevel(1, { hasDir: true, dirLevel: 1 }),
229+
'00-colors-alt'
230+
);
219231
test.equals(p.getDirLevel(3, { hasDir: true, dirLevel: 1 }), '');
220232
test.end();
221233
}

packages/uikit-workshop/dist/styleguide/js/patternlab-pattern.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/uikit-workshop/dist/styleguide/js/patternlab-viewer.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/uikit-workshop/dist/styleguide/js/pl-modal-viewer-chunk-7506fe4aa4d15996d2ad.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

packages/uikit-workshop/dist/styleguide/js/pl-modal-viewer-chunk-ed8e352aad9ffe2ff692.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/uikit-workshop/dist/styleguide/js/pl-plugin-loader-chunk-4f1ccb7cc375a296d19f.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

packages/uikit-workshop/dist/styleguide/js/pl-plugin-loader-chunk-c06d0d01bbade5b0b123.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/uikit-workshop/dist/styleguide/js/vendors-chunk-293d3e32578ff722034c.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

packages/uikit-workshop/dist/styleguide/js/vendors-chunk-68c417591f725b5a10b5.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)