Skip to content

Commit 7a0b0d9

Browse files
author
Brian Muenzenmeyer
committed
Merge pull request #140 from pattern-lab/dev
Dev to Master
2 parents bdd5973 + 31b4dfc commit 7a0b0d9

18 files changed

+533
-146
lines changed

CHANGELOG

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
THIS CHANGELOG IS AN ATTEMPT TO DOCUMENT CHANGES TO THIS PROJECT.
2+
3+
PL-node-v0.11.0
4+
- ADD: Ignore pattern directories that start with an underscore.
5+
- ADD: Support for lists with the listItems variable
6+
- FIX: Resolved issue where pattern parameter data bled into global data object
7+
- ADD: Support a fluid viewport
8+
29
PL-node-v0.10.1
310
- ADD: Added more unit tests for recently more-modular code
411
- FIX: Lineage was not working for patterns with pattern parameters

Gruntfile.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ module.exports = function(grunt) {
4747
pseudopattern_hunter: {
4848
src: './builder/pseudopattern_hunter.js',
4949
dest: './builder/pseudopattern_hunter.js'
50+
},
51+
list_item_hunter: {
52+
src: './builder/list_item_hunter.js',
53+
dest: './builder/list_item_hunter.js'
5054
}
5155
},
5256
copy: {

README.md

Lines changed: 38 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,40 @@ Pattern states should be lowercase and use hyphens where spaces are present.
7373
}
7474
```
7575

76+
##### Pattern Export
77+
`config.json` also has two properties that work together to export completed patterns for use in a production environment. Provide an array of keys and an output directory. Pattern Lab doesn't ship with any pattern export keys, but the default directory is `"./pattern_exports/"` created inside the install directory.
78+
79+
```
80+
"patternExportKeys": ["molecules-primary-nav", "organisms-header", "organisms-header"],
81+
"patternExportDirectory": "./pattern_exports/"
82+
```
83+
84+
Coupled with exported css (much easier to extract with existing tools like [grunt-contrib-copy](https://github.com/gruntjs/grunt-contrib-copy)), pattern export can help to maintain the relevancy of the design system by directly placing partials in a directory of your choosing.
85+
86+
##### baseurl
87+
88+
If your instance of Pattern Lab lives in a subdirectory of your server, for instance on github pages (ex: yourusername.github.io/patterns-demo/), then add the baseurl here. The baseurl is everything after the hostname - ie: `patterns-demo`
89+
90+
```
91+
"baseurl" : "/patterns-demo"
92+
```
93+
94+
Default: blank
95+
96+
##### excluding patterns
97+
98+
If you'd like to exclude an individual pattern you can do so by prepending the filename with an underscore, like: `_filename.mustache`
99+
100+
You can also exclude complete directories by prepending the directory name with an underscore, like: `/_experiment/...`
101+
102+
##### Verbose Mode
103+
`patternlab.json` is a file created for debugging purposes. Set `debug` to true in `.config.json` to see all the secrets.
104+
105+
##### Server
106+
Running `grunt serve` will compile the patternlab front end and host it on <a href="http://localhost:9001">http://localhost:9001</a> by default. Page will reload on any saved source code change.
107+
108+
### Advanced Pattern Library Features
109+
76110
##### Pattern Parameters
77111
Pattern parameters are a simple mechanism for replacing Mustache variables via attributes on a pattern partial tag rather than having to use a pattern-specific json file. They are especially useful when you want to supply distinct values for Mustache variables in a specific pattern partial instance that may be included multiple times in a molecule, template, or page.
78112

@@ -157,32 +191,6 @@ This would compile to:
157191
As you can see, it's a much easier way of linking patterns to one another.
158192

159193

160-
##### Pattern Export
161-
`config.json` also has two properties that work together to export completed patterns for use in a production environment. Provide an array of keys and an output directory. Pattern Lab doesn't ship with any pattern export keys, but the default directory is `"./pattern_exports/"` created inside the install directory.
162-
163-
```
164-
"patternExportKeys": ["molecules-primary-nav", "organisms-header", "organisms-header"],
165-
"patternExportDirectory": "./pattern_exports/"
166-
```
167-
168-
Coupled with exported css (much easier to extract with existing tools like [grunt-contrib-copy](https://github.com/gruntjs/grunt-contrib-copy)), pattern export can help to maintain the relevancy of the design system by directly placing partials in a directory of your choosing.
169-
170-
##### baseurl
171-
172-
If your instance of Pattern Lab lives in a subdirectory of your server, for instance on github pages (ex: yourusername.github.io/patterns-demo/), then add the baseurl here. The baseurl is everything after the hostname - ie: `patterns-demo`
173-
174-
```
175-
"baseurl" : "/patterns-demo"
176-
```
177-
178-
Default: blank
179-
180-
##### Verbose Mode
181-
`patternlab.json` is a file created for debugging purposes. Set `debug` to true in `.config.json` to see all the secrets.
182-
183-
##### Server
184-
Running `grunt serve` will compile the patternlab front end and host it on <a href="http://localhost:9001">http://localhost:9001</a> by default. Page will reload on any saved source code change.
185-
186194
===
187195

188196
The Node version of Pattern Lab is maintained by [@bmuenzenmeyer](https://twitter.com/bmuenzenmeyer) and contributors. Pull requests welcome, but please take a moment to read the [guidelines](https://github.com/pattern-lab/patternlab-node/blob/master/CONTRIBUTING.md).
@@ -191,9 +199,11 @@ The Node version of Pattern Lab is maintained by [@bmuenzenmeyer](https://twitte
191199

192200
You can find some simple upgrade documenation in it's current home here (unreleased but confirmed to work): [https://github.com/pattern-lab/website/blob/dev/patternlabsite/docs/node/upgrading.md](https://github.com/pattern-lab/website/blob/dev/patternlabsite/docs/node/upgrading.md)
193201

194-
### Forward, To the Specification!
202+
### ROADMAP
203+
204+
A roadmap exists for Pattern Lab Node. Check it out [here](https://github.com/pattern-lab/patternlab-node/issues/134)
195205

196-
Dave Olsen has published the [specification](https://github.com/pattern-lab/the-spec/blob/draft/SPEC.md) for Pattern Lab ports. Development will be oriented toward compliance with this as the spec and the port mature together.
206+
Dave Olsen has also published the [specification](https://github.com/pattern-lab/the-spec/blob/draft/SPEC.md) for Pattern Lab ports. Development will be oriented toward compliance with this as the spec and the port mature together.
197207

198208
### Is Pattern Lab a Platform or a Build Tool?
199209

builder/lineage_hunter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* patternlab-node - v0.10.1 - 2015
2+
* patternlab-node - v0.11.0 - 2015
33
*
44
* Brian Muenzenmeyer, and the web community.
55
* Licensed under the MIT license.

builder/list_item_hunter.js

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/*
2+
* patternlab-node - v0.11.0 - 2015
3+
*
4+
* Brian Muenzenmeyer, 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.
8+
*
9+
*/
10+
11+
(function () {
12+
"use strict";
13+
14+
var list_item_hunter = function(){
15+
16+
var extend = require('util')._extend,
17+
pa = require('./pattern_assembler'),
18+
mustache = require('mustache'),
19+
pattern_assembler = new pa(),
20+
items = [ 'zero','one','two','three','four','five','six','seven','eight','nine','ten','eleven','twelve','thirteen','fourteen','fifteen','sixteen','seventeen','eighteen','nineteen','twenty'];
21+
22+
function processListItemPartials(pattern, patternlab){
23+
//find any listitem blocks
24+
var matches = pattern_assembler.find_list_items(pattern, patternlab);
25+
if(matches !== null){
26+
matches.forEach(function(liMatch, index, matches){
27+
28+
if(patternlab.config.debug){
29+
console.log('found listItem of size ' + liMatch + ' inside ' + pattern.key);
30+
}
31+
32+
//find the boundaries of the block
33+
var loopNumberString = liMatch.split('.')[1].split('}')[0].trim();
34+
var end = liMatch.replace('#', '/');
35+
var patternBlock = pattern.template.substring(pattern.template.indexOf(liMatch) + liMatch.length, pattern.template.indexOf(end)).trim();
36+
37+
//build arrays that repeat the block, however large we need to
38+
var repeatedBlockTemplate = [];
39+
var repeatedBlockHtml = '';
40+
for(var i = 0; i < items.indexOf(loopNumberString); i++){
41+
repeatedBlockTemplate.push(patternBlock);
42+
}
43+
44+
//check for a local listitems.json file
45+
var listData = JSON.parse(JSON.stringify(patternlab.listitems));
46+
listData = pattern_assembler.merge_data(listData, pattern.patternSpecificListJson);
47+
48+
//iterate over each copied block, rendering its contents along with pattenlab.listitems[i]
49+
for(var i = 0; i < repeatedBlockTemplate.length; i++){
50+
51+
var thisBlockTemplate = repeatedBlockTemplate[i];
52+
var thisBlockHTML = "";
53+
54+
//combine listItem data with pattern data with global data
55+
var itemData = listData['' + items.indexOf(loopNumberString)]; //this is a property like "2"
56+
var globalData = JSON.parse(JSON.stringify(patternlab.data));
57+
var localData = JSON.parse(JSON.stringify(pattern.jsonFileData));
58+
59+
var allData = pattern_assembler.merge_data(globalData, localData);
60+
allData = pattern_assembler.merge_data(allData, itemData[i]);
61+
allData.link = extend({}, patternlab.data.link);
62+
63+
//check for partials within the repeated block
64+
var foundPartials = pattern_assembler.find_pattern_partials({ 'template' : thisBlockTemplate });
65+
66+
if(foundPartials && foundPartials.length > 0){
67+
68+
for(var j = 0; j < foundPartials.length; j++){
69+
70+
//get the partial
71+
var partialName = foundPartials[j].match(/([a-z-]+)/ig)[0];
72+
var partialPattern = pattern_assembler.get_pattern_by_key(partialName, patternlab);
73+
74+
//replace its reference within the block with the extended template
75+
thisBlockTemplate = thisBlockTemplate.replace(foundPartials[j], partialPattern.extendedTemplate);
76+
}
77+
78+
//render with data
79+
thisBlockHTML = pattern_assembler.renderPattern(thisBlockTemplate, allData, patternlab.partials);
80+
81+
} else{
82+
//just render with mergedData
83+
thisBlockHTML = pattern_assembler.renderPattern(thisBlockTemplate, allData, patternlab.partials);
84+
}
85+
86+
//add the rendered HTML to our string
87+
repeatedBlockHtml = repeatedBlockHtml + thisBlockHTML;
88+
}
89+
90+
//replace the block with our generated HTML
91+
var repeatingBlock = pattern.extendedTemplate.substring(pattern.extendedTemplate.indexOf(liMatch), pattern.extendedTemplate.indexOf(end) + end.length);
92+
pattern.extendedTemplate = pattern.extendedTemplate.replace(repeatingBlock, repeatedBlockHtml);
93+
94+
});
95+
}
96+
}
97+
98+
return {
99+
process_list_item_partials: function(pattern, patternlab){
100+
processListItemPartials(pattern, patternlab);
101+
}
102+
};
103+
104+
};
105+
106+
module.exports = list_item_hunter;
107+
108+
}());

builder/media_hunter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* patternlab-node - v0.10.1 - 2015
2+
* patternlab-node - v0.11.0 - 2015
33
*
44
* Brian Muenzenmeyer, and the web community.
55
* Licensed under the MIT license.

builder/object_factory.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* patternlab-node - v0.10.1 - 2015
2+
* patternlab-node - v0.11.0 - 2015
33
*
44
* Brian Muenzenmeyer, and the web community.
55
* Licensed under the MIT license.
@@ -15,8 +15,7 @@
1515
this.fileName = filename.substring(0, filename.indexOf('.'));
1616
this.subdir = subdir;
1717
this.name = subdir.replace(/[\/\\]/g, '-') + '-' + this.fileName; //this is the unique name with the subDir
18-
this.data = data || null;
19-
this.jsonFileData = {};
18+
this.jsonFileData = data || {};
2019
this.patternName = this.fileName.substring(this.fileName.indexOf('-') + 1); //this is the display name for the ui
2120
this.patternLink = this.name + '/' + this.name + '.html';
2221
this.patternGroup = this.name.substring(this.name.indexOf('-') + 1, this.name.indexOf('-', 4) + 1 - this.name.indexOf('-') + 1);

builder/parameter_hunter.js

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* patternlab-node - v0.10.1 - 2015
2+
* patternlab-node - v0.11.0 - 2015
33
*
44
* Brian Muenzenmeyer, and the web community.
55
* Licensed under the MIT license.
@@ -23,9 +23,10 @@
2323
//find the {{> template-name(*) }} within patterns
2424
var matches = pattern.template.match(/{{>([ ]+)?([A-Za-z0-9-]+)(\()(.+)(\))([ ]+)?}}/g);
2525
if(matches !== null){
26+
//compile this partial immeadiately, essentially consuming it.
2627
matches.forEach(function(pMatch, index, matches){
2728
//find the partial's name
28-
var partialName = pMatch.match(/([a-z-]+)/ig)[0]
29+
var partialName = pMatch.match(/([a-z-]+)/ig)[0];
2930

3031
if(patternlab.config.debug){
3132
console.log('found patternParameters for ' + partialName);
@@ -39,20 +40,17 @@
3940
//do no evil. there is no good way to do this that I can think of without using a split, which then makes commas and colons special characters and unusable within the pattern params
4041
var paramData = eval(paramString);
4142

42-
//compile this partial immeadiately, essentially consuming it.
4343
var partialPattern = pattern_assembler.get_pattern_by_key(partialName, patternlab);
44-
var existingData = pattern.data || patternlab.data;
44+
var globalData = JSON.parse(JSON.stringify(patternlab.data));
45+
var localData = JSON.parse(JSON.stringify(pattern.jsonFileData));
4546

46-
//merge paramData with any other data that exists.
47-
for (var prop in paramData) {
48-
if (existingData.hasOwnProperty(prop)) {
49-
existingData[prop] = paramData[prop];
50-
}
51-
}
47+
var allData = pattern_assembler.merge_data(globalData, localData);
48+
allData = pattern_assembler.merge_data(allData, paramData);
5249

5350
//extend pattern data links into link for pattern link shortcuts to work. we do this locally and globally
54-
existingData.link = extend({}, patternlab.data.link);
55-
var renderedPartial = pattern_assembler.renderPattern(partialPattern.extendedTemplate, existingData, patternlab.partials);
51+
allData.link = extend({}, patternlab.data.link);
52+
53+
var renderedPartial = pattern_assembler.renderPattern(partialPattern.extendedTemplate, allData, patternlab.partials);
5654

5755
//remove the parameter from the partial and replace it with the rendered partial + paramData
5856
pattern.extendedTemplate = pattern.extendedTemplate.replace(pMatch, renderedPartial);

0 commit comments

Comments
 (0)