Skip to content

Commit f5219c9

Browse files
author
Brian Muenzenmeyer
committed
Merge pull request #132 from pattern-lab/dev
Dev to Master
2 parents 721ffe7 + 8175083 commit f5219c9

28 files changed

+554
-211
lines changed

.jslintrc

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"ass": false,
3+
"bitwise": false,
4+
"browser": false,
5+
"closure": false,
6+
"continue": false,
7+
"couch": false,
8+
"debug": false,
9+
"devel": true,
10+
"eqeq": false,
11+
"eval": true,
12+
"evil": false,
13+
"forin": false,
14+
"indent": 2,
15+
"maxerr": 50,
16+
"maxlen": false,
17+
"newcap": false,
18+
"node": true,
19+
"nomen": false,
20+
"passfail": false,
21+
"plusplus": false,
22+
"predef": [
23+
"node",
24+
"$",
25+
"require"
26+
],
27+
"regexp": false,
28+
"rhino": false,
29+
"sloppy": false,
30+
"stupid": false,
31+
"sub": false,
32+
"todo": false,
33+
"unparam": true,
34+
"vars": false,
35+
"white": true
36+
}

CHANGELOG

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11
THIS CHANGELOG IS AN ATTEMPT TO DOCUMENT CHANGES TO THIS PROJECT.
2+
PL-node-v0.10.0
3+
- ADD: Added support for pattern parameters! Resolves #88
4+
- FIX: Data inheritance is now working as advertised. Resolves #127. This turned out to be a MAJOR thing, as I realized the home-page was not passing down any of its json data to partials.
5+
- CHG: Refactored a lot of code out of patternlab.js and into separate files. Doing so should make everything dryer, more unit testable, and easier to understand I hope.
6+
- ADD: Added proper styling for the homepage-emergency alert that is displayed for demo purposes
7+
- ADD: Added a new comment organism, the sticky comment, to ship an example of pattern parameters
8+
- CHG: Start some JS linting of the project. I don't quite agree with a lot of it, so am trying to set some smart configurations
9+
- CHG: Wrapped some build messages in the patternlab.config.debug flag
10+
- FIX: Allow users to set a base url path. Resolves #125 ([)testing in the while requested)
211

312
PL-node-v0.9.1
413
- FIX: Fixed an issue with view all navigation not checking for index out of bounds cases
@@ -7,7 +16,7 @@ PL-node-v0.9.0
716
- FIX: Added grunt-contrib-copy args to copy all found source/css/*.css
817
- ADD: Added upgrade instructions to README
918
- FIX: Fix issue with styleguide accordions not closing upon click of a sibling menu.
10-
- THX: @getsetbro for reporting more issues :)
19+
- THX: @getsetbro for reporting more issues :)
1120
- ADD: Added support for pattern search. This is 'in beta' and should have more testing applied to it.
1221
- ADD: Added support for all keyboard shortcuts found in PL-PHP-v1.0.0
1322
- FIX: Fixed an issue where Hay mode and Disco mode did not stop one another when using keyboard shortcuts
@@ -63,7 +72,7 @@ PL-node-v0.1.3
6372

6473
PL-node-v0.1.2
6574
- ADD: Abstracted template rendering into a function for easier swapping of rendering engine
66-
- ADD: Smarter filtering of files to support other templates Thanks
75+
- ADD: Smarter filtering of files to support other templates Thanks
6776
- ADD: Help command line agument
6877
- ADD: Version command line argument
6978
- ADD: Patterns only command line argument
@@ -102,7 +111,7 @@ PL-node-v0.0.5
102111

103112
PL-node-v0.0.4
104113
- ADD: An explicit MIT license
105-
- FIX: Clean public/patterns/ before build
114+
- FIX: Clean public/patterns/ before build
106115

107116
PL-node-v0.0.3
108117
- FIX: Install documentation was incomplete, should not have assumed grunt
@@ -114,4 +123,4 @@ PL-node-v0.0.2
114123
- FIX: Grunt watching styleguide scss
115124

116125
PL-node-v0.0.1
117-
- Minimum Viable Product! At this point, I feel you could use Pattern Lab Node to build an atomic design-driven website.
126+
- Minimum Viable Product! At this point, I feel you could use Pattern Lab Node to build an atomic design-driven website.

Gruntfile.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,21 @@ module.exports = function(grunt) {
3232
src: './builder/patternlab_grunt.js',
3333
dest: './builder/patternlab_grunt.js'
3434
},
35+
parameter_hunter: {
36+
src: './builder/parameter_hunter.js',
37+
dest: './builder/parameter_hunter.js'
38+
},
3539
pattern_exporter: {
3640
src: './builder/pattern_exporter.js',
3741
dest: './builder/pattern_exporter.js'
42+
},
43+
pattern_assembler: {
44+
src: './builder/pattern_assembler.js',
45+
dest: './builder/pattern_assembler.js'
46+
},
47+
pseudopattern_hunter: {
48+
src: './builder/pseudopattern_hunter.js',
49+
dest: './builder/pseudopattern_hunter.js'
3850
}
3951
},
4052
copy: {
@@ -125,4 +137,4 @@ module.exports = function(grunt) {
125137

126138
grunt.registerTask('serve', ['clean', 'concat', 'patternlab', /*'sass',*/ 'copy', 'connect', 'watch']);
127139

