Skip to content

Commit 3739152

Browse files
Merge pull request #443 from pattern-lab/dev
Pattern Lab Node Core 2.4.3
2 parents 4c3d644 + 84db306 commit 3739152

10 files changed

+232
-143
lines changed

.travis.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,15 @@ before_install:
1111

1212
before_script:
1313
- npm install -g grunt-cli
14+
- npm install patternengine-node-underscore
15+
- npm install patternengine-node-handlebars
16+
- npm install patternengine-node-twig
1417

1518
branches:
1619
only:
1720
- master
1821
- dev
22+
- issue/438-runAllTestsTravis
1923

2024
notifications:
2125
webhooks:

core/lib/object_factory.js

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ var extend = require('util')._extend;
66

77
// Pattern properties
88

9-
var Pattern = function (relPath, data) {
9+
var Pattern = function (relPath, data, patternlab) {
1010
// We expect relPath to be the path of the pattern template, relative to the
1111
// root of the pattern tree. Parse out the path parts and save the useful ones.
1212
var pathObj = path.parse(path.normalize(relPath));
@@ -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

@@ -48,6 +44,10 @@ var Pattern = function (relPath, data) {
4844
// the joined pattern group and subgroup directory
4945
this.flatPatternPath = this.subdir.replace(/[\/\\]/g, '-'); // '00-atoms-00-global'
5046

47+
// calculated path from the root of the public directory to the generated
48+
// (rendered!) html file for this pattern, to be shown in the iframe
49+
this.patternLink = patternlab ? this.getPatternLink(patternlab, 'rendered') : null;
50+
5151
// The canonical "key" by which this pattern is known. This is the callable
5252
// name of the pattern. UPDATE: this.key is now known as this.patternPartial
5353
this.patternPartial = this.patternGroup + '-' + this.patternBaseName;
@@ -84,6 +84,20 @@ Pattern.prototype = {
8484
}
8585
},
8686

87+
// calculated path from the root of the public directory to the generated html
88+
// file for this pattern.
89+
// Should look something like '00-atoms-00-global-00-colors/00-atoms-00-global-00-colors.html'
90+
getPatternLink: function (patternlab, suffixType) {
91+
// if no suffixType is provided, we default to rendered
92+
var suffixConfig = patternlab.config.outputFileSuffixes;
93+
var suffix = suffixType ? suffixConfig[suffixType] : suffixConfig.rendered;
94+
95+
if (suffixType === 'rawTemplate') {
96+
return this.name + path.sep + this.name + suffix + this.fileExtension;
97+
}
98+
return this.name + path.sep + this.name + suffix + '.html';
99+
},
100+
87101
// the finders all delegate to the PatternEngine, which also encapsulates all
88102
// appropriate regexes
89103
findPartials: function () {
@@ -111,16 +125,16 @@ Pattern.prototype = {
111125

112126
// factory: creates an empty Pattern for miscellaneous internal use, such as
113127
// by list_item_hunter
114-
Pattern.createEmpty = function (customProps) {
115-
var pattern = new Pattern('', null);
128+
Pattern.createEmpty = function (customProps, patternlab) {
129+
var pattern = new Pattern('', null, patternlab);
116130
return extend(pattern, customProps);
117131
};
118132

119133
// factory: creates an Pattern object on-demand from a hash; the hash accepts
120134
// parameters that replace the positional parameters that the Pattern
121135
// constructor takes.
122-
Pattern.create = function (relPath, data, customProps) {
123-
var newPattern = new Pattern(relPath || '', data || null);
136+
Pattern.create = function (relPath, data, customProps, patternlab) {
137+
var newPattern = new Pattern(relPath || '', data || null, patternlab);
124138
return extend(newPattern, customProps);
125139
};
126140

core/lib/pattern_assembler.js

Lines changed: 3 additions & 3 deletions
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.patternLink;
9898

9999
//only push to array if the array doesn't contain this pattern
100100
var isNew = true;
@@ -213,7 +213,7 @@ var pattern_assembler = function () {
213213
if (proposedDirectoryStats.isDirectory()) {
214214
var subTypeMarkdownFileContents = fs.readFileSync(proposedDirectory + '.md', 'utf8');
215215
var subTypeMarkdown = markdown_parser.parse(subTypeMarkdownFileContents);
216-
var subTypePattern = new Pattern(relPath);
216+
var subTypePattern = new Pattern(relPath, null, patternlab);
217217
subTypePattern.patternSectionSubtype = true;
218218
subTypePattern.patternLink = subTypePattern.name + '/index.html';
219219
subTypePattern.patternDesc = subTypeMarkdown.markdown;
@@ -244,7 +244,7 @@ var pattern_assembler = function () {
244244
if (!patternEngines.isPatternFile(filename, patternlab)) { return null; }
245245

246246
//make a new Pattern Object
247-
var currentPattern = new Pattern(relPath);
247+
var currentPattern = new Pattern(relPath, null, patternlab);
248248

249249
//if file is named in the syntax for variants
250250
if (patternEngines.isPseudoPatternJSON(filename)) {

core/lib/patternlab.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/*
2-
* patternlab-node - v2.4.2 - 2016
2+
* patternlab-node - v2.4.3 - 2016
33
*
44
* Brian Muenzenmeyer, Geoff Pursell, and the web community.
5-
* Licensed under the MIT license.
6-
*
7-
* Many thanks to Brad Frost and Dave Olsen for inspiration, encouragement, and advice.
5+
* Licensed under the MIT license.
6+
*
7+
* Many thanks to Brad Frost and Dave Olsen for inspiration, encouragement, and advice.
88
*
99
*/
1010

@@ -60,10 +60,10 @@ function processAllPatternsRecursive(pattern_assembler, patterns_dir, patternlab
6060
function checkConfiguration(patternlab) {
6161
//default the output suffixes if not present
6262
var outputFileSuffixes = {
63-
rendered: '',
63+
rendered: '.rendered',
6464
rawTemplate: '',
6565
markupOnly: '.markup-only'
66-
}
66+
};
6767

6868
if (!patternlab.config.outputFileSuffixes) {
6969
plutils.logOrange('Configuration Object "outputFileSuffixes" not found, and defaulted to the following:');
@@ -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
});

core/lib/ui_builder.js

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ var ui_builder = function () {
6969
*/
7070
function writeFile(filePath, data, callback) {
7171
if (callback) {
72-
fs.outputFile(filePath, data, callback);
72+
fs.outputFileSync(filePath, data, callback);
7373
} else {
74-
fs.outputFile(filePath, data);
74+
fs.outputFileSync(filePath, data);
7575
}
7676
}
7777

@@ -82,7 +82,6 @@ var ui_builder = function () {
8282
* @returns boolean - whether or not the pattern is excluded
8383
*/
8484
function isPatternExcluded(pattern, patternlab) {
85-
var styleGuideExcludes = patternlab.config.styleGuideExcludes;
8685
var isOmitted;
8786

8887
// skip underscore-prefixed files
@@ -103,16 +102,6 @@ var ui_builder = function () {
103102
return true;
104103
}
105104

106-
//this pattern is a member of any excluded pattern groups
107-
isOmitted = styleGuideExcludes && styleGuideExcludes.length && _.some(styleGuideExcludes, function (exclude) {
108-
return exclude === pattern.patternGroup; });
109-
if (isOmitted) {
110-
if (patternlab.config.debug) {
111-
console.log('Omitting ' + pattern.patternPartial + ' from styleguide patterns its patternGroup is specified in styleguideExcludes.');
112-
}
113-
return true;
114-
}
115-
116105
//this pattern is contained with a directory prefixed with an underscore (a handy way to hide whole directories from the nav
117106
isOmitted = pattern.relPath.charAt(0) === '_' || pattern.relPath.indexOf('/_') > -1;
118107
if (isOmitted) {
@@ -154,7 +143,8 @@ var ui_builder = function () {
154143
engine: null,
155144
flatPatternPath: pattern.flatPatternPath,
156145
isDocPattern: true
157-
}
146+
},
147+
patternlab
158148
);
159149
return docPattern;
160150
}
@@ -463,6 +453,7 @@ var ui_builder = function () {
463453

464454
var p;
465455
var typePatterns = [];
456+
var styleGuideExcludes = patternlab.config.styleGuideExcludes;
466457

467458
_.forOwn(patternTypeObj, function (patternSubtypes, patternSubtype) {
468459

@@ -492,7 +483,6 @@ var ui_builder = function () {
492483
return true; //stop yelling at us eslint we know we know
493484
});
494485

495-
496486
//do not create a viewall page for flat patterns
497487
if (!writeViewAllFile || !p) {
498488
return false;
@@ -509,7 +499,19 @@ var ui_builder = function () {
509499
var viewAllHTML = buildViewAllHTML(patternlab, typePatterns, patternType);
510500
writeFile(paths.public.patterns + p.subdir + '/index.html', mainPageHeadHtml + viewAllHTML + footerHTML);
511501

512-
patterns = patterns.concat(typePatterns);
502+
//determine if we should omit this patterntype completely from the viewall page
503+
var omitPatternType = styleGuideExcludes && styleGuideExcludes.length
504+
&& _.some(styleGuideExcludes, function (exclude) {
505+
return exclude === patternType;
506+
});
507+
if (omitPatternType) {
508+
if (patternlab.config.debug) {
509+
console.log('Omitting ' + patternType + ' from building a viewall page because its patternGroup is specified in styleguideExcludes.');
510+
}
511+
} else {
512+
patterns = patterns.concat(typePatterns);
513+
}
514+
513515
return true; //stop yelling at us eslint we know we know
514516
});
515517
return patterns;

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.2",
4+
"version": "2.4.3",
55
"main": "./core/lib/patternlab.js",
66
"dependencies": {
77
"diveSync": "^0.3.0",

patternlab-config.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,10 @@
5454
},
5555
"patternExportPatternPartials": [],
5656
"patternExportDirectory": "./pattern_exports/",
57-
"cacheBust": true
57+
"cacheBust": true,
58+
"outputFileSuffixes": {
59+
"rendered": ".rendered",
60+
"rawTemplate": "",
61+
"markupOnly": ".markup-only"
62+
}
5863
}

0 commit comments

Comments
 (0)