Skip to content

Commit ef54360

Browse files
author
Brian Muenzenmeyer
committed
Merge pull request #243 from pattern-lab/dev
Pattern Lab Node v1.1.0
2 parents 3f2efa9 + 5293fb9 commit ef54360

File tree

93 files changed

+1899
-4011
lines changed

Some content is hidden

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

93 files changed

+1899
-4011
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: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,29 @@
11
THIS CHANGELOG IS AN ATTEMPT TO DOCUMENT CHANGES TO THIS PROJECT.
22

3+
PL-node-v1.1.0
4+
- FIX: Fixed issue where partials containing styleModifiers with integers were not found correctly under all circumstances
5+
- 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.
6+
- THX: Thanks @theorise for reporting these issues.
7+
- THX: Thanks @dmolsen for input on desired behavior.
8+
- FIX: Fixed issue where style modifier partials within list item blocks where not uniquely being applied. this seems like a regression. added a unit test with fix
9+
- ADD: Added fuzzy pattern matching support based on patternType-substring(patternName) to align with PL PHP
10+
- FIX: Fixed issue with gulpfile not copying style.css and watching the wrong directory
11+
- THX: Thanks @robinsonaaron for the issue and pull request!
12+
- FIX: Prefer exact pattern key match over fuzzy matches inside getpatternbykey()
13+
- THX: Thanks @EvanLovely for the suggestion
14+
- ADD: Make all paths configurable
15+
- THX: HUGE Thanks to @geoffp and @EvanLovely for their thoughts, time, and talent to make this a reality!
16+
- FIX: Fix issue where absolute paths in the config path object would not resolve
17+
- THX: Thanks to @geoffp and @EvanLovely for reporting, fixing and testing the issue in the dev branch.
18+
- FIX: Typo in gulp instructions in README.
19+
- THX: Thanks @simonknittel for the watchful eyes
20+
- CHG: Changed locations of ./public/styleguide to ./core/styleguide to make ./public/ a cleaner distribution directory
21+
- CHG: Removed scss files and config from project. This is in preparation for including the default asset repo in the future
22+
- FIX: Fix issue where partials were not being sent to Mustache during pattern parameter parsing.
23+
- THX: Thanks to @e2tha-e for reporting this issue.
24+
- ADD: Now patterns and pseudopatterns can be linked from global or file data.json
25+
- THX: Thanks @kylewelsby for the thoughtful enhancement
26+
327
PL-node-v1.0.0
428
- FIX: Resolve issue with not hiding underscored patterns.
529
- THX: Thanks @ivancamilov for reporting this regression.

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: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ To run patternlab-node using gulp, you need to swap out the default grunt config
4444
3. Run `npm install` from the command line
4545
4. Run `gulp` or `gulp serve` from the command line
4646

47-
This creates all patterns, the styleguide, and the pattern lab site. It's strongly recommended to run `grunt serve` to see have BrowserSync spin up and serve the files to you.
47+
This creates all patterns, the styleguide, and the pattern lab site. It's strongly recommended to run `gulp serve` to have BrowserSync spin up and serve the files to you.
4848

4949
### There and Back Again, or Switching Between Grunt and Gulp
5050

