Skip to content

Commit 2225f99

Browse files
author
Josef Bredereck
committed
Remove eslint-disable and made changed pattern name and dir behavior
It is now possible to set up patterns like `../00-colors/00-colors.(extension)` or `../00-colors/colors.(extension)` the match will be the pattern name without the prefix numbers.
1 parent 8ffce15 commit 2225f99

File tree

2 files changed

+12
-15
lines changed

2 files changed

+12
-15
lines changed

packages/core/src/lib/object_factory.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ const Pattern = function(relPath, data, patternlab) {
2424
const info = {};
2525
// 00-colors(.mustache) is subbed in 00-atoms-/00-global/00-colors
2626
info.hasDir =
27-
path.basename(pathObj.dir) === pathObj.name ||
28-
path.basename(pathObj.dir) === pathObj.name.split('~')[0];
27+
path.basename(pathObj.dir).replace(patternPrefixMatcher, '') ===
28+
pathObj.name.replace(patternPrefixMatcher, '') ||
29+
path.basename(pathObj.dir).replace(patternPrefixMatcher, '') ===
30+
pathObj.name.split('~')[0].replace(patternPrefixMatcher, '');
2931

3032
info.dir = info.hasDir ? pathObj.dir.split(path.sep).pop() : '';
3133
info.dirLevel = pathObj.dir.split(path.sep).length;
@@ -96,9 +98,7 @@ const Pattern = function(relPath, data, patternlab) {
9698
// (rendered!) html file for this pattern, to be shown in the iframe
9799
this.patternLink = this.patternSectionSubtype
98100
? `$${this.name}/index.html`
99-
: patternlab // eslint-disable-next-line prettier/prettier
100-
? this.getPatternLink(patternlab, 'rendered') // eslint-disable-next-line prettier/prettier
101-
: null;
101+
: patternlab ? this.getPatternLink(patternlab, 'rendered') : null;
102102

103103
// The canonical "key" by which this pattern is known. This is the callable
104104
// name of the pattern. UPDATE: this.key is now known as this.patternPartial

packages/core/test/object_factory_tests.js

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ tap.test('test Pattern initializes correctly', function(test) {
6666
tap.test(
6767
'test Pattern initializes correctly with pattern in sepatated directory',
6868
function(test) {
69-
var p = new Pattern('00-atoms/00-global/00-colors/00-colors.mustache', {
69+
var p = new Pattern('00-atoms/00-global/00-colors/colors.mustache', {
7070
d: 123,
7171
});
7272
test.equals(
@@ -77,14 +77,14 @@ tap.test(
7777
path.sep +
7878
'00-colors' +
7979
path.sep +
80-
'00-colors.mustache'
80+
'colors.mustache'
8181
);
8282
test.equals(p.name, '00-atoms-00-global-00-colors');
8383
test.equals(
8484
p.subdir,
8585
'00-atoms' + path.sep + '00-global' + path.sep + '00-colors'
8686
);
87-
test.equals(p.fileName, '00-colors');
87+
test.equals(p.fileName, 'colors');
8888
test.equals(p.fileExtension, '.mustache');
8989
test.equals(p.jsonFileData.d, 123);
9090
test.equals(p.patternBaseName, 'colors');
@@ -111,14 +111,11 @@ tap.test(
111111
);
112112

113113
tap.test('test Pattern name for variants correctly initialzed', function(test) {
114-
var p1 = new Pattern(
115-
'00-atoms/00-global/00-colors/00-colors~variant.mustache',
116-
{
117-
d: 123,
118-
}
119-
);
114+
var p1 = new Pattern('00-atoms/00-global/00-colors/colors~variant.mustache', {
115+
d: 123,
116+
});
120117
var p2 = new Pattern(
121-
'00-atoms/00-global/00-colors/00-colors~variant-minus.json',
118+
'00-atoms/00-global/00-colors/colors~variant-minus.json',
122119
{ d: 123 }
123120
);
124121
test.equals(p1.name, '00-atoms-00-global-00-colors-variant');

0 commit comments

Comments
 (0)