Skip to content

Commit 630384b

Browse files
committed
Merge branch 'dev' into feature/enable-as-dependency
2 parents 6dfd2f7 + 14797d9 commit 630384b

File tree

6 files changed

+61
-27
lines changed

6 files changed

+61
-27
lines changed

CHANGELOG

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ PL-node-v1.1.0
77
- THX: Thanks @dmolsen for input on desired behavior.
88
- 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
99
- 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
1014

1115
PL-node-v1.0.0
1216
- FIX: Resolve issue with not hiding underscored patterns.

README.md

Lines changed: 1 addition & 1 deletion
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

builder/pattern_assembler.js

Lines changed: 19 additions & 13 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.0.1 - 2015
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

@@ -248,18 +248,25 @@
248248
}
249249

250250
function getpatternbykey(key, patternlab){
251+
252+
//look for exact key matches
253+
for(var i = 0; i < patternlab.patterns.length; i++){
254+
if(patternlab.patterns[i].key === key){
255+
return patternlab.patterns[i];
256+
}
257+
}
258+
259+
//else look by verbose syntax
251260
for(var i = 0; i < patternlab.patterns.length; i++){
252261
switch(key){
253-
case patternlab.patterns[i].key:
254262
case patternlab.patterns[i].subdir + '/' + patternlab.patterns[i].fileName:
255263
case patternlab.patterns[i].subdir + '/' + patternlab.patterns[i].fileName + '.mustache':
256264
return patternlab.patterns[i];
257265
}
258-
//look for exact key matches
259-
if(key === patternlab.patterns[i].key){
260-
return patternlab.patterns[i];
261-
}
262-
//return the fuzzy match within the type if it exists
266+
}
267+
268+
//return the fuzzy match if all else fails
269+
for(var i = 0; i < patternlab.patterns.length; i++){
263270
var keyParts = key.split('-'),
264271
keyType = keyParts[0],
265272
keyName = keyParts.slice(1).join('-');
@@ -270,7 +277,6 @@
270277
throw 'Could not find pattern with key ' + key;
271278
}
272279

273-
274280
function mergeData(obj1, obj2){
275281
if(typeof obj2 === 'undefined'){
276282
obj2 = {};

builder/patternlab.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ var patternlab_engine = function (config) {
9090
console.log(err);
9191
return;
9292
}
93-
pattern_assembler.process_pattern_iterative(file.substring(2), patternlab);
93+
pattern_assembler.process_pattern_iterative(path.resolve(file), patternlab);
9494
});
9595

9696
//now that all the main patterns are known, look for any links that might be within data and expand them
@@ -115,8 +115,9 @@ var patternlab_engine = function (config) {
115115
console.log(err);
116116
return;
117117
}
118-
pattern_assembler.process_pattern_recursive(file.substring(2), patternlab);
119-
});
118+
pattern_assembler.process_pattern_recursive(path.resolve(file), patternlab);
119+
});
120+
120121

121122
//delete the contents of config.patterns.public before writing
122123
if(deletePatternDir){

gulpfile.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ gulp.task('connect', ['lab'], function(){
101101
baseDir: paths().public.root
102102
}
103103
});
104-
gulp.watch(path.resolve(paths().public.css, 'style.css'), ['cp:css']);
104+
gulp.watch(path.resolve(paths().source.css, '**/*.css'), ['cp:css']);
105105

106106
//suggested watches if you use scss
107107
// gulp.watch('./source/css/**/*.scss', ['sass:style']);
@@ -152,7 +152,7 @@ gulp.task('lab-pipe', ['lab'], function(cb){
152152

153153
gulp.task('default', ['lab']);
154154

155-
gulp.task('assets', ['cp:js', 'cp:img', 'cp:font', 'cp:data', /*'sass:style', 'sass:styleguide'*/]);
155+
gulp.task('assets', ['cp:js', 'cp:img', 'cp:font', 'cp:data', 'cp:css' /*'sass:style', 'sass:styleguide'*/]);
156156
gulp.task('prelab', ['clean', 'assets']);
157157
gulp.task('lab', ['prelab', 'patternlab'], function(cb){cb();});
158158
gulp.task('patterns', ['patternlab:only_patterns']);

test/pattern_assembler_tests.js

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@
239239
return;
240240
}
241241

242-
pattern_assembler.process_pattern_iterative(file.substring(2), patternlab);
242+
pattern_assembler.process_pattern_iterative(path.resolve(file), patternlab);
243243
}
244244
);
245245

@@ -263,7 +263,7 @@
263263
return;
264264
}
265265

266-
pattern_assembler.process_pattern_recursive(file.substring(2), patternlab);
266+
pattern_assembler.process_pattern_recursive(path.resolve(file), patternlab);
267267
}
268268
);
269269

@@ -532,11 +532,12 @@
532532
var patternlab = {};
533533
//THIS IS BAD.
534534
patternlab.config = fs.readJSONSync('./config.json');
535-
patternlab.config.patterns = {source: patterns_dir};
536-
patternlab.data = fs.readJSONSync('./source/_data/data.json');
537-
patternlab.listitems = fs.readJSONSync('./source/_data/listitems.json');
538-
patternlab.header = fs.readFileSync('./source/_patternlab-files/pattern-header-footer/header.html', 'utf8');
539-
patternlab.footer = fs.readFileSync('./source/_patternlab-files/pattern-header-footer/footer.html', 'utf8');
535+
patternlab.config.paths.source.patterns = patterns_dir;
536+
537+
patternlab.data = fs.readJSONSync(path.resolve(patternlab.config.paths.source.data, 'data.json'));
538+
patternlab.listitems = fs.readJSONSync(path.resolve(patternlab.config.paths.source.data, 'listitems.json'));
539+
patternlab.header = fs.readFileSync(path.resolve(patternlab.config.paths.source.patternlabFiles, 'pattern-header-footer/header.html'), 'utf8');
540+
patternlab.footer = fs.readFileSync(path.resolve(patternlab.config.paths.source.patternlabFiles, 'pattern-header-footer/footer.html'), 'utf8');
540541
patternlab.patterns = [];
541542
patternlab.data.link = {};
542543
patternlab.partials = {};
@@ -560,7 +561,7 @@
560561
return;
561562
}
562563

563-
pattern_assembler.process_pattern_iterative(file.substring(2), patternlab);
564+
pattern_assembler.process_pattern_iterative(path.resolve(file), patternlab);
564565
}
565566
);
566567

@@ -697,6 +698,28 @@
697698
//assert
698699
test.equals(result, patternlab.patterns[0]);
699700
test.done();
701+
},
702+
'get_pattern_by_key - returns the exact key if found' : function(test){
703+
//arrange
704+
var pattern_assembler = new pa();
705+
var patternlab = {};
706+
patternlab.patterns = [];
707+
708+
patternlab.patterns.push({
709+
key: 'molecules-primary-nav-jagged',
710+
subdir: 'molecules',
711+
fileName: 'primary-nav-jagged'
712+
}, {
713+
key: 'molecules-primary-nav',
714+
subdir: 'molecules',
715+
fileName: 'molecules-primary-nav'
716+
});
717+
718+
//act
719+
var result = pattern_assembler.get_pattern_by_key('molecules-primary-nav', patternlab);
720+
//assert
721+
test.equals(result, patternlab.patterns[1]);
722+
test.done();
700723
}
701724
};
702725
}());

0 commit comments

Comments
 (0)