Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ public/index.html
public/styleguide.html
public/styleguide/html/styleguide.html
public/css/*
public/data/*
public/fonts/*
public/js/*
public/images/*
Expand Down
15 changes: 15 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
THIS CHANGELOG IS AN ATTEMPT TO DOCUMENT CHANGES TO THIS PROJECT.

PL-node-v1.0.0
- FIX: Resolve issue with not hiding underscored patterns.
- THX: Thanks @ivancamilov for reporting this regression.
- FIX: Fix misapplied error input class
- THX: Thanks @johngerome for the pull request!
- ADD: Added a note in the README during installation to run with elevated privileges
- THX: Thanks @RichardBray for the heads up
- ADD: Added a Prerequisites section to the README
- ADD: Added unit tests for pattern states and pseudopatterns
- CHG: Changed pseudopattern generation to use config.patterns.source directory instead of hardcode
- CHG: Explicitly sorting patterns by name prior to building the UI
- ADD: Added ability to specify link.* urls inside data objects
- CHG: Incremented version to 1.0.0. Achieved near-parity with PL PHP 1!
- THX: Thanks to each and every person who cared about Pattern Lab Node! - Brian

PL-node-v0.15.1
- FIX: Resolve issue with styleModifiers not being replaced when the partial has spaces in it.
- ADD: Support multiple styleModifier classes using the | pipe syntax
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,20 @@ The Node version of [Pattern Lab](http://patternlab.io/) is, at its core, a stat

This repository contains the vanilla builder logic, grunt and gulp configurations, and some sample template/css/data to illustrate the power and flexibility of the tool.

### Prerequisites

Make sure Node and npm are installed. A great guide can be found here: [https://docs.npmjs.com/getting-started/installing-node](https://docs.npmjs.com/getting-started/installing-node)

### Download

* Download the [latest release of patternlab-node](https://github.com/pattern-lab/patternlab-node/releases/latest) from Github
* Via npm, run `npm install patternlab-node` (Note this will auto install the grunt version currently. see below)
* **NOTE** Node version 4.X and 5.X have tentative support, citing [a lot of Windows issues](https://github.com/nodejs/node-gyp/issues/629), including [mine](https://github.com/pattern-lab/patternlab-node/issues/162). Upgrade node at your own risk until otherwise stated. I've tried to catalog some issues and troubleshooting steps on the [wiki](https://github.com/pattern-lab/patternlab-node/wiki/Windows-Issues).

### Troubleshooting Installs

Make sure you are running your terminal/command line session as administrator. This could mean `sudo`, or opening the window with a right-click option.

### Choose Your Adventure! Now Vanilla, Grunt & Gulp

This repository ships with two `package.json` files, a `Gruntfile.js`, and a `gulpfile.js`. The default is grunt currently. The core builder is not dependent on either.
Expand Down
2 changes: 1 addition & 1 deletion builder/lineage_hunter.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* patternlab-node - v0.15.1 - 2015
* patternlab-node - v1.0.0 - 2015
*
* Brian Muenzenmeyer, and the web community.
* Licensed under the MIT license.
Expand Down
2 changes: 1 addition & 1 deletion builder/list_item_hunter.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* patternlab-node - v0.15.1 - 2015
* patternlab-node - v1.0.0 - 2015
*
* Brian Muenzenmeyer, and the web community.
* Licensed under the MIT license.
Expand Down
2 changes: 1 addition & 1 deletion builder/media_hunter.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* patternlab-node - v0.15.1 - 2015
* patternlab-node - v1.0.0 - 2015
*
* Brian Muenzenmeyer, and the web community.
* Licensed under the MIT license.
Expand Down
2 changes: 1 addition & 1 deletion builder/object_factory.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* patternlab-node - v0.15.1 - 2015
* patternlab-node - v1.0.0 - 2015
*
* Brian Muenzenmeyer, and the web community.
* Licensed under the MIT license.
Expand Down
12 changes: 6 additions & 6 deletions builder/parameter_hunter.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/*
* patternlab-node - v0.15.1 - 2015
*
/*
* patternlab-node - v1.0.0 - 2015
*
* Brian Muenzenmeyer, 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
60 changes: 45 additions & 15 deletions builder/pattern_assembler.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/*
* patternlab-node - v0.15.1 - 2015
*
/*
* patternlab-node - v1.0.0 - 2015
*
* Brian Muenzenmeyer, 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 @@ -46,14 +46,15 @@
}

function setState(pattern, patternlab){
if(patternlab.config.patternStates[pattern.patternName]){
if(patternlab.config.patternStates && patternlab.config.patternStates[pattern.patternName]){
pattern.patternState = patternlab.config.patternStates[pattern.patternName];
} else{
pattern.patternState = "";
}
}

function addPattern(pattern, patternlab){
//add the link to the global object
patternlab.data.link[pattern.patternGroup + '-' + pattern.patternName] = '/patterns/' + pattern.patternLink;

//only push to array if the array doesn't contain this pattern
Expand Down Expand Up @@ -94,21 +95,17 @@
var filename = path.basename(file);
var ext = path.extname(filename);

//ignore dotfiles and non-variant .json files
if(filename.charAt(0) === '.' || (ext === '.json' && filename.indexOf('~') === -1)){
//ignore dotfiles, underscored files, and non-variant .json files
if(filename.charAt(0) === '.' || filename.charAt(0) === '_' || (ext === '.json' && filename.indexOf('~') === -1)){
return;
}

//make a new Pattern Object
var currentPattern = new of.oPattern(file, subdir, filename);

//if file is named in the syntax for variants
//if file is named in the syntax for variants, no need to process further
//processPatternRecursive() will run find_pseudopatterns() and look at each pattern for a variant
if(ext === '.json' && filename.indexOf('~') > -1){
//add current pattern to patternlab object with minimal data
//processPatternRecursive() will run find_pseudopatterns() to fill out
//the object in the next diveSync
addPattern(currentPattern, patternlab);
//no need to process further
return;
}

Expand Down Expand Up @@ -321,6 +318,36 @@
return o;
}

//look for pattern links included in data files.
//these will be in the form of link.* WITHOUT {{}}, which would still be there from direct pattern inclusion
function parseDataLinks(patternlab){

//loop through all patterns
for (var i = 0; i < patternlab.patterns.length; i++){
var pattern = patternlab.patterns[i];
//look for link.* such as link.pages-blog as a value
var linkRE = /link.[A-z0-9-_]+/g;
//convert to string for easier searching
var dataObjAsString = JSON.stringify(pattern.jsonFileData);
var linkMatches = dataObjAsString.match(linkRE);

//if no matches found, escape current loop iteration
if(linkMatches === null) { continue; }

for(var i = 0; i < linkMatches.length; i++){
//for each match, find the expanded link within the already constructed patternlab.data.link object
var expandedLink = patternlab.data.link[linkMatches[i].split('.')[1]];
if(patternlab.config.debug){
console.log('expanded data link from ' + linkMatches[i] + ' to ' + expandedLink + ' inside ' + pattern.key);
}
//replace value with expandedLink on the pattern
dataObjAsString = dataObjAsString.replace(linkMatches[i], expandedLink);
}
//write back to data on the pattern
pattern.jsonFileData = JSON.parse(dataObjAsString);
}
}

return {
find_pattern_partials: function(pattern){
return findPartials(pattern);
Expand Down Expand Up @@ -360,6 +387,9 @@
},
is_object_empty: function(obj){
return isObjectEmpty(obj);
},
parse_data_links: function(patternlab){
parseDataLinks(patternlab);
}
};

Expand Down
2 changes: 1 addition & 1 deletion builder/pattern_exporter.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* patternlab-node - v0.15.1 - 2015
* patternlab-node - v1.0.0 - 2015
*
* Brian Muenzenmeyer, and the web community.
* Licensed under the MIT license.
Expand Down
19 changes: 18 additions & 1 deletion builder/patternlab.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* patternlab-node - v0.15.1 - 2015
* patternlab-node - v1.0.0 - 2015
*
* Brian Muenzenmeyer, and the web community.
* Licensed under the MIT license.
Expand Down Expand Up @@ -91,6 +91,10 @@ var patternlab_engine = function () {
pattern_assembler.process_pattern_iterative(file.substring(2), patternlab);
});

//now that all the main patterns are known, look for any links that might be within data and expand them
//we need to do this before expanding patterns & partials into extendedTemplates, otherwise we could lose the data -> partial reference
pattern_assembler.parse_data_links(patternlab);

//diveSync again to recursively include partials, filling out the
//extendedTemplate property of the patternlab.patterns elements
diveSync(patterns_dir, {
Expand Down Expand Up @@ -124,6 +128,7 @@ var patternlab_engine = function () {
var allData = JSON.parse(JSON.stringify(patternlab.data));
allData = pattern_assembler.merge_data(allData, pattern.jsonFileData);

//render the extendedTemplate with all data
pattern.patternPartial = pattern_assembler.renderPattern(pattern.extendedTemplate, allData);

//add footer info before writing
Expand Down Expand Up @@ -211,6 +216,18 @@ var patternlab_engine = function () {
//build the patternlab website
var patternlabSiteTemplate = fs.readFileSync('./source/_patternlab-files/index.mustache', 'utf8');

//sort all patterns explicitly.
patternlab.patterns = patternlab.patterns.sort(function(a,b){
if (a.name > b.name) {
return 1;
}
if (a.name < b.name) {
return -1;
}
// a must be equal to b
return 0;
});

//loop through all patterns.to build the navigation
//todo: refactor this someday
for(var i = 0; i < patternlab.patterns.length; i++){
Expand Down
2 changes: 1 addition & 1 deletion builder/patternlab_grunt.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* patternlab-node - v0.15.1 - 2015
* patternlab-node - v1.0.0 - 2015
*
* Brian Muenzenmeyer, and the web community.
* Licensed under the MIT license.
Expand Down
2 changes: 1 addition & 1 deletion builder/patternlab_gulp.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* patternlab-node - v0.15.1 - 2015
* patternlab-node - v1.0.0 - 2015
*
* Brian Muenzenmeyer, and the web community.
* Licensed under the MIT license.
Expand Down
10 changes: 5 additions & 5 deletions builder/pseudopattern_hunter.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* patternlab-node - v0.15.1 - 2015
* patternlab-node - v1.0.0 - 2015
*
* Brian Muenzenmeyer, and the web community.
* Licensed under the MIT license.
Expand Down Expand Up @@ -28,7 +28,7 @@
//look for a pseudo pattern by checking if there is a file containing same name, with ~ in it, ending in .json
var needle = currentPattern.subdir + '/' + currentPattern.fileName + '~*.json';
var pseudoPatterns = glob.sync(needle, {
cwd: 'source/_patterns/', //relative to gruntfile
cwd: patternlab.config.patterns.source + '/',
debug: false,
nodir: true,
});
Expand All @@ -41,14 +41,14 @@
console.log('found pseudoPattern variant of ' + currentPattern.key);
}

//we want to do everything we normally would here, except instead head the pseudoPattern data
var variantFileData = fs.readJSONSync('source/_patterns/' + pseudoPatterns[i]);
//we want to do everything we normally would here, except instead read the pseudoPattern data
var variantFileData = fs.readJSONSync(patternlab.config.patterns.source + '/' + pseudoPatterns[i]);

//extend any existing data with variant data
variantFileData = pattern_assembler.merge_data(currentPattern.jsonFileData, variantFileData);

var variantName = pseudoPatterns[i].substring(pseudoPatterns[i].indexOf('~') + 1).split('.')[0];
var variantFilePath = 'source/_patterns/' + currentPattern.subdir + '/' + currentPattern.fileName + '~' + variantName + '.json';
var variantFilePath = patternlab.config.patterns.source + '/' + currentPattern.subdir + '/' + currentPattern.fileName + '~' + variantName + '.json';
var variantFileName = currentPattern.fileName + '-' + variantName + '.';
var patternVariant = new of.oPattern(variantFilePath, currentPattern.subdir, variantFileName, variantFileData);

Expand Down
12 changes: 6 additions & 6 deletions builder/style_modifier_hunter.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/*
* patternlab-node - v0.15.1 - 2015
*
/*
* patternlab-node - v1.0.0 - 2015
*
* Brian Muenzenmeyer, 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
2 changes: 1 addition & 1 deletion package.gulp.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": "0.15.1",
"version": "1.0.0",
"devDependencies": {
"browser-sync": "^2.10.0",
"del": "^2.0.2",
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": "0.15.1",
"version": "1.0.0",
"devDependencies": {
"bs-html-injector": "^3.0.0",
"diveSync": "^0.3.0",
Expand Down
Loading