Skip to content

Commit 1935b1c

Browse files
committed
replace pattern.patternLink with pattern.getPatternLink(pl) to output
correct static file paths; add and fix unit tests
1 parent e698056 commit 1935b1c

File tree

6 files changed

+185
-98
lines changed

6 files changed

+185
-98
lines changed

core/lib/lineage_hunter.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ var lineage_hunter = function () {
2222
//create the more complex patternLineage object too
2323
var l = {
2424
"lineagePattern": ancestorPattern.patternPartial,
25-
"lineagePath": "../../patterns/" + ancestorPattern.patternLink
25+
"lineagePath": "../../patterns/" + ancestorPattern.getPatternLink(patternlab)
2626
};
27+
2728
if (ancestorPattern.patternState) {
2829
l.lineageState = ancestorPattern.patternState;
2930
}
@@ -37,7 +38,7 @@ var lineage_hunter = function () {
3738
//create the more complex patternLineage object in reverse
3839
var lr = {
3940
"lineagePattern": pattern.patternPartial,
40-
"lineagePath": "../../patterns/" + pattern.patternLink
41+
"lineagePath": "../../patterns/" + pattern.getPatternLink(patternlab)
4142
};
4243
if (pattern.patternState) {
4344
lr.lineageState = pattern.patternState;

core/lib/object_factory.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@ var Pattern = function (relPath, data) {
2929
return val.charAt(0).toUpperCase() + val.slice(1) + ' ' + working.charAt(0).toUpperCase() + working.slice(1);
3030
}, '').trim(); //this is the display name for the ui. strip numeric + hyphen prefixes
3131

32-
// calculated path from the root of the public directory to the generated html
33-
// file for this pattern
34-
this.patternLink = this.name + path.sep + this.name + '.html'; // '00-atoms-00-global-00-colors/00-atoms-00-global-00-colors.html'
35-
3632
// the top-level pattern group this pattern belongs to. 'atoms'
3733
this.patternGroup = this.subdir.split(path.sep)[0].replace(/^\d*-/, '');
3834

@@ -84,6 +80,22 @@ Pattern.prototype = {
8480
}
8581
},
8682

83+
// calculated path from the root of the public directory to the generated html
84+
// file for this pattern.
85+
// Should look something like '00-atoms-00-global-00-colors/00-atoms-00-global-00-colors.html'
86+
getPatternLink: function (patternlab, suffixType) {
87+
// if no suffixType is provided, we default to rendered
88+
var suffixConfig = patternlab.config.outputFileSuffixes;
89+
var suffix = suffixType ? suffixConfig[suffixType] : suffixConfig.rendered;
90+
91+
if (this.patternLink) {
92+
// Someone or something has explicitly set a patternLink on this pattern.
93+
// We had better respect that.
94+
return this.patternLink;
95+
}
96+
return this.name + path.sep + this.name + suffix + '.html';
97+
},
98+
8799
// the finders all delegate to the PatternEngine, which also encapsulates all
88100
// appropriate regexes
89101
findPartials: function () {

core/lib/pattern_assembler.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ var pattern_assembler = function () {
9494
function addPattern(pattern, patternlab) {
9595

9696
//add the link to the global object
97-
patternlab.data.link[pattern.patternPartial] = '/patterns/' + pattern.patternLink.replace('.html', patternlab.config.outputFileSuffixes.rendered + '.html');
97+
patternlab.data.link[pattern.patternPartial] = '/patterns/' + pattern.getPatternLink(patternlab);
9898

9999
//only push to array if the array doesn't contain this pattern
100100
var isNew = true;

core/lib/patternlab.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -355,13 +355,13 @@ var patternlab_engine = function (config) {
355355

356356
//write the compiled template to the public patterns directory
357357
var patternPage = headHTML + pattern.patternPartialCode + footerHTML;
358-
fs.outputFileSync(paths.public.patterns + pattern.patternLink.replace('.html', patternlab.config.outputFileSuffixes.rendered + '.html'), patternPage);
358+
fs.outputFileSync(paths.public.patterns + pattern.getPatternLink(patternlab, 'rendered'), patternPage);
359359

360360
//write the mustache file too
361-
fs.outputFileSync(paths.public.patterns + pattern.patternLink.replace('.html', patternlab.config.outputFileSuffixes.rawTemplate + pattern.fileExtension), pattern.template);
361+
fs.outputFileSync(paths.public.patterns + pattern.getPatternLink(patternlab, 'rawTemplate'), pattern.template);
362362

363363
//write the encoded version too
364-
fs.outputFileSync(paths.public.patterns + pattern.patternLink.replace('.html', patternlab.config.outputFileSuffixes.markupOnly + '.html'), pattern.patternPartialCode);
364+
fs.outputFileSync(paths.public.patterns + pattern.getPatternLink(patternlab, 'markupOnly'), pattern.patternPartialCode);
365365

366366
return true;
367367
});

test/lineage_hunter_tests.js

Lines changed: 65 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,18 @@ function createBasePatternLabObject() {
3030
}
3131
},
3232
outputFileSuffixes: {
33-
rendered: ''
34-
}
33+
rendered: '.rendered',
34+
rawTemplate: '',
35+
markupOnly: '.markup-only'
36+
},
37+
patternStateCascade: ["inprogress", "inreview", "complete"]
3538
};
3639
pl.data = {};
3740
pl.data.link = {};
3841
pl.config.debug = false;
3942
pl.patterns = [];
4043
pl.partials = {};
41-
pl.config.patternStateCascade = ["inprogress", "inreview", "complete"];
44+
4245
return pl;
4346
}
4447

