Skip to content
This repository was archived by the owner on Dec 10, 2019. It is now read-only.

Commit e2ee979

Browse files
committed
Merge branch 'pattern-engines' into pattern-engines-upstream
2 parents 5d4c18f + 8c605fa commit e2ee979

Some content is hidden

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

88 files changed

+1294
-3807
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,5 @@ public/styleguide/css/static.css.map
1818
public/styleguide/css/styleguide-specific.css.map
1919
public/styleguide/css/styleguide.css.map
2020
source/css/style.css.map
21+
.idea/
22+
public/styleguide/

CHANGELOG

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

3+
PL-node-v1.1.1
4+
- FIX: Fixed issue where alternate patterns are added to end of styleguide instead of inline with their parent pattern.
5+
36
PL-node-v1.1.0
47
- FIX: Fixed issue where partials containing styleModifiers with integers were not found correctly under all circumstances
58
- FIX: Fixed issue where excluded patterns were still rendered on the Pattern Lab site. Now they do not directly get rendered via the menu, view all links, or the styleguide, but are accessible for inclusion as pattern partials, and can be accessed via lineage.
@@ -11,10 +14,18 @@ PL-node-v1.1.0
1114
- THX: Thanks @robinsonaaron for the issue and pull request!
1215
- FIX: Prefer exact pattern key match over fuzzy matches inside getpatternbykey()
1316
- THX: Thanks @EvanLovely for the suggestion
17+
- ADD: Make all paths configurable
18+
- THX: HUGE Thanks to @geoffp and @EvanLovely for their thoughts, time, and talent to make this a reality!
1419
- FIX: Fix issue where absolute paths in the config path object would not resolve
1520
- THX: Thanks to @geoffp and @EvanLovely for reporting, fixing and testing the issue in the dev branch.
1621
- FIX: Typo in gulp instructions in README.
1722
- THX: Thanks @simonknittel for the watchful eyes
23+
- CHG: Changed locations of ./public/styleguide to ./core/styleguide to make ./public/ a cleaner distribution directory
24+
- CHG: Removed scss files and config from project. This is in preparation for including the default asset repo in the future
25+
- FIX: Fix issue where partials were not being sent to Mustache during pattern parameter parsing.
26+
- THX: Thanks to @e2tha-e for reporting this issue.
27+
- ADD: Now patterns and pseudopatterns can be linked from global or file data.json
28+
- THX: Thanks @kylewelsby for the thoughtful enhancement
1829

1930
PL-node-v1.0.0
2031
- FIX: Resolve issue with not hiding underscored patterns.

Gruntfile.js

