From d85d912ba963489d533492df134e559e1ab88500 Mon Sep 17 00:00:00 2001 From: david-moldenhauer Date: Thu, 23 May 2019 13:22:15 +0200 Subject: [PATCH 1/4] Ensure that patterns in direcorties greater than 2 levels deep from source are sorted to the next possible parent directory. This allowes file structures like: 00-atoms/03-controls/00-button - button.pattern - button.md - button.scss - button.js --- packages/core/src/lib/object_factory.js | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/core/src/lib/object_factory.js b/packages/core/src/lib/object_factory.js index 8135e3988..e82932e6a 100644 --- a/packages/core/src/lib/object_factory.js +++ b/packages/core/src/lib/object_factory.js @@ -35,6 +35,7 @@ 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' + this.subdir = (this.subdir.match(/\w(?=\\)|\w(?=\/)/g) || []).length > 1 ? this.subdir.split(/\/|\\/, 2).join(path.sep) : this.subdir; // '00-atoms/03-controls/00-button' -> '00-atoms/00-global' this.fileExtension = pathObj.ext; // '.mustache' // this is the unique name, subDir + fileName (sans extension) From 4b813958da2d8578a777368117b7085179aede72 Mon Sep 17 00:00:00 2001 From: david-moldenhauer Date: Thu, 23 May 2019 18:07:02 +0200 Subject: [PATCH 2/4] changed to an if statement instead of shorthand to pass 'pretty' test --- packages/core/src/lib/object_factory.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/core/src/lib/object_factory.js b/packages/core/src/lib/object_factory.js index e82932e6a..2e4bb8d96 100644 --- a/packages/core/src/lib/object_factory.js +++ b/packages/core/src/lib/object_factory.js @@ -35,7 +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' - this.subdir = (this.subdir.match(/\w(?=\\)|\w(?=\/)/g) || []).length > 1 ? this.subdir.split(/\/|\\/, 2).join(path.sep) : this.subdir; // '00-atoms/03-controls/00-button' -> '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/00-global' + } this.fileExtension = pathObj.ext; // '.mustache' // this is the unique name, subDir + fileName (sans extension) From 6a306ce624ea4e05ed447a7edad130d40341162b Mon Sep 17 00:00:00 2001 From: david-moldenhauer Date: Thu, 23 May 2019 18:18:52 +0200 Subject: [PATCH 3/4] =?UTF-8?q?fixed=20error=20Replace=20`((this.subdir.ma?= =?UTF-8?q?tch(/\w(=3F=3D\\)|\w(=3F=3D\/)/g)=C2=B7||=C2=B7[]).length=C2=B7?= =?UTF-8?q?>=C2=B71)`=20with=20`=C2=B7((this.subdir.match(/\w(=3F=3D\\)|\w?= =?UTF-8?q?(=3F=3D\/)/g)=C2=B7||=C2=B7[]).length=C2=B7>=C2=B71)=C2=B7=20fi?= =?UTF-8?q?xed=20error=20Replace=20`=E2=86=B9`=20with=20`=C2=B7=C2=B7`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/core/src/lib/object_factory.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/core/src/lib/object_factory.js b/packages/core/src/lib/object_factory.js index 2e4bb8d96..6697840c5 100644 --- a/packages/core/src/lib/object_factory.js +++ b/packages/core/src/lib/object_factory.js @@ -35,8 +35,8 @@ 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/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/00-global' } this.fileExtension = pathObj.ext; // '.mustache' From 83509fb348b59bc136697eb98f6e06812ec1645c Mon Sep 17 00:00:00 2001 From: david-moldenhauer Date: Sat, 25 May 2019 18:32:12 +0200 Subject: [PATCH 4/4] took the liberty to adjust tests for third level subdirectories. Why Pattern.info.hasDir exists and why Pattern.getDirLevel removes the last folder when this is true does not make sense to me. I'm guessing this is for a currently not functioning workaround to support a third sublevel if the folder and pattern name match. --- packages/core/src/lib/object_factory.js | 2 +- packages/core/test/object_factory_tests.js | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/packages/core/src/lib/object_factory.js b/packages/core/src/lib/object_factory.js index 6697840c5..aca46615e 100644 --- a/packages/core/src/lib/object_factory.js +++ b/packages/core/src/lib/object_factory.js @@ -36,7 +36,7 @@ const Pattern = function(relPath, data, patternlab) { 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/00-global' + this.subdir = this.subdir.split(/\/|\\/, 2).join(path.sep); // '00-atoms/03-controls/00-button' -> '00-atoms/03-controls' } this.fileExtension = pathObj.ext; // '.mustache' diff --git a/packages/core/test/object_factory_tests.js b/packages/core/test/object_factory_tests.js index 166416e27..44db8a590 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,7 +205,7 @@ 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(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,