Skip to content

Commit 03b47d8

Browse files
committed
Merge branch 'dev' into issues/393-styleguideExcludes
2 parents eb3db58 + 4668693 commit 03b47d8

File tree

7 files changed

+96
-25
lines changed

7 files changed

+96
-25
lines changed

core/lib/pattern_assembler.js

Lines changed: 20 additions & 3 deletions
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
}

core/lib/patternlab.js

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* patternlab-node - v2.4.0 - 2016
2+
* patternlab-node - v2.4.2 - 2016
33
*
44
* Brian Muenzenmeyer, Geoff Pursell, and the web community.
55
* Licensed under the MIT license.
@@ -13,10 +13,8 @@
1313
var diveSync = require('diveSync'),
1414
glob = require('glob'),
1515
_ = require('lodash'),
16-
path = require('path');
17-
18-
// GTP: these two diveSync pattern processors factored out so they can be reused
19-
// from unit tests to reduce code dupe!
16+
path = require('path'),
17+
plutils = require('./utilities');
2018

2119
function buildPatternData(dataFilesPath, fs) {
2220
var dataFilesPath = dataFilesPath;
@@ -29,6 +27,8 @@ function buildPatternData(dataFilesPath, fs) {
2927
return mergeObject;
3028
}
3129

30+
// GTP: these two diveSync pattern processors factored out so they can be reused
31+
// from unit tests to reduce code dupe!
3232
function processAllPatternsIterative(pattern_assembler, patterns_dir, patternlab) {
3333
diveSync(
3434
patterns_dir,
@@ -57,6 +57,23 @@ function processAllPatternsRecursive(pattern_assembler, patterns_dir, patternlab
5757
);
5858
}
5959

60+
function checkConfiguration(patternlab) {
61+
//default the output suffixes if not present
62+
var outputFileSuffixes = {
63+
rendered: '',
64+
rawTemplate: '',
65+
markupOnly: '.markup-only'
66+
}
67+
68+
if (!patternlab.config.outputFileSuffixes) {
69+
plutils.logOrange('Configuration Object "outputFileSuffixes" not found, and defaulted to the following:');
70+
console.log(outputFileSuffixes);
71+
plutils.logOrange('Since Pattern Lab Core 2.3.0 this configuration option is required. Suggest you add it to your patternlab-config.json file.');
72+
console.log();
73+
}
74+
patternlab.config.outputFileSuffixes = _.extend(outputFileSuffixes, patternlab.config.outputFileSuffixes);
75+
}
76+
6077
var patternlab_engine = function (config) {
6178
'use strict';
6279

@@ -66,13 +83,14 @@ var patternlab_engine = function (config) {
6683
pe = require('./pattern_exporter'),
6784
lh = require('./lineage_hunter'),
6885
ui = require('./ui_builder'),
69-
plutils = require('./utilities'),
7086
sm = require('./starterkit_manager'),
7187
patternlab = {};
7288

7389
patternlab.package = fs.readJSONSync(path.resolve(__dirname, '../../package.json'));
7490
patternlab.config = config || fs.readJSONSync(path.resolve(__dirname, '../../patternlab-config.json'));
7591

92+
checkConfiguration(patternlab);
93+
7694
var paths = patternlab.config.paths;
7795

7896
function getVersion() {
@@ -169,7 +187,7 @@ var patternlab_engine = function (config) {
169187
}
170188

171189
function loadStarterKit(starterkitName, clean) {
172-
var starterkit_manager = new sm(patternlab);
190+
var starterkit_manager = new sm(patternlab.config);
173191
starterkit_manager.load_starterkit(starterkitName, clean);
174192
}
175193

@@ -335,23 +353,15 @@ var patternlab_engine = function (config) {
335353
patternLabFoot : footerPartial
336354
});
337355

338-
//default the output suffixes if not present
339-
var outputFileSuffixes = {
340-
rendered: '',
341-
rawTemplate: '',
342-
markupOnly: '.markup-only'
343-
}
344-
outputFileSuffixes = _.extend(outputFileSuffixes, patternlab.config.outputFileSuffixes);
345-
346356
//write the compiled template to the public patterns directory
347357
var patternPage = headHTML + pattern.patternPartialCode + footerHTML;
348-
fs.outputFileSync(paths.public.patterns + pattern.patternLink.replace('.html', outputFileSuffixes.rendered + '.html'), patternPage);
358+
fs.outputFileSync(paths.public.patterns + pattern.patternLink.replace('.html', patternlab.config.outputFileSuffixes.rendered + '.html'), patternPage);
349359

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

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

356366
return true;
357367
});

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "patternlab-node",
33
"description": "Pattern Lab is a collection of tools to help you create atomic design systems. This is the node command line interface (CLI).",
4-
"version": "2.4.0",
4+
"version": "2.4.2",
55
"main": "./core/lib/patternlab.js",
66
"dependencies": {
77
"diveSync": "^0.3.0",

test/lineage_hunter_tests.js

Lines changed: 9 additions & 1 deletion
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

Lines changed: 4 additions & 1 deletion
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

Lines changed: 33 additions & 1 deletion
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

Lines changed: 1 addition & 0 deletions
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)