Lines changed: 30 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
module.exports = function(grunt) {
22

3+
var path = require('path');
4+
35
// Project configuration.
46
grunt.initConfig({
57
pkg: grunt.file.readJSON('package.json'),
@@ -60,97 +62,77 @@ module.exports = function(grunt) {
6062
copy: {
6163
main: {
6264
files: [
63-
{ expand: true, cwd: './source/js/', src: '*', dest: './public/js/'},
64-
{ expand: true, cwd: './source/css/', src: '*.css', dest: './public/css/' },
65-
{ expand: true, cwd: './source/images/', src: ['*.png', '*.jpg', '*.gif', '*.jpeg'], dest: './public/images/' },
66-
{ expand: true, cwd: './source/images/sample/', src: ['*.png', '*.jpg', '*.gif', '*.jpeg'], dest: './public/images/sample/'},
67-
{ expand: true, cwd: './source/fonts/', src: '*', dest: './public/fonts/'},
68-
{ expand: true, cwd: './source/_data/', src: 'annotations.js', dest: './public/data/' }
65+
{ expand: true, cwd: path.resolve(paths().source.js), src: '*.js', dest: path.resolve(paths().public.js) },
66+
{ expand: true, cwd: path.resolve(paths().source.css), src: '*.css', dest: path.resolve(paths().public.css) },
67+
{ expand: true, cwd: path.resolve(paths().source.images), src: ['**/*.png', '**/*.jpg', '**/*.gif', '**/*.jpeg'], dest: path.resolve(paths().public.images) },
68+
{ expand: true, cwd: path.resolve(paths().source.fonts), src: '*', dest: path.resolve(paths().public.fonts) },
69+
{ expand: true, cwd: path.resolve(paths().source.data), src: 'annotations.js', dest: path.resolve(paths().public.data) }
6970
]
7071
},
71-
css: {
72+
styleguide: {
7273
files: [
73-
{ expand: true, cwd: './source/css/', src: '*.css', dest: './public/css/' }
74+
{ expand: true, cwd: path.resolve(paths().source.styleguide), src: ['*.*', '**/*.*'], dest: path.resolve(paths().public.styleguide) }
7475
]
7576
}
7677
},
7778
watch: {
7879
all: {
7980
files: [
80-
'source/css/**/*.css',
81-
'public/styleguide/css/*.css',
82-
'source/_patterns/**/*.mustache',
83-
'source/_patterns/**/*.json',
84-
'source/_data/*.json'
81+
path.resolve(paths().source.css + '**/*.css'),
82+
path.resolve(paths().source.styleguide + 'css/*.css'),
83+
path.resolve(paths().source.patterns + '**/*.mustache'),
84+
path.resolve(paths().source.patterns + '**/*.json'),
85+
path.resolve(paths().source.fonts + '/*'),
86+
path.resolve(paths().source.images + '/*'),
87+
path.resolve(paths().source.data + '*.json')
8588
],
86-
tasks: ['default']
87-
},
88-
// scss: {
89-
// files: ['source/css/**/*.scss', 'public/styleguide/css/*.scss'],
90-
// tasks: ['sass', 'copy:css','bsReload:css']
91-
// },
92-
patterns: {
93-
files: [
94-
'source/_patterns/**/*.mustache',
95-
'source/_patterns/**/*.json',
96-
'source/_data/*.json'
97-
],
98-
tasks: ['default']
89+
tasks: ['default', 'bsReload:css']
9990
}
10091
},
101-
// sass: {
102-
// build: {
103-
// options: {
104-
// style: 'expanded',
105-
// precision: 8
106-
// },
107-
// files: {
108-
// './source/css/style.css': './source/css/style.scss',
109-
// './public/styleguide/css/static.css': './public/styleguide/css/static.scss',
110-
// './public/styleguide/css/styleguide.css': './public/styleguide/css/styleguide.scss',
111-
// './public/styleguide/css/styleguide-specific.css': './public/styleguide/css/styleguide-specific.scss'
112-
// }
113-
// }
114-
// },
11592
nodeunit: {
11693
all: ['test/*_tests.js']
11794
},
11895
browserSync: {
11996
dev: {
12097
options: {
121-
server: './public',
98+
server: path.resolve(paths().public.root),
12299
watchTask: true,
100+
watchOptions: {
101+
ignoreInitial: true,
102+
ignored: '*.html'
103+
},
123104
plugins: [
124105
{
125106
module: 'bs-html-injector',
126107
options: {
127-
files: './public/index.html'
108+
files: [path.resolve(paths().public.root + '/index.html'), path.resolve(paths().public.styleguide + '/styleguide.html')]
128109
}
129110
}
130111
]
131112
}
132113
}
133114
},
134115
bsReload: {
135-
css: './public/**/*.css'
116+
css: path.resolve(paths().public.root + '**/*.css')
136117
}
137118
});
138119

120+
function paths () {
121+
return require('./config.json').paths;
122+
}
123+
139124
// load all grunt tasks
140125
require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);
141126

142127
//load the patternlab task
143128
grunt.task.loadTasks('./builder/');
144129

145-
//if you choose to use scss, or any preprocessor, you can add it here
146-
grunt.registerTask('default', ['patternlab', /*'sass',*/ 'copy:main']);
130+
grunt.registerTask('default', ['patternlab', 'copy:main', 'copy:styleguide']);
147131

148132
//travis CI task
149133
grunt.registerTask('travis', ['nodeunit', 'patternlab']);
150134

151-
//TODO: this line is more efficient, but you cannot run concurrent watch tasks without another dependency.
152-
//grunt.registerTask('serve', ['patternlab', /*'sass',*/ 'copy:main', 'browserSync', 'watch:patterns', 'watch:scss']);
153-
grunt.registerTask('serve', ['patternlab', /*'sass',*/ 'copy:main', 'browserSync', 'watch:all']);
135+
grunt.registerTask('serve', ['patternlab', 'copy:main', 'copy:styleguide', 'browserSync', 'watch:all']);
154136

155137
grunt.registerTask('build', ['nodeunit', 'concat']);
156138

README.md

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,36 @@ Get more information about patternlab-node, pattern lab in general, and where to
8080
##### Watching Changes
8181
To have patternlab-node watch for changes to either a mustache template, data, or stylesheets, run `grunt|gulp watch` or `grunt|gulp serve`. The `Gruntfile|Gulpfile` governs what is watched. It should be easy to add scss or whatever preprocessor you fancy.
8282

83-
##### Preprocessor Support
84-
The patternlab-node release package ships with some `.scss` files utilized in the creation of the style guide and sample templates, but these are not required. The compilation tasks are commented out in the `Gruntfiles|Gulpfiles` but can be uncommented or changed to meet your needs. Sass modules are not included in `package.json` files - the prevailing thought being if you are familiar enough with preprocessors, you can use the instructions for [grunt-contrib-sass](https://github.com/gruntjs/grunt-contrib-sass) / [gulp-sass](https://github.com/dlmanning/gulp-sass) / _preprocessor of choice_ to install them. Uncomment the preprocessor configuration to fully utilize the example templates, css and style guide.
83+
##### Configurable Paths
84+
Pattern Lab Node ships with a particular source and public workflow intended to separate the code you work on with the code generated for consumption elsewhere. If you wish to change any paths, you may do so within `config.json`. The contents are here:
8585

86-
**NOTE:** You may run into issues installing gulp-sass if you don't have the latest Visual Studio on Windows. See [here](https://github.com/sass/node-sass/issues/469) for more information and [this query](https://github.com/sass/node-sass/issues?utf8=%E2%9C%93&q=is%3Aissue+install) for a slew of installation problems related to gulp-sass.
86+
```
87+
"paths" : {
88+
"source" : {
89+
"root": "./source/",
90+
"patterns" : "./source/_patterns/",
91+
"data" : "./source/_data/",
92+
"styleguide" : "./core/styleguide/",
93+
"patternlabFiles" : "./source/_patternlab-files/",
94+
"js" : "./source/js",
95+
"images" : "./source/images",
96+
"fonts" : "./source/fonts",
97+
"css" : "./source/css/"
98+
},
99+
"public" : {
100+
"root" : "./public/",
101+
"patterns" : "./public/patterns/",
102+
"data" : "./public/data/",
103+
"styleguide" : "./public/styleguide/",
104+
"js" : "./public/js",
105+
"images" : "./public/images",
106+
"fonts" : "./public/fonts",
107+
"css" : "./public/css"
108+
}
109+
}
110+
```
111+
112+
Note the intentional repitition of the nested structure, made this way for maximum flexibility. Relative paths are default but absolute paths should work too. You may also use these paths within Grunt or Gulp files by referring to the paths() object.
87113

88114
##### Nav Bar Controls
89115
If you don't have a need for some of the nav-bar tools in the Pattern Lab frontend, you can turn them off in `config.json`.

builder/lineage_hunter.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
/*
2-
* patternlab-node - v1.0.1 - 2015
3-
*
1+
/*
2+
* patternlab-node - v1.1.1 - 2016
3+
*
44
* Brian Muenzenmeyer, and the web community.
55
* Licensed under the MIT license.
66
*

builder/list_item_hunter.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
/*
2-
* patternlab-node - v1.0.1 - 2015
3-
*
1+
/*
2+
* patternlab-node - v1.1.1 - 2016
3+
*
44
* 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.
5+
* Licensed under the MIT license.
6+
*
7+
* Many thanks to Brad Frost and Dave Olsen for inspiration, encouragement, and advice.
88
*
99
*/
1010

@@ -106,6 +106,9 @@
106106
var repeatingBlock = pattern.extendedTemplate.substring(pattern.extendedTemplate.indexOf(liMatch), pattern.extendedTemplate.indexOf(end) + end.length);
107107
pattern.extendedTemplate = pattern.extendedTemplate.replace(repeatingBlock, repeatedBlockHtml);
108108

109+
//update the extendedTemplate in the partials object in case this pattern is consumed later
110+
patternlab.partials[pattern.key] = pattern.extendedTemplate;
111+
109112
});
110113
}
111114
}

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 - v1.0.1 - 2015
2+
* patternlab-node - v1.1.1 - 2016
33
*
44
* Brian Muenzenmeyer, and the web community.
55
* Licensed under the MIT license.