@@ -57,7 +60,7 @@ exports['lineage hunter '] = {
5760

5861
var patternlab = {
5962
patterns: [
60-
{
63+
Pattern.createEmpty({
6164
"name": "00-atoms-03-images-00-logo",
6265
"subdir": "00-atoms\\03-images",
6366
"filename": "00-logo.mustache",
@@ -75,8 +78,8 @@ exports['lineage hunter '] = {
7578
"lineageIndex": [],
7679
"lineageR": [],
7780
"lineageRIndex": []
78-
},
79-
{
81+
}),
82+
Pattern.createEmpty({
8083
"name": "01-molecules-05-navigation-00-primary-nav",
8184
"subdir": "01-molecules\\05-navigation",
8285
"filename": "00-primary-nav.mustache",
@@ -94,8 +97,8 @@ exports['lineage hunter '] = {
9497
"lineageIndex": [],
9598
"lineageR": [],
9699
"lineageRIndex": []
97-
},
98-
{
100+
}),
101+
Pattern.createEmpty({
99102
"name": "01-molecules-04-forms-00-search",
100103
"subdir": "01-molecules\\04-forms",
101104
"filename": "00-search.mustache",
@@ -113,11 +116,13 @@ exports['lineage hunter '] = {
113116
"lineageIndex": [],
114117
"lineageR": [],
115118
"lineageRIndex": []
116-
}
119+
})
117120
],
118121
config: {
119122
outputFileSuffixes: {
120-
rendered: ''
123+
rendered: '.rendered',
124+
rawTemplate: '',
125+
markupOnly: '.markup-only'
121126
}
122127
}
123128
};
@@ -150,7 +155,14 @@ exports['lineage hunter '] = {
150155
"template": "<h1> {{message}} </h1>",
151156
"extendedTemplate": "<h1> {{message}} </h1>"
152157
})
153-
]
158+
],
159+
config: {
160+
outputFileSuffixes: {
161+
rendered: '.rendered',
162+
rawTemplate: '',
163+
markupOnly: '.markup-only'
164+
}
165+
}
154166
};
155167

156168
lineage_hunter.find_lineage(currentPattern, patternlab);
@@ -286,7 +298,7 @@ exports['lineage hunter '] = {
286298

287299
var patternlab = {
288300
patterns: [
289-
{
301+
Pattern.createEmpty({
290302
"name": "01-atoms-05-alerts-00-error",
291303
"subdir": "01-atoms\\05-alerts",
292304
"filename": "00-error.mustache",
@@ -304,8 +316,15 @@ exports['lineage hunter '] = {
304316
"lineageIndex": [],
305317
"lineageR": [],
306318
"lineageRIndex": []
319+
})
320+
],
321+
config: {
322+
outputFileSuffixes: {
323+
rendered: '.rendered',
324+
rawTemplate: '',
325+
markupOnly: '.markup-only'
307326
}
308-
]
327+
}
309328
};
310329

311330
var lineage_hunter = new lh();
@@ -361,7 +380,14 @@ exports['lineage hunter '] = {
361380
"lineageR": [],
362381
"lineageRIndex": []
363382
})
364-
]
383+
],
384+
config: {
385+
outputFileSuffixes: {
386+
rendered: '.rendered',
387+
rawTemplate: '',
388+
markupOnly: '.markup-only'
389+
}
390+
}
365391
};
366392

367393
var lineage_hunter = new lh();
@@ -415,7 +441,14 @@ exports['lineage hunter '] = {
415441
"lineageR": [],
416442
"lineageRIndex": []
417443
})
418-
]
444+
],
445+
config: {
446+
outputFileSuffixes: {
447+
rendered: '.rendered',
448+
rawTemplate: '',
449+
markupOnly: '.markup-only'
450+
}
451+
}
419452
};
420453

421454
var lineage_hunter = new lh();
@@ -469,7 +502,14 @@ exports['lineage hunter '] = {
469502
"lineageR": [],
470503
"lineageRIndex": []
471504
})
472-
]
505+
],
506+
config: {
507+
outputFileSuffixes: {
508+
rendered: '.rendered',
509+
rawTemplate: '',
510+
markupOnly: '.markup-only'
511+
}
512+
}
473513
};
474514

475515
var lineage_hunter = new lh();
@@ -490,7 +530,7 @@ exports['lineage hunter '] = {
490530
});
491531
var patternlab = {
492532
patterns: [
493-
{
533+
Pattern.createEmpty({
494534
"name": "01-atoms-05-alerts-00-error",
495535
"subdir": "01-atoms\\05-alerts",
496536
"filename": "00-error.mustache",
@@ -508,8 +548,15 @@ exports['lineage hunter '] = {
508548
"lineageIndex": [],
509549
"lineageR": [],
510550
"lineageRIndex": []
551+
})
552+
],
553+
config: {
554+
outputFileSuffixes: {
555+
rendered: '.rendered',
556+
rawTemplate: '',
557+
markupOnly: '.markup-only'
511558
}
512-
]
559+
}
513560
};
514561

515562
var lineage_hunter = new lh();

0 commit comments

Comments
 (0)