Skip to content

Commit

Permalink
Merge pull request #443 from pattern-lab/dev
Browse files Browse the repository at this point in the history
Pattern Lab Node Core 2.4.3
  • Loading branch information
bmuenzenmeyer authored Aug 20, 2016
2 parents 4c3d644 + 84db306 commit 3739152
Show file tree
Hide file tree
Showing 10 changed files with 232 additions and 143 deletions.
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@ before_install:

before_script:
- npm install -g grunt-cli
- npm install patternengine-node-underscore
- npm install patternengine-node-handlebars
- npm install patternengine-node-twig

branches:
only:
- master
- dev
- issue/438-runAllTestsTravis

notifications:
webhooks:
Expand Down
32 changes: 23 additions & 9 deletions core/lib/object_factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var extend = require('util')._extend;

// Pattern properties

var Pattern = function (relPath, data) {
var Pattern = function (relPath, data, patternlab) {
// We expect relPath to be the path of the pattern template, relative to the
// root of the pattern tree. Parse out the path parts and save the useful ones.
var pathObj = path.parse(path.normalize(relPath));
Expand All @@ -29,10 +29,6 @@ var Pattern = function (relPath, data) {
return val.charAt(0).toUpperCase() + val.slice(1) + ' ' + working.charAt(0).toUpperCase() + working.slice(1);
}, '').trim(); //this is the display name for the ui. strip numeric + hyphen prefixes

// calculated path from the root of the public directory to the generated html
// file for this pattern
this.patternLink = this.name + path.sep + this.name + '.html'; // '00-atoms-00-global-00-colors/00-atoms-00-global-00-colors.html'

// the top-level pattern group this pattern belongs to. 'atoms'
this.patternGroup = this.subdir.split(path.sep)[0].replace(/^\d*-/, '');

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

// calculated path from the root of the public directory to the generated
// (rendered!) html file for this pattern, to be shown in the iframe
this.patternLink = patternlab ? this.getPatternLink(patternlab, 'rendered') : null;

// The canonical "key" by which this pattern is known. This is the callable
// name of the pattern. UPDATE: this.key is now known as this.patternPartial
this.patternPartial = this.patternGroup + '-' + this.patternBaseName;
Expand Down Expand Up @@ -84,6 +84,20 @@ Pattern.prototype = {
}
},

// calculated path from the root of the public directory to the generated html
// file for this pattern.
// Should look something like '00-atoms-00-global-00-colors/00-atoms-00-global-00-colors.html'
getPatternLink: function (patternlab, suffixType) {
// if no suffixType is provided, we default to rendered
var suffixConfig = patternlab.config.outputFileSuffixes;
var suffix = suffixType ? suffixConfig[suffixType] : suffixConfig.rendered;

if (suffixType === 'rawTemplate') {
return this.name + path.sep + this.name + suffix + this.fileExtension;
}
return this.name + path.sep + this.name + suffix + '.html';
},

