Skip to content

Commit 6c0e72f

Browse files
committed
parsing with outputfileSuffix accounted for
fixed all unit tests fix #428
1 parent cfee9ff commit 6c0e72f

5 files changed

+67
-6
lines changed

core/lib/pattern_assembler.js

+20-3
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ var pattern_assembler = function () {
4545
return patternlab.patterns[i];
4646
}
4747
}
48-
console.error('Could not find pattern with partial ' + partialName);
48+
if (patternlab.config.debug) {
49+
console.error('Could not find pattern with partial ' + partialName);
50+
}
4951
return undefined;
5052
}
5153

@@ -92,7 +94,7 @@ var pattern_assembler = function () {
9294
function addPattern(pattern, patternlab) {
9395

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

9799
//only push to array if the array doesn't contain this pattern
98100
var isNew = true;
@@ -412,27 +414,42 @@ var pattern_assembler = function () {
412414
function parseDataLinksHelper(patternlab, obj, key) {
413415
var linkRE, dataObjAsString, linkMatches;
414416

417+
//check for link.patternPartial
415418
linkRE = /link\.[A-z0-9-_]+/g;
419+
420+
//stringify the passed in object
416421
dataObjAsString = JSON5.stringify(obj);
422+
if (!dataObjAsString) { return obj; }
423+
424+
//find matches
417425
linkMatches = dataObjAsString.match(linkRE);
418426

419427
if (linkMatches) {
420428
for (var i = 0; i < linkMatches.length; i++) {
421429
var dataLink = linkMatches[i];
422430
if (dataLink && dataLink.split('.').length >= 2) {
431+
432+
//get the partial the link refers to
423433
var linkPatternPartial = dataLink.split('.')[1];
424434
var pattern = getPartial(linkPatternPartial, patternlab);
425435
if (pattern !== undefined) {
436+
437+
//get the full built link and replace it
426438
var fullLink = patternlab.data.link[linkPatternPartial];
427439
if (fullLink) {
428440
fullLink = path.normalize(fullLink).replace(/\\/g, '/');
429441
if (patternlab.config.debug) {
430442
console.log('expanded data link from ' + dataLink + ' to ' + fullLink + ' inside ' + key);
431443
}
444+
445+
//also make sure our global replace didn't mess up a protocol
446+
fullLink = fullLink.replace(/:\//g, '://');
432447
dataObjAsString = dataObjAsString.replace(dataLink, fullLink);
433448
}
434449
} else {
435-
console.log('pattern not found for', dataLink, 'inside', key);
450+
if (patternlab.config.debug) {
451+
console.log('pattern not found for', dataLink, 'inside', key);
452+
}
436453
}
437454
}
438455
}

test/lineage_hunter_tests.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ function createBasePatternLabObject() {
2828
source: {
2929
patterns: patterns_dir
3030
}
31+
},
32+
outputFileSuffixes: {
33+
rendered: ''
3134
}
3235
};
3336
pl.data = {};
@@ -111,7 +114,12 @@ exports['lineage hunter '] = {
111114
"lineageR": [],
112115
"lineageRIndex": []
113116
}
114-
]
117+
],
118+
config: {
119+
outputFileSuffixes: {
120+
rendered: ''
121+
}
122+
}
115123
};
116124

117125
var lineage_hunter = new lh();

test/list_item_hunter_tests.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,10 @@
6565
"source": {
6666
"patterns": "./test/files/_patterns"
6767
}
68-
}
68+
},
69+
"outputFileSuffixes": {
70+
"rendered": ''
71+
}
6972
},
7073
"partials" : {},
7174
"patterns" : []

test/pattern_assembler_tests.js

+33-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
var patternlab = {};
2121
patternlab.config = fs.readJSONSync('./patternlab-config.json');
2222
patternlab.config.paths.source.patterns = patterns_dir;
23+
patternlab.config.outputFileSuffixes = {rendered : ''};
2324

