Skip to content

Commit e61b6f0

Browse files
author
Brian Muenzenmeyer
committed
Merge pull request #96 from pattern-lab/dev
Merging changes for patternlab 0.8.0
2 parents 8494969 + 727cb79 commit e61b6f0

File tree

96 files changed

+382
-7553
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+382
-7553
lines changed

CHANGELOG

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
11
THIS CHANGELOG IS AN ATTEMPT TO DOCUMENT CHANGES TO THIS PROJECT.
22

3+
PL-node-v0.8.0
4+
- CHG: note the change in versioning to proper semver. wanted to do ths to inch closer to a 1.0.0 release
5+
- DEL: deleted most of the lingering PHP sync listener code
6+
- FIX: support for displaying the HTML and Mustache in the code viewer
7+
- ADD: pattern link support
8+
- CHG: updated included mustache templates to reflect pattern links in navigation and compiling pages direct from templates
9+
- THX: @getsetbro for finding and fixing a typo
10+
- FIX: fixed a bug preventing pattern states from displaying on the flat template/pages
11+
- ADD: support for basic pseudo-patterns
12+
13+
PL-node-v0.1.7
14+
- ADD: pattern export
15+
- CHG: updated devDependencies
16+
- FIX: fixed a type in the README and config
17+
- THX: thanks @seanhussey for the pull request!
18+
319
PL-node-v0.1.6
420
- ADD: media queries found in css added to ish controls
521
- ADD: basic lineage support

Gruntfile.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ module.exports = function(grunt) {
3131
patternlab_grunt: {
3232
src: './builder/patternlab_grunt.js',
3333
dest: './builder/patternlab_grunt.js'
34+
},
35+
pattern_exporter: {
36+
src: './builder/pattern_exporter.js',
37+
dest: './builder/pattern_exporter.js'
3438
}
3539
},
3640
copy: {
@@ -59,6 +63,9 @@ module.exports = function(grunt) {
5963
},
6064
watch: {
6165
// scss: { //scss can be watched if you like
66+
// options: {
67+
// livereload: true
68+
// },
6269
// files: ['source/css/**/*.scss', 'public/styleguide/css/*.scss'],
6370
// tasks: ['default']
6471
// },
@@ -83,7 +90,8 @@ module.exports = function(grunt) {
8390
files: {
8491
'./source/css/style.css': './source/css/style.scss',
8592
'./public/styleguide/css/static.css': './public/styleguide/css/static.scss',
86-
'./public/styleguide/css/styleguide.css': './public/styleguide/css/styleguide.scss'
93+
'./public/styleguide/css/styleguide.css': './public/styleguide/css/styleguide.scss',
94+
'./public/styleguide/css/styleguide-specific.css': './public/styleguide/css/styleguide-specific.scss'
8795
}
8896
}
8997
},

README.md

Lines changed: 81 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ The Node version of Pattern Lab is, at its core, a static site generator. It com
66

77
### Getting Started
88

9-
To run patternlab-node, just do the following from the command line at the root of patternlab-node:
9+
To run patternlab-node, run the following from the command line at the root of whichever directory you want to initialize your project in:
1010

1111
1. `npm install`
1212
2. `npm install -g grunt-cli`
@@ -46,7 +46,7 @@ The current selection is as follows. It reflects support versus patternlab-php.
4646
"m": true,
4747
"l": true,
4848
"full": true,
49-
"ranndom": true,
49+
"random": true,
5050
"disco": true,
5151
"hay": true,
5252
"mqs": false,
@@ -62,10 +62,6 @@ The current selection is as follows. It reflects support versus patternlab-php.
6262
"tools-docs": true
6363
}
6464
```
65-
66-
##### Verbose Mode
67-
`patternlab.json` is a file created for debugging purposes. Set `debug` to true in `.config.json` to see all the secrets.
68-
6965
##### Pattern States
7066
You can set the state of a pattern by including it in `config.json` too. The out of the box styles are in progress (orange), in review (yellow), and complete (green).
7167
Pattern states should be lowercase and use hyphens where spaces are present.
@@ -77,6 +73,85 @@ Pattern states should be lowercase and use hyphens where spaces are present.
7773
}
7874
```
7975