// the finders all delegate to the PatternEngine, which also encapsulates all
// appropriate regexes
findPartials: function () {
Expand Down Expand Up @@ -111,16 +125,16 @@ Pattern.prototype = {

// factory: creates an empty Pattern for miscellaneous internal use, such as
// by list_item_hunter
Pattern.createEmpty = function (customProps) {
var pattern = new Pattern('', null);
Pattern.createEmpty = function (customProps, patternlab) {
var pattern = new Pattern('', null, patternlab);
return extend(pattern, customProps);
};

// factory: creates an Pattern object on-demand from a hash; the hash accepts
// parameters that replace the positional parameters that the Pattern
// constructor takes.
Pattern.create = function (relPath, data, customProps) {
var newPattern = new Pattern(relPath || '', data || null);
Pattern.create = function (relPath, data, customProps, patternlab) {
var newPattern = new Pattern(relPath || '', data || null, patternlab);
return extend(newPattern, customProps);
};

Expand Down
6 changes: 3 additions & 3 deletions core/lib/pattern_assembler.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ var pattern_assembler = function () {
function addPattern(pattern, patternlab) {

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

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

//make a new Pattern Object
var currentPattern = new Pattern(relPath);
var currentPattern = new Pattern(relPath, null, patternlab);

//if file is named in the syntax for variants
if (patternEngines.isPseudoPatternJSON(filename)) {
Expand Down
18 changes: 9 additions & 9 deletions core/lib/patternlab.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/*
* patternlab-node - v2.4.2 - 2016
* patternlab-node - v2.4.3 - 2016
*
* Brian Muenzenmeyer, Geoff Pursell, and the web community.
* Licensed under the MIT license.
*
* Many thanks to Brad Frost and Dave Olsen for inspiration, encouragement, and advice.
* Licensed under the MIT license.
*
* Many thanks to Brad Frost and Dave Olsen for inspiration, encouragement, and advice.
*
*/

Expand Down Expand Up @@ -60,10 +60,10 @@ function processAllPatternsRecursive(pattern_assembler, patterns_dir, patternlab
function checkConfiguration(patternlab) {
//default the output suffixes if not present
var outputFileSuffixes = {
rendered: '',
rendered: '.rendered',
rawTemplate: '',
markupOnly: '.markup-only'
}
};

if (!patternlab.config.outputFileSuffixes) {
plutils.logOrange('Configuration Object "outputFileSuffixes" not found, and defaulted to the following:');
Expand Down Expand Up @@ -355,13 +355,13 @@ var patternlab_engine = function (config) {

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

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

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

return true;
});
Expand Down
34 changes: 18 additions & 16 deletions core/lib/ui_builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ var ui_builder = function () {
*/
function writeFile(filePath, data, callback) {
if (callback) {
fs.outputFile(filePath, data, callback);
fs.outputFileSync(filePath, data, callback);
} else {
fs.outputFile(filePath, data);
fs.outputFileSync(filePath, data);
}
}

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

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

//this pattern is a member of any excluded pattern groups
isOmitted = styleGuideExcludes && styleGuideExcludes.length && _.some(styleGuideExcludes, function (exclude) {
return exclude === pattern.patternGroup; });
if (isOmitted) {
if (patternlab.config.debug) {
console.log('Omitting ' + pattern.patternPartial + ' from styleguide patterns its patternGroup is specified in styleguideExcludes.');
}
return true;
}

//this pattern is contained with a directory prefixed with an underscore (a handy way to hide whole directories from the nav
isOmitted = pattern.relPath.charAt(0) === '_' || pattern.relPath.indexOf('/_') > -1;
if (isOmitted) {
Expand Down Expand Up @@ -154,7 +143,8 @@ var ui_builder = function () {
engine: null,
flatPatternPath: pattern.flatPatternPath,
isDocPattern: true
}
},
patternlab
);
return docPattern;
}
Expand Down Expand Up @@ -463,6 +453,7 @@ var ui_builder = function () {

var p;
var typePatterns = [];
var styleGuideExcludes = patternlab.config.styleGuideExcludes;

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

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


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

patterns = patterns.concat(typePatterns);
//determine if we should omit this patterntype completely from the viewall page
var omitPatternType = styleGuideExcludes && styleGuideExcludes.length
&& _.some(styleGuideExcludes, function (exclude) {
return exclude === patternType;
});
if (omitPatternType) {
if (patternlab.config.debug) {
console.log('Omitting ' + patternType + ' from building a viewall page because its patternGroup is specified in styleguideExcludes.');
}
} else {
patterns = patterns.concat(typePatterns);
}

return true; //stop yelling at us eslint we know we know
});
return patterns;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "patternlab-node",
"description": "Pattern Lab is a collection of tools to help you create atomic design systems. This is the node command line interface (CLI).",
"version": "2.4.2",
"version": "2.4.3",
"main": "./core/lib/patternlab.js",
"dependencies": {
"diveSync": "^0.3.0",
Expand Down
7 changes: 6 additions & 1 deletion patternlab-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,10 @@
},
"patternExportPatternPartials": [],
"patternExportDirectory": "./pattern_exports/",
"cacheBust": true
"cacheBust": true,
"outputFileSuffixes": {
"rendered": ".rendered",
"rawTemplate": "",
"markupOnly": ".markup-only"
}
}
Loading

0 comments on commit 3739152

Please sign in to comment.