Skip to content

Ensure that patterns in direcorties greater than 2 levels deep from s… #1016

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/core/src/lib/object_factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ const Pattern = function(relPath, data, patternlab) {
this.relPath = path.normalize(relPath); // '00-atoms/00-global/00-colors.mustache'
this.fileName = pathObj.name; // '00-colors'
this.subdir = pathObj.dir; // '00-atoms/00-global'
if ((this.subdir.match(/\w(?=\\)|\w(?=\/)/g) || []).length > 1) {
this.subdir = this.subdir.split(/\/|\\/, 2).join(path.sep); // '00-atoms/03-controls/00-button' -> '00-atoms/03-controls'
}
this.fileExtension = pathObj.ext; // '.mustache'

// this is the unique name, subDir + fileName (sans extension)
Expand Down
25 changes: 11 additions & 14 deletions packages/core/test/object_factory_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ tap.test(
path.sep +
'colors.mustache'
);
test.equals(p.name, '00-atoms-00-global-00-colors');
test.equals(p.name, '00-atoms-00-global');
test.equals(
p.subdir,
'00-atoms' + path.sep + '00-global' + path.sep + '00-colors'
'00-atoms' + path.sep + '00-global'
);
test.equals(p.fileName, 'colors');
test.equals(p.fileExtension, '.mustache');
Expand All @@ -91,12 +91,12 @@ tap.test(
test.equals(p.patternName, 'Colors');
test.equals(
p.getPatternLink(pl),
'00-atoms-00-global-00-colors' +
'00-atoms-00-global' +
path.sep +
'00-atoms-00-global-00-colors.rendered.html'
'00-atoms-00-global.rendered.html'
);
test.equals(p.patternGroup, 'atoms');
test.equals(p.patternSubGroup, 'global');
test.equals(p.patternSubGroup, 'atoms'); //because of p.info.hasDir
test.equals(p.flatPatternPath, '00-atoms-00-global');
test.equals(p.patternPartial, 'atoms-colors');
test.equals(p.template, '');
Expand All @@ -111,15 +111,15 @@ tap.test(
);

tap.test('test Pattern name for variants correctly initialzed', function(test) {
var p1 = new Pattern('00-atoms/00-global/00-colors/colors~variant.mustache', {
var p1 = new Pattern('00-atoms/00-global/colors~variant.mustache', {
d: 123,
});
var p2 = new Pattern(
'00-atoms/00-global/00-colors/colors~variant-minus.json',
'00-atoms/00-global/colors~variant-minus.json',
{ d: 123 }
);
test.equals(p1.name, '00-atoms-00-global-00-colors-variant');
test.equals(p2.name, '00-atoms-00-global-00-colors-variant-minus');
test.equals(p1.name, '00-atoms-00-global-colors-variant');
test.equals(p2.name, '00-atoms-00-global-colors-variant-minus');
test.end();
});

Expand Down Expand Up @@ -205,11 +205,8 @@ tap.test(
{ d: 123 }
);
test.equals(p.getDirLevel(0, { hasDir: true, dirLevel: 3 }), '00-atoms');
test.equals(p.getDirLevel(1, { hasDir: true, dirLevel: 3 }), '00-global');
test.equals(
p.getDirLevel(3, { hasDir: true, dirLevel: 3 }),
'00-colors-alt'
);
test.equals(p.getDirLevel(1, { hasDir: true, dirLevel: 3 }), '00-atoms');
test.equals(p.getDirLevel(3, { hasDir: true, dirLevel: 3 }), '');
var p = new Pattern('00-atoms/00-colors-alt/colors-alt.mustache', {
d: 123,
});
Expand Down