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

Commit 5769a9c

Browse files
committed
Merge remote-tracking branch 'refs/remotes/upstream/dev' into pattern-engines
Conflicts: builder/object_factory.js builder/pattern_assembler.js builder/patternlab.js builder/pseudopattern_hunter.js test/lineage_hunter_tests.js test/list_item_hunter_tests.js test/pattern_assembler_tests.js
2 parents 7243967 + 0173a0a commit 5769a9c

26 files changed

+640
-236
lines changed

CHANGELOG

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
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+
315
PL-node-v1.0.0
416
- FIX: Resolve issue with not hiding underscored patterns.
517
- THX: Thanks @ivancamilov for reporting this regression.

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.0.1 - 2015
33
*
44
* Brian Muenzenmeyer, and the web community.
55
* Licensed under the MIT license.
@@ -24,47 +24,41 @@
2424
if(matches !== null){
2525
matches.forEach(function(match, index, matches){
2626
//strip out the template cruft
27-
var foundPattern = match.replace("{{> ", "").replace(" }}", "").replace("{{>", "").replace("}}", "");
27+
var foundPatternKey = match.replace("{{> ", "").replace(" }}", "").replace("{{>", "").replace("}}", "");
2828

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

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

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

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

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

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

builder/list_item_hunter.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
/*
2-
* patternlab-node - v1.0.0 - 2015
3-
*
1+
/*
2+
* patternlab-node - v1.0.1 - 2015
3+
*
44
* Brian Muenzenmeyer, and the web community.
55
* Licensed under the MIT license.
66
*
@@ -79,13 +79,16 @@
7979
var partialName = foundPartials[j].match(/([\w\-\.\/~]+)/g)[0];
8080
var partialPattern = pattern_assembler.get_pattern_by_key(partialName, patternlab);
8181

82+
//create a copy of the partial so as to not pollute it after the get_pattern_by_key call.
83+
var cleanPartialPattern = JSON.parse(JSON.stringify(partialPattern));
84+
8285
//if partial has style modifier data, replace the styleModifier value
83-
if(pattern.stylePartials && pattern.stylePartials.length > 0){
84-
style_modifier_hunter.consume_style_modifier(partialPattern, foundPartials[j], patternlab);
86+
if(foundPartials[j].indexOf(':') > -1){
87+
style_modifier_hunter.consume_style_modifier(cleanPartialPattern, foundPartials[j], patternlab);
8588
}
8689

8790
//replace its reference within the block with the extended template
88-
thisBlockTemplate = thisBlockTemplate.replace(foundPartials[j], partialPattern.extendedTemplate);
91+
thisBlockTemplate = thisBlockTemplate.replace(foundPartials[j], cleanPartialPattern.extendedTemplate);
8992
}
9093

9194
//render with data

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.0.1 - 2015
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.0 - 2015
3-
*
1+
/*
2+
* patternlab-node - v1.0.1 - 2015
3+
*
44
* Brian Muenzenmeyer, and the web community.
55
* Licensed under the MIT license.
66
*

builder/parameter_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.0.1 - 2015
33
*
44
* Brian Muenzenmeyer, and the web community.
55
* Licensed under the MIT license.

builder/pattern_assembler.js

Lines changed: 24 additions & 6 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.0.1 - 2015
33
*
44
* Brian Muenzenmeyer, and the web community.
55
* Licensed under the MIT license.
@@ -72,7 +72,7 @@
7272

7373
function processPatternIterative(file, patternlab){
7474
//extract some information
75-
var subdir = path.dirname(path.relative(patternlab.config.patterns.source, file)).replace('\\', '/');
75+
var subdir = path.dirname(path.relative(patternlab.config.paths.source.patterns, file)).replace('\\', '/');
7676
var filename = path.basename(file);
7777
var ext = path.extname(filename);
7878

@@ -101,7 +101,7 @@
101101

102102
//look for a json file for this template
103103
try {
104-
var jsonFilename = path.resolve(patternlab.config.patterns.source, currentPattern.subdir, currentPattern.fileName + ".json");
104+
var jsonFilename = path.resolve(patternlab.config.paths.source.patterns, currentPattern.subdir, currentPattern.fileName + ".json");
105105
currentPattern.jsonFileData = fs.readJSONSync(jsonFilename);
106106
if(patternlab.config.debug){
107107
console.log('processPatternIterative: found pattern-specific data.json for ' + currentPattern.key);
@@ -112,8 +112,8 @@
112112

113113
//look for a listitems.json file for this template
114114
try {
115-
var listJsonFileName = patternlab.config.patterns.source + currentPattern.subdir + '/' + currentPattern.fileName + ".listitems.json";
116-
currentPattern.listitems = fs.readJSONSync(listJsonFileName.substring(2));
115+
var listJsonFileName = path.resolve(patternlab.config.paths.source.patterns, currentPattern.subdir,currentPattern.fileName + ".listitems.json");
116+
currentPattern.listitems = fs.readJSONSync(listJsonFileName);
117117
buildListItems(currentPattern);
118118
if(patternlab.config.debug){
119119
console.log('found pattern-specific listitems.json for ' + currentPattern.key);
@@ -228,14 +228,32 @@
228228
}
229229

230230
function getpatternbykey(key, patternlab){
231+
232+
//look for exact key matches
233+
for(var i = 0; i < patternlab.patterns.length; i++){
234+
if(patternlab.patterns[i].key === key){
235+
return patternlab.patterns[i];
236+
}
237+
}
238+
239+
//else look by verbose syntax
231240
for(var i = 0; i < patternlab.patterns.length; i++){
232241
switch(key){
233-
case patternlab.patterns[i].key:
234242
case patternlab.patterns[i].subdir + '/' + patternlab.patterns[i].fileName:
235243
case patternlab.patterns[i].subdir + '/' + patternlab.patterns[i].fileName + '.mustache':
236244
return patternlab.patterns[i];
237245
}
238246
}
247+
248+
//return the fuzzy match if all else fails
249+
for(var i = 0; i < patternlab.patterns.length; i++){
250+
var keyParts = key.split('-'),
251+
keyType = keyParts[0],
252+
keyName = keyParts.slice(1).join('-');
253+
if(patternlab.patterns[i].key.split('-')[0] === keyType && patternlab.patterns[i].key.indexOf(keyName) > -1){
254+
return patternlab.patterns[i];
255+
}
256+
}
239257
throw 'Could not find pattern with key ' + key;
240258
}
241259

builder/pattern_exporter.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.0.1 - 2015
33
*
44
* Brian Muenzenmeyer, and the web community.
55
* Licensed under the MIT license.

0 commit comments

Comments
 (0)