builder/object_factory.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
/*
2-
* patternlab-node - v1.0.1 - 2015
3-
*
1+
/*
2+
* patternlab-node - v1.1.1 - 2016
3+
*
44
* Brian Muenzenmeyer, and the web community.
55
* Licensed under the MIT license.
66
*

builder/parameter_hunter.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* patternlab-node - v1.0.1 - 2015
2+
* patternlab-node - v1.1.1 - 2016
33
*
44
* Brian Muenzenmeyer, and the web community.
55
* Licensed under the MIT license.
@@ -61,6 +61,9 @@
6161

6262
//remove the parameter from the partial and replace it with the rendered partial + paramData
6363
pattern.extendedTemplate = pattern.extendedTemplate.replace(pMatch, renderedPartial);
64+
65+
//update the extendedTemplate in the partials object in case this pattern is consumed later
66+
patternlab.partials[pattern.key] = pattern.extendedTemplate;
6467
});
6568
}
6669
}

builder/pattern_assembler.js

Lines changed: 45 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
/*
2-
* patternlab-node - v1.0.1 - 2015
3-
*
1+
/*
2+
* patternlab-node - v1.1.1 - 2016
3+
*
44
* 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.
5+
* Licensed under the MIT license.
6+
*
7+
* Many thanks to Brad Frost and Dave Olsen for inspiration, encouragement, and advice.
88
*
99
*/
1010