76+
##### Pseudo-Patterns
77+
Pseudo-patterns are meant to give developers the ability to build multiple and unique **rendered** patterns off of one base pattern and its mark-up while giving them control over the data that is injected into the base pattern. This feature is especially useful when developing template- and page-style patterns.
78+
79+
Pseudo-patterns are, essentially, the pattern-specific JSON files that would accompany a pattern. Rather than require a Mustache pattern, though, pseudo-patterns are hinted so a developer can reference a shared pattern. The basic syntax:
80+
81+
`patternName~pseudoPatternName.json`
82+
83+
The tilde, `~`, and JSON extension denotes that this is a pseudo-pattern. `patternName` is the parent pattern that will be used when rendering the pseudo-pattern. `patternName` and `pseudoPatternName` are combined when adding the pseudo-pattern to the navigation.
84+
85+
The JSON file itself works exactly like the [pattern-specific JSON file](http://patternlab.io/docs/data-pattern-specific.html). It has the added benefit that the pseudo-pattern will also import any values from the parent pattern's pattern-specific JSON file. Here is an example (which ships with the package) where we want to show an emergency notification on our homepage template. Our `03-templates/` directory looks like this:
86+
87+
```
88+
00-homepage.mustache
89+
01-blog.mustache
90+
02-article.mustache
91+
```
92+
93+
Our `00-homepage.mustache` template might look like this:
94+
95+
```
96+
<div id="main-container">
97+
{{# emergency }}
98+
<div class="emergency">Oh Noes! Emergency!</div>
99+
{{/ emergency }}
100+
{ ...a bunch of other content... }
101+
</div>
102+
```
103+
104+
If our `_data.json` file doesn't give a value for `emergency` that section will never show up when `00-homepage.mustache` is rendered.
105+
106+
We want to show both the regular and emergency states of the homepage but we don't want to duplicate the entire `00-homepage.mustache` template. That would be a maintenance nightmare. So let's add our pseudo-pattern:
107+
108+
```
109+
00-homepage.mustache
110+
00-homepage~emergency.json
111+
01-blog.mustache
112+
02-article.mustache
113+
```
114+
115+
In our pseudo-pattern, `00-homepage~emergency.json`, we add our `emergency` attribute:
116+
117+
```
118+
{
119+
"emergency": true
120+
}
121+
```
122+
123+
Now when we generate our site we'll have our homepage template rendered twice. Once as the regular template and once as a pseudo-pattern showing the emergency section. Note that the pseudo-pattern will show up in our navigation as `Homepage Emergency`.
124+
125+
##### Pattern Linking
126+
You can build patterns that link to one another to help simulate using a real website. This is especially useful when working with the Pages and Templates pattern types. The basic format is:
127+
128+
`{{ link.pattern-name }}`
129+
130+
For example, if you wanted to add a link to the `home page` template from your `blog` template you could write the following:
131+
132+
`<a href="{{ link.templates-homepage }}">Home</a>`
133+
134+
This would compile to:
135+
136+
`<a href="/patterns/templates-homepage/templates-homepage.html">Home</a>`
137+
138+
As you can see, it's a much easier way of linking patterns to one another.
139+
140+
141+
##### Pattern Export
142+
`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.
143+
144+
```
145+
"patternExportKeys": ["molecules-primary-nav", "organisms-header", "organisms-header"],
146+
"patternExportDirectory": "./pattern_exports/"
147+
```
148+
149+
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.
150+
151+
152+
##### Verbose Mode
153+
`patternlab.json` is a file created for debugging purposes. Set `debug` to true in `.config.json` to see all the secrets.
154+
80155
##### Server
81156
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.
82157

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.1.6 - 2014
2+
* patternlab-node - v0.8.0 - 2015
33
*
44
* Brian Muenzenmeyer, and the web community.
55
* Licensed under the MIT license.

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.1.6 - 2014
2+
* patternlab-node - v0.8.0 - 2015
33
*
44
* Brian Muenzenmeyer, and the web community.
55
* Licensed under the MIT license.

builder/object_factory.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* patternlab-node - v0.1.6 - 2014
2+
* patternlab-node - v0.8.0 - 2015
33
*
44
* Brian Muenzenmeyer, and the web community.
55
* Licensed under the MIT license.
@@ -11,18 +11,19 @@
1111
(function () {
1212
"use strict";
1313

14-
var oPattern = function(name, subdir, filename, data){
15-
this.name = name; //this is the unique name with the subDir
14+
var oPattern = function(subdir, filename, data){
15+
this.fileName = filename.substring(0, filename.indexOf('.'));
1616
this.subdir = subdir;
17-
this.filename = filename;
18-
this.data = data;
19-
this.template = '';
20-
this.patternPartial = '';
21-
this.patternName = ''; //this is the display name for the ui
22-
this.patternLink = '';
23-
this.patternGroup = name.substring(name.indexOf('-') + 1, name.indexOf('-', 4) + 1 - name.indexOf('-') + 1);
17+
this.name = (subdir.replace(/[\/\\]/g, '-') + '-' + this.fileName).replace(/\\/g, '-'); //this is the unique name with the subDir
18+
this.data = data || null;
19+
this.patternName = this.fileName.substring(this.fileName.indexOf('-') + 1); //this is the display name for the ui
20+
this.patternLink = this.name + '/' + this.name + '.html';
21+
this.patternGroup = this.name.substring(this.name.indexOf('-') + 1, this.name.indexOf('-', 4) + 1 - this.name.indexOf('-') + 1);
2422
this.patternSubGroup = subdir.substring(subdir.indexOf('/') + 4);
2523
this.flatPatternPath = subdir.replace(/\//g, '-');
24+
this.key = this.patternGroup + '-' + this.patternName;
25+
this.template = '';
26+
this.patternPartial = '';
2627
this.lineage = [];
2728
this.lineageIndex = [];
2829
this.lineageR = [];

builder/pattern_assembler.js

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,35 @@
11
(function () {
2-
"use strict";
3-
2+
"use strict";
3+
4+
var fs = require('fs-extra'),
5+
path = require('path');
6+
7+
var pattern_assembler = function(){
8+
9+
function setState(pattern, patternlab){
10+
if(patternlab.config.patternStates[pattern.patternName]){
11+
pattern.patternState = patternlab.config.patternStates[pattern.patternName];
12+
} else{
13+
pattern.patternState = "";
14+
}
15+
}
16+
17+
function addPattern(pattern, patternLab){
18+
patternLab.data.link[pattern.patternGroup + '-' + pattern.patternName] = '/patterns/' + pattern.patternLink;
19+
patternLab.patterns.push(pattern);
20+
}
21+
22+
return {
23+
setPatternState: function(pattern, patternlab){
24+
setState(pattern, patternlab);
25+
},
26+
addPattern: function(pattern, patternLab){
27+
addPattern(pattern, patternLab);
28+
}
29+
};
30+
31+
};
32+
33+
module.exports = pattern_assembler;
434

535
}());

builder/pattern_exporter.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* patternlab-node - v0.8.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 fs = require('fs-extra'),
15+
path = require('path');
16+
17+
var pattern_exporter = function(){
18+
19+
function exportPatterns(patternlab){
20+
21+
//read the config export options
22+
var exportKeys = patternlab.config.patternExportKeys;
23+
24+
//find the chosen patterns to export
25+
for (var i = 0; i < exportKeys.length; i++){
26+
for (var j = 0; j < patternlab.patterns.length; j++){
27+
if(exportKeys[i] === patternlab.patterns[j].key){
28+
//write matches to the desired location
29+
fs.outputFileSync(patternlab.config.patternExportDirectory + patternlab.patterns[j].key + '.html', patternlab.patterns[j].patternPartial);
30+
}
31+
}
32+
}
33+
34+
35+
36+
}
37+
38+
return {
39+
export_patterns: function(patternlab){
40+
exportPatterns(patternlab);
41+
}
42+
};
43+
44+
};
45+
46+
module.exports = pattern_exporter;
47+
48+
}());

0 commit comments

Comments
 (0)