@@ -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: 26 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* patternlab-node - v1.0.0 - 2015
2+
* patternlab-node - v1.1.0 - 2016
33
*
44
* Brian Muenzenmeyer, and the web community.
55
* Licensed under the MIT license.
@@ -23,47 +23,41 @@
2323
if(matches !== null){
2424
matches.forEach(function(match, index, matches){
2525
//strip out the template cruft
26-
var foundPattern = match.replace("{{> ", "").replace(" }}", "").replace("{{>", "").replace("}}", "");
26+
var foundPatternKey = match.replace("{{> ", "").replace(" }}", "").replace("{{>", "").replace("}}", "");
2727

2828
// remove any potential pattern parameters. this and the above are rather brutish but I didn't want to do a regex at the time
29-
if(foundPattern.indexOf('(') > 0){
30-
foundPattern = foundPattern.substring(0, foundPattern.indexOf('('));
29+
if(foundPatternKey.indexOf('(') > 0){
30+
foundPatternKey = foundPatternKey.substring(0, foundPatternKey.indexOf('('));
3131
}
3232

33-
//add if it doesnt exist
34-
if (pattern.lineageIndex.indexOf(foundPattern) === -1){
33+
//remove any potential stylemodifiers.
34+
foundPatternKey = foundPatternKey.split(':')[0];
3535

36-
pattern.lineageIndex.push(foundPattern);
36+
//get the ancestorPattern
37+
var ancestorPattern = pattern_assembler.get_pattern_by_key(foundPatternKey, patternlab);
3738

38-
patternlab.patterns.forEach(function(ancestorPattern, index, patterns){
39+
if (ancestorPattern && pattern.lineageIndex.indexOf(ancestorPattern.key) === -1){
3940

40-
//find the pattern in question
41-
var searchPattern = ancestorPattern.patternGroup + "-" + ancestorPattern.patternName;
41+
//add it since it didnt exist
42+
pattern.lineageIndex.push(ancestorPattern.key);
43+
//create the more complex patternLineage object too
44+
var l = {
45+
"lineagePattern": ancestorPattern.key,
46+
"lineagePath": "../../patterns/" + ancestorPattern.patternLink
47+
};
48+
pattern.lineage.push(JSON.stringify(l));
4249

43-
if(searchPattern === foundPattern){
44-
//create the more complex patternLineage object too
45-
var l = {
46-
"lineagePattern": foundPattern,
47-
"lineagePath": "../../patterns/" + ancestorPattern.patternLink
50+
//also, add the lineageR entry if it doesn't exist
51+
if (ancestorPattern.lineageRIndex.indexOf(pattern.key) === -1){
52+
ancestorPattern.lineageRIndex.push(pattern.key);
53+
54+
//create the more complex patternLineage object in reverse
55+
var lr = {
56+
"lineagePattern": pattern.key,
57+
"lineagePath": "../../patterns/" + pattern.patternLink
4858
};
49-
pattern.lineage.push(JSON.stringify(l));
50-
51-
//also, add the lineageR entry if it doesn't exist
52-
var patternLabel = pattern.patternGroup + "-" + pattern.patternName;
53-
if (ancestorPattern.lineageRIndex.indexOf(patternLabel) === -1){
54-
ancestorPattern.lineageRIndex.push(patternLabel);
55-
56-
//create the more complex patternLineage object in reverse
57-
var lr = {
58-
"lineagePattern": patternLabel,
59-
"lineagePath": "../../patterns/" + pattern.patternLink
60-
};
61-
ancestorPattern.lineageR.push(JSON.stringify(lr));
62-
}
59+
ancestorPattern.lineageR.push(JSON.stringify(lr));
6360
}
64-
65-
});
66-
6761
}
6862
});
6963
}

builder/list_item_hunter.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* patternlab-node - v1.0.0 - 2015
2+
* patternlab-node - v1.1.0 - 2016
33
*
44
* Brian Muenzenmeyer, and the web community.
55
* Licensed under the MIT license.
@@ -72,13 +72,16 @@
7272
var partialName = foundPartials[j].match(/([\w\-\.\/~]+)/g)[0];
7373
var partialPattern = pattern_assembler.get_pattern_by_key(partialName, patternlab);
7474

75+
//create a copy of the partial so as to not pollute it after the get_pattern_by_key call.
76+
var cleanPartialPattern = JSON.parse(JSON.stringify(partialPattern));
77+
7578
//if partial has style modifier data, replace the styleModifier value
76-
if(pattern.stylePartials && pattern.stylePartials.length > 0){
77-
style_modifier_hunter.consume_style_modifier(partialPattern, foundPartials[j], patternlab);
79+
if(foundPartials[j].indexOf(':') > -1){
80+
style_modifier_hunter.consume_style_modifier(cleanPartialPattern, foundPartials[j], patternlab);
7881
}
7982

8083
//replace its reference within the block with the extended template
81-
thisBlockTemplate = thisBlockTemplate.replace(foundPartials[j], partialPattern.extendedTemplate);
84+
thisBlockTemplate = thisBlockTemplate.replace(foundPartials[j], cleanPartialPattern.extendedTemplate);
8285
}
8386

8487
//render with data
@@ -97,6 +100,9 @@
97100
var repeatingBlock = pattern.extendedTemplate.substring(pattern.extendedTemplate.indexOf(liMatch), pattern.extendedTemplate.indexOf(end) + end.length);
98101
pattern.extendedTemplate = pattern.extendedTemplate.replace(repeatingBlock, repeatedBlockHtml);
99102

103+
//update the extendedTemplate in the partials object in case this pattern is consumed later
104+
patternlab.partials[pattern.key] = pattern.extendedTemplate;
105+
100106
});
101107
}
102108
}

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

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

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.0 - 2015
2+
* patternlab-node - v1.1.0 - 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
}

0 commit comments

Comments
 (0)