2425
//patternlab.data = fs.readJSONSync(path.resolve(patternlab.config.paths.source.data, 'data.json'));
2526
patternlab.data = {};
@@ -73,6 +74,9 @@
7374
source: {
7475
patterns: patterns_dir
7576
}
77+
},
78+
outputFileSuffixes: {
79+
rendered : ''
7680
}
7781
};
7882
pl.data = {};
@@ -113,6 +117,9 @@
113117
source: {
114118
patterns: patterns_dir
115119
}
120+
},
121+
outputFileSuffixes: {
122+
rendered : ''
116123
}
117124
};
118125
pl.data = {};
@@ -154,6 +161,9 @@
154161
source: {
155162
patterns: patterns_dir
156163
}
164+
},
165+
outputFileSuffixes: {
166+
rendered : ''
157167
}
158168
};
159169
pl.data = {};
@@ -193,6 +203,9 @@
193203
source: {
194204
patterns: patterns_dir
195205
}
206+
},
207+
outputFileSuffixes: {
208+
rendered : ''
196209
}
197210
};
198211
pl.data = {};
@@ -233,6 +246,9 @@
233246
source: {
234247
patterns: patterns_dir
235248
}
249+
},
250+
outputFileSuffixes: {
251+
rendered : ''
236252
}
237253
};
238254
pl.data = {};
@@ -274,6 +290,9 @@
274290
source: {
275291
patterns: patterns_dir
276292
}
293+
},
294+
outputFileSuffixes: {
295+
rendered : ''
277296
}
278297
};
279298
pl.data = {};
@@ -356,6 +375,7 @@
356375
//THIS IS BAD
357376
patternlab.config = fs.readJSONSync('./patternlab-config.json');
358377
patternlab.config.paths.source.patterns = patterns_dir;
378+
patternlab.config.outputFileSuffixes = { rendered : '' };
359379
patternlab.data = {};
360380
patternlab.listitems = {};
361381
patternlab.header = {};
@@ -364,7 +384,17 @@
364384
//patternlab.listitems = fs.readJSONSync(path.resolve(patternlab.config.paths.source.data, 'listitems.json'));
365385
//patternlab.header = fs.readFileSync(path.resolve(patternlab.config.paths.source.patternlabFiles, 'templates/pattern-header-footer/header.html'), 'utf8');
366386
//patternlab.footer = fs.readFileSync(path.resolve(patternlab.config.paths.source.patternlabFiles, 'templates/pattern-header-footer/footer.html'), 'utf8');
367-
patternlab.patterns = [];
387+
patternlab.patterns = [
388+
{
389+
patternPartial: 'twitter-brad'
390+
},
391+
{
392+
patternPartial: 'twitter-dave'
393+
},
394+
{
395+
patternPartial: 'twitter-brian'
396+
}
397+
];
368398
patternlab.data.link = {};
369399
patternlab.partials = {};
370400

@@ -454,6 +484,7 @@
454484
patternlab.partials = {};
455485
patternlab.data = {link: {}};
456486
patternlab.config = { debug: false };
487+
patternlab.config.outputFileSuffixes = {rendered : ''};
457488

458489
var pattern = new Pattern('00-test/01-bar.mustache');
459490
pattern.extendedTemplate = 'barExtended';
@@ -476,6 +507,7 @@
476507
patternlab.partials = {};
477508
patternlab.data = {link: {}};
478509
patternlab.config = { debug: false };
510+
patternlab.config.outputFileSuffixes = {rendered : ''};
479511

480512
var pattern = new Pattern('00-test/01-bar.mustache');
481513
pattern.extendedTemplate = undefined;

test/pseudopattern_hunter_tests.js

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ exports['pseudopattern_hunter'] = {
2626
pl.patterns = [];
2727
pl.partials = {};
2828
pl.config.patternStates = {};
29+
pl.config.outputFileSuffixes = { rendered: ''}
2930

3031
var atomPattern = new Pattern('00-test/03-styled-atom.mustache');
3132
atomPattern.template = fs.readFileSync(patterns_dir + '00-test/03-styled-atom.mustache', 'utf8');

0 commit comments

Comments
 (0)