diff --git a/packages/core/src/lib/object_factory.js b/packages/core/src/lib/object_factory.js index 77e32b5cf..83524a9c7 100644 --- a/packages/core/src/lib/object_factory.js +++ b/packages/core/src/lib/object_factory.js @@ -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) diff --git a/packages/core/test/object_factory_tests.js b/packages/core/test/object_factory_tests.js index 92d46cc17..81f5f4ad4 100644 --- a/packages/core/test/object_factory_tests.js +++ b/packages/core/test/object_factory_tests.js @@ -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'); @@ -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, ''); @@ -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(); }); @@ -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, });