Skip to content

Commit 53eee9f

Browse files
committed
Merge branch 'david-moldenhauer-feature/multilevel-patterns' into dev
2 parents 0ca1a3f + eaaa274 commit 53eee9f

File tree

2 files changed

+14
-20
lines changed

2 files changed

+14
-20
lines changed

packages/core/src/lib/object_factory.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ const Pattern = function(relPath, data, patternlab) {
3535
this.relPath = path.normalize(relPath); // '00-atoms/00-global/00-colors.mustache'
3636
this.fileName = pathObj.name; // '00-colors'
3737
this.subdir = pathObj.dir; // '00-atoms/00-global'
38+
if ((this.subdir.match(/\w(?=\\)|\w(?=\/)/g) || []).length > 1) {
39+
this.subdir = this.subdir.split(/\/|\\/, 2).join(path.sep); // '00-atoms/03-controls/00-button' -> '00-atoms/03-controls'
40+
}
3841
this.fileExtension = pathObj.ext; // '.mustache'
3942

4043
// this is the unique name, subDir + fileName (sans extension)

packages/core/test/object_factory_tests.js

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -79,24 +79,19 @@ tap.test(
7979
path.sep +
8080
'colors.mustache'
8181
);
82-
test.equals(p.name, '00-atoms-00-global-00-colors');
83-
test.equals(
84-
p.subdir,
85-
'00-atoms' + path.sep + '00-global' + path.sep + '00-colors'
86-
);
82+
test.equals(p.name, '00-atoms-00-global');
83+
test.equals(p.subdir, '00-atoms' + path.sep + '00-global');
8784
test.equals(p.fileName, 'colors');
8885
test.equals(p.fileExtension, '.mustache');
8986
test.equals(p.jsonFileData.d, 123);
9087
test.equals(p.patternBaseName, 'colors');
9188
test.equals(p.patternName, 'Colors');
9289
test.equals(
9390
p.getPatternLink(pl),
94-
'00-atoms-00-global-00-colors' +
95-
path.sep +
96-
'00-atoms-00-global-00-colors.rendered.html'
91+
'00-atoms-00-global' + path.sep + '00-atoms-00-global.rendered.html'
9792
);
9893
test.equals(p.patternGroup, 'atoms');
99-
test.equals(p.patternSubGroup, 'global');
94+
test.equals(p.patternSubGroup, 'global'); //because of p.info.hasDir
10095
test.equals(p.flatPatternPath, '00-atoms-00-global');
10196
test.equals(p.patternPartial, 'atoms-colors');
10297
test.equals(p.template, '');
@@ -111,15 +106,14 @@ tap.test(
111106
);
112107

113108
tap.test('test Pattern name for variants correctly initialzed', function(test) {
114-
var p1 = new Pattern('00-atoms/00-global/00-colors/colors~variant.mustache', {
109+
var p1 = new Pattern('00-atoms/00-global/colors~variant.mustache', {
115110
d: 123,
116111
});
117-
var p2 = new Pattern(
118-
'00-atoms/00-global/00-colors/colors~variant-minus.json',
119-
{ d: 123 }
120-
);
121-
test.equals(p1.name, '00-atoms-00-global-00-colors-variant');
122-
test.equals(p2.name, '00-atoms-00-global-00-colors-variant-minus');
112+
var p2 = new Pattern('00-atoms/00-global/colors~variant-minus.json', {
113+
d: 123,
114+
});
115+
test.equals(p1.name, '00-atoms-00-global-colors-variant');
116+
test.equals(p2.name, '00-atoms-00-global-colors-variant-minus');
123117
test.end();
124118
});
125119

@@ -206,10 +200,7 @@ tap.test(
206200
);
207201
test.equals(p.getDirLevel(0, { hasDir: true, dirLevel: 3 }), '00-atoms');
208202
test.equals(p.getDirLevel(1, { hasDir: true, dirLevel: 3 }), '00-global');
209-
test.equals(
210-
p.getDirLevel(3, { hasDir: true, dirLevel: 3 }),
211-
'00-colors-alt'
212-
);
203+
test.equals(p.getDirLevel(3, { hasDir: true, dirLevel: 3 }), '');
213204
var p = new Pattern('00-atoms/00-colors-alt/colors-alt.mustache', {
214205
d: 123,
215206
});

0 commit comments

Comments
 (0)