128-
};
140+
};

README.md

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
[![Build Status](https://travis-ci.org/pattern-lab/patternlab-node.png?branch=master)](https://travis-ci.org/pattern-lab/patternlab-node)
1+
[![Build Status](https://travis-ci.org/pattern-lab/patternlab-node.png?branch=master)](https://travis-ci.org/pattern-lab/patternlab-node)
22

33
## About the Node Version of Pattern Lab
44

55
The Node version of Pattern Lab is, at its core, a static site generator. It combines platform-agnostic assets, like the [Mustache](http://mustache.github.io/)-based patterns and the JavaScript-based viewer, with a Node-based "builder" that transforms and dynamically builds the Pattern Lab site. By making it a static site generator, the Node version of Pattern Lab strongly separates patterns, data, and presentation from build logic. The Node version is a work in progress, the [PHP version](https://github.com/pattern-lab/patternlab-php) should be seen as a reference for other developers to improve upon as they build their own Pattern Lab Builders in their language of choice.
66

77
### Getting Started
88

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:
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`
@@ -73,6 +73,25 @@ Pattern states should be lowercase and use hyphens where spaces are present.
7373
}
7474
```
7575

76+
##### Pattern Parameters
77+
attern 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.
78+
79+
The basic syntax is this:
80+
81+
```
82+
{{> molecules-single-comment(description: 'A life is like a garden. Perfect moments can be had, but not preserved, except in memory.') }}
83+
```
84+
85+
The attributes listed in the pattern parameters should match Mustache variable names in your pattern. The values listed for each attribute will replace the Mustache variables. Again, pattern parameters are a simple find and replace of Mustache variables with the supplied values.
86+
87+
Pattern parameters **do not** currently support the following:
88+
89+
* sub-lists (e.g. iteration of a section),
90+
* and the use of long strings of text can be unwieldy
91+
* nested properties within the parameter data, such as `{{> molecules-single-comment(foo.bar: 'baz') }}`
92+
93+
You can read the full documentation on pattern parameters here: [Using Pattern Parameters](http://patternlab.io/docs/pattern-parameters.html)
94+
7695
##### Pseudo-Patterns
7796
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.
7897

@@ -139,7 +158,7 @@ As you can see, it's a much easier way of linking patterns to one another.
139158

140159

141160
##### 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.
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.
143162

144163
```
145164
"patternExportKeys": ["molecules-primary-nav", "organisms-header", "organisms-header"],
@@ -148,6 +167,15 @@ As you can see, it's a much easier way of linking patterns to one another.
148167

149168
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.
150169

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
151179

152180
##### Verbose Mode
153181
`patternlab.json` is a file created for debugging purposes. Set `debug` to true in `.config.json` to see all the secrets.
@@ -165,7 +193,7 @@ You can find some simple upgrade documenation in it's current home here (unrelea
165193

166194
### Forward, To the Specification!
167195

168-
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.
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.
169197

170198
### Is Pattern Lab a Platform or a Build Tool?
171199

@@ -219,7 +247,7 @@ By default, the Pattern Lab assets can be manually generated and the Pattern Lab
219247
* [Watching for Changes and Auto-Regenerating Patterns](http://patternlab.io/docs/advanced-auto-regenerate.html) - Node version coming soon
220248
* [Auto-Reloading the Browser Window When Changes Are Made](http://patternlab.io/docs/advanced-reload-browser.html) - Node version coming soon
221249
* [Multi-browser & Multi-device Testing with Page Follow](http://patternlab.io/docs/advanced-page-follow.html)
222-
* [Keyboard Shortcuts](http://patternlab.io/docs/advanced-keyboard-shortcuts.html)
250+
* [Keyboard Shortcuts](http://patternlab.io/docs/advanced-keyboard-shortcuts.html)
223251
* [Special Pattern Lab-specific Query String Variables ](http://patternlab.io/docs/pattern-linking.html)
224252
* [Preventing the Cleaning of public/](http://patternlab.io/docs/advanced-clean-public.html) - Node version coming soon
225253
* [Modifying the Pattern Lab Nav](http://patternlab.io/docs/advanced-pattern-lab-nav.html) - Node version coming soon

builder/lineage_hunter.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* patternlab-node - v0.9.1 - 2015
2+
* patternlab-node - v0.10.0 - 2015
33
*
44
* Brian Muenzenmeyer, and the web community.
55
* Licensed under the MIT license.
@@ -15,12 +15,15 @@
1515

1616
function findlineage(pattern, patternlab){
1717

18+
var pa = require('./pattern_assembler');
19+
var pattern_assembler = new pa();
20+
1821
//find the {{> template-name }} within patterns
19-
var matches = pattern.template.match(/{{>([ ]+)?([A-Za-z0-9-]+)(?:\:[A-Za-z0-9-]+)?(?:(| )\(.*)?([ ]+)}}/g);
22+
var matches = pattern_assembler.find_pattern_partials(pattern);
2023
if(matches !== null){
2124
matches.forEach(function(match, index, matches){
2225
//strip out the template cruft
23-
var foundPattern = match.replace("{{> ", "").replace(" }}", "");
26+
var foundPattern = match.replace("{{> ", "").replace(" }}", "").replace("{{>", "").replace("}}", "");
2427

2528
//add if it doesnt exist
2629
if (pattern.lineageIndex.indexOf(foundPattern) === -1){
@@ -71,4 +74,4 @@
7174

7275
module.exports = lineage_hunter;
7376

74-
}());
77+
}());

builder/media_hunter.js

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* patternlab-node - v0.9.1 - 2015
2+
* patternlab-node - v0.10.0 - 2015
33
*
44
* Brian Muenzenmeyer, and the web community.
55
* Licensed under the MIT license.
@@ -12,8 +12,8 @@
1212
"use strict";
1313

1414
var diveSync = require('diveSync'),
15-
path = require('path'),
16-
fs = require('fs-extra');
15+
path = require('path'),
16+
fs = require('fs-extra');
1717

1818
var media_hunter = function(){
1919

@@ -32,7 +32,7 @@
3232
}
3333
}
3434
}
35-
});
35+
});
3636
//alpha sort for now, but should meet most use-cases except greater than 100ems. you are using ems right?
3737
patternlab.mediaQueries.sort();
3838
}
@@ -48,22 +48,3 @@
4848
module.exports = media_hunter;
4949

5050
}());
51-
52-
// protected function gatherMQs() {
53-
54-
// $mqs = array();
55-
56-
// foreach(glob($this->sd."/css/*.css") as $filename) {
57-
// $data = file_get_contents($filename);
58-
// preg_match_all("/(min|max)-width:([ ]+)?(([0-9]{1,5})(\.[0-9]{1,20}|)(px|em))/",$data,$matches);
59-
// foreach ($matches[3] as $match) {
60-
// if (!in_array($match,$mqs)) {
61-
// $mqs[] = $match;
62-
// }
63-
// }
64-
// }
65-
66-
// sort($mqs);
67-
// return $mqs;
68-
69-
// }

builder/object_factory.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* patternlab-node - v0.9.1 - 2015
2+
* patternlab-node - v0.10.0 - 2015
33
*
44
* Brian Muenzenmeyer, and the web community.
55
* Licensed under the MIT license.
@@ -16,6 +16,7 @@
1616
this.subdir = subdir;
1717
this.name = subdir.replace(/[\/\\]/g, '-') + '-' + this.fileName; //this is the unique name with the subDir
1818
this.data = data || null;
19+
this.jsonFileData = {};
1920
this.patternName = this.fileName.substring(this.fileName.indexOf('-') + 1); //this is the display name for the ui
2021
this.patternLink = this.name + '/' + this.name + '.html';
2122
this.patternGroup = this.name.substring(this.name.indexOf('-') + 1, this.name.indexOf('-', 4) + 1 - this.name.indexOf('-') + 1);
@@ -59,4 +60,4 @@
5960
oNavSubItem: oNavSubItem
6061
};
6162

62-
}());
63+
}());

builder/parameter_hunter.js

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*
2+
* patternlab-node - v0.10.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 parameter_hunter = function(){
15+
16+
var extend = require('util')._extend,
17+
pa = require('./pattern_assembler'),
18+
mustache = require('mustache'),
19+
pattern_assembler = new pa();
20+
21+
function findparameters(pattern, patternlab){
22+
23+
//find the {{> template-name(*) }} within patterns
24+
var matches = pattern.template.match(/{{>([ ]+)?([A-Za-z0-9-]+)(\()(.+)(\))([ ]+)?}}/g);
25+
if(matches !== null){
26+
matches.forEach(function(pMatch, index, matches){
27+
//find the partial's name
28+
var partialName = pMatch.match(/([a-z-]+)/ig)[0]
29+
30+
if(patternlab.config.debug){
31+
console.log('found patternParameters for ' + partialName);
32+
}
33+
34+
//strip out the additional data and eval
35+
var leftParen = pMatch.indexOf('(');
36+
var rightParen = pMatch.indexOf(')');
37+
var paramString = '({' + pMatch.substring(leftParen + 1, rightParen) + '})';
38+
39+
//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
40+
var paramData = eval(paramString);
41+
42+
//compile this partial immeadiately, essentially consuming it.
43+
//TODO: see how this affects lineage. perhaps add manually here.
44+
var partialPattern = pattern_assembler.get_pattern_by_key(partialName, patternlab);
45+
var existingData = pattern.data || patternlab.data;
46+
47+
//merge paramData with any other data that exists.
48+
for (var prop in paramData) {
49+
if (existingData.hasOwnProperty(prop)) {
50+
existingData[prop] = paramData[prop];
51+
}
52+
}
53+
54+
//extend pattern data links into link for pattern link shortcuts to work. we do this locally and globally
55+
existingData.link = extend({}, patternlab.data.link);
56+
var renderedPartial = pattern_assembler.renderPattern(partialPattern.extendedTemplate, existingData, patternlab.partials);
57+
58+
//remove the parameter from the partial and replace it with the rendered partial + paramData
59+
pattern.extendedTemplate = pattern.extendedTemplate.replace(pMatch, renderedPartial);
60+
61+
//TODO: lineage is missing for this pattern
62+
63+
});
64+
}
65+
}
66+
67+
return {
68+
find_parameters: function(pattern, patternlab){
69+
findparameters(pattern, patternlab);
70+
}
71+
};
72+
73+
};
74+
75+
module.exports = parameter_hunter;
76+
77+
}());

0 commit comments

Comments
 (0)