@@ -37,14 +37,17 @@
3737
if(pattern.abspath === patternlab.patterns[i].abspath){
3838
//if abspath already exists, overwrite that element
3939
patternlab.patterns[i] = pattern;
40+
patternlab.partials[pattern.key] = pattern.extendedTemplate || pattern.template;
4041
isNew = false;
4142
break;
4243
}
4344
}
44-
//if the pattern is new, just push to the array
45-
if(isNew){
45+
// if the pattern is new, we must register it with various data structures!
46+
if (isNew) {
4647
// do global registration
4748
patternlab.patterns.push(pattern);
49+
patternlab.partials[pattern.key] = pattern.extendedTemplate || pattern.template;
50+
4851
// do plugin-specific registration
4952
pattern.registerPartial();
5053
}
@@ -199,10 +202,16 @@
199202

200203
//find any listItem blocks that within the pattern, even if there are no partials
201204
list_item_hunter.process_list_item_partials(currentPattern, patternlab);
202-
203-
// expand any partials present in this pattern; that is, drill down into the template and replace their calls in this template with rendered results
205+
206+
// expand any partials present in this pattern; that is, drill down into
207+
// the template and replace their calls in this template with rendered
208+
// results
204209
if (currentPattern.engine.expandPartials && (foundPatternPartials !== null && foundPatternPartials.length > 0)) {
205210
expandPartials(foundPatternPartials, list_item_hunter, patternlab, currentPattern);
211+
212+
// update the extendedTemplate in the partials object in case this
213+
// pattern is consumed later
214+
patternlab.partials[currentPattern.key] = currentPattern.extendedTemplate;
206215
}
207216

208217
//find pattern lineage
@@ -273,33 +282,36 @@
273282

274283

275284

285+
function parseDataLinksHelper (patternlab, obj, key) {
286+
var linkRE, dataObjAsString, linkMatches, expandedLink;
287+
288+
linkRE = /link\.[A-z0-9-_]+/g
289+
dataObjAsString = JSON.stringify(obj);
290+
linkMatches = dataObjAsString.match(linkRE)
291+
292+
if(linkMatches) {
293+
for (var i = 0; i < linkMatches.length; i++) {
294+
expandedLink = patternlab.data.link[linkMatches[i].split('.')[1]];
295+
if (expandedLink) {
296+
if(patternlab.config.debug){
297+
console.log('expanded data link from ' + linkMatches[i] + ' to ' + expandedLink + ' inside ' + key);
298+
}
299+
dataObjAsString = dataObjAsString.replace(linkMatches[i], expandedLink);
300+
}
301+
}
302+
}
303+
return JSON.parse(dataObjAsString)
304+
}
276305
//look for pattern links included in data files.
277306
//these will be in the form of link.* WITHOUT {{}}, which would still be there from direct pattern inclusion
278-
function parseDataLinks(patternlab){
307+
function parseDataLinks(patternlab) {
308+
//look for link.* such as link.pages-blog as a value
309+
310+
patternlab.data = parseDataLinksHelper(patternlab, patternlab.data, 'data.json')
279311

280312
//loop through all patterns
281-
for (var i = 0; i < patternlab.patterns.length; i++){
282-
var pattern = patternlab.patterns[i];
283-
//look for link.* such as link.pages-blog as a value
284-
var linkRE = /link.[A-z0-9-_]+/g;
285-
//convert to string for easier searching
286-
var dataObjAsString = JSON.stringify(pattern.jsonFileData);
287-
var linkMatches = dataObjAsString.match(linkRE);
288-
289-
//if no matches found, escape current loop iteration
290-
if(linkMatches === null) { continue; }
291-
292-
for(var i = 0; i < linkMatches.length; i++){
293-
//for each match, find the expanded link within the already constructed patternlab.data.link object
294-
var expandedLink = patternlab.data.link[linkMatches[i].split('.')[1]];
295-
if(patternlab.config.debug){
296-
console.log('expanded data link from ' + linkMatches[i] + ' to ' + expandedLink + ' inside ' + pattern.key);
297-
}
298-
//replace value with expandedLink on the pattern
299-
dataObjAsString = dataObjAsString.replace(linkMatches[i], expandedLink);
300-
}
301-
//write back to data on the pattern
302-
pattern.jsonFileData = JSON.parse(dataObjAsString);
313+
for (var i = 0; i < patternlab.patterns.length; i++) {
314+
patternlab.patterns[i].jsonFileData = parseDataLinksHelper(patternlab, patternlab.patterns[i].jsonFileData, patternlab.patterns[i].key)
303315
}
304316
}
305317

0 commit comments

Comments
 (0)