Skip to content

Commit bf8cc0d

Browse files
committed
Fix issue where excluded patterns were still rendered on the Pattern Lab site.
Closes #210
1 parent 5a091d8 commit bf8cc0d

15 files changed

+88
-98
lines changed

CHANGELOG

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ THIS CHANGELOG IS AN ATTEMPT TO DOCUMENT CHANGES TO THIS PROJECT.
22

33
PL-node-v1.0.1
44
- FIX: Fix issue where partials containing styleModifiers with integers were not found correctly under all circumstances
5+
- FIX: Fix 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.
58

69
PL-node-v1.0.0
710
- FIX: Resolve issue with not hiding underscored patterns.

builder/lineage_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/list_item_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/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: 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/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: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
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.
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

@@ -96,7 +96,7 @@
9696
var ext = path.extname(filename);
9797

9898
//ignore dotfiles, underscored files, and non-variant .json files
99-
if(filename.charAt(0) === '.' || filename.charAt(0) === '_' || (ext === '.json' && filename.indexOf('~') === -1)){
99+
if(filename.charAt(0) === '.' || (ext === '.json' && filename.indexOf('~') === -1)){
100100
return;
101101
}
102102

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.

builder/patternlab.js

Lines changed: 67 additions & 29 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.
@@ -124,6 +124,7 @@ var patternlab_engine = function () {
124124

125125
//render all patterns last, so lineageR works
126126
patternlab.patterns.forEach(function(pattern, index, patterns){
127+
127128
//render the pattern, but first consolidate any data we may have
128129
var allData = JSON.parse(JSON.stringify(patternlab.data));
129130
allData = pattern_assembler.merge_data(allData, pattern.jsonFileData);
@@ -165,15 +166,24 @@ var patternlab_engine = function () {
165166
// check if patterns are excluded, if not add them to styleguidePatterns
166167
if (styleGuideExcludes.length) {
167168
for (i = 0; i < patternlab.patterns.length; i++) {
168-
var key = patternlab.patterns[i].key;
169-
var typeKey = key.substring(0, key.indexOf('-'));
170-
var isExcluded = (styleGuideExcludes.indexOf(typeKey) > -1);
171-
if (!isExcluded) {
172-
styleguidePatterns.push(patternlab.patterns[i]);
169+
170+
// skip underscore-prefixed files
171+
if(isPatternExcluded(patternlab.patterns[i])){
172+
if(patternlab.config.debug){
173+
console.log('Omitting ' + patternlab.patterns[i].key + " from styleguide pattern exclusion.");
173174
}
175+
continue;
176+
}
177+
178+
var key = patternlab.patterns[i].key;
179+
var typeKey = key.substring(0, key.indexOf('-'));
180+
var isExcluded = (styleGuideExcludes.indexOf(typeKey) > -1);
181+
if (!isExcluded) {
182+
styleguidePatterns.push(patternlab.patterns[i]);
183+
}
174184
}
175185
} else {
176-
styleguidePatterns = patternlab.patterns;
186+
styleguidePatterns = patternlab.patterns;
177187
}
178188

179189
//build the styleguide
@@ -187,7 +197,10 @@ var patternlab_engine = function () {
187197

188198
for (i = 0; i < patternlab.patterns.length; i++) {
189199
// skip underscore-prefixed files
190-
if (path.basename(patternlab.patterns[i].abspath).charAt(0) === '_') {
200+
if(isPatternExcluded(patternlab.patterns[i])){
201+
if(patternlab.config.debug){
202+
console.log('Omitting ' + patternlab.patterns[i].key + " from view all rendering.");
203+
}
191204
continue;
192205
}
193206

@@ -203,6 +216,14 @@ var patternlab_engine = function () {
203216

204217
for (j = 0; j < patternlab.patterns.length; j++) {
205218
if (patternlab.patterns[j].subdir === pattern.subdir) {
219+
//again, skip any sibling patterns to the current one that may have underscores
220+
if(isPatternExcluded(patternlab.patterns[j])){
221+
if(patternlab.config.debug){
222+
console.log('Omitting ' + patternlab.patterns[j].key + " from view all sibling rendering.");
223+
}
224+
continue;
225+
}
226+
206227
viewAllPatterns.push(patternlab.patterns[j]);
207228
}
208229
}
@@ -231,17 +252,19 @@ var patternlab_engine = function () {
231252
//loop through all patterns.to build the navigation
232253
//todo: refactor this someday
233254
for(var i = 0; i < patternlab.patterns.length; i++){
234-
// skip underscore-prefixed files
235-
if (path.basename(patternlab.patterns[i].abspath).charAt(0) === '_') {
236-
continue;
237-
}
238255

239256
var pattern = patternlab.patterns[i];
240257
var bucketName = pattern.name.replace(/\\/g, '-').split('-')[1];
241258

242259
//check if the bucket already exists
243260
var bucketIndex = patternlab.bucketIndex.indexOf(bucketName);
244261
if(bucketIndex === -1){
262+
263+
// skip underscore-prefixed files. don't create a bucket on account of an underscored pattern
264+
if(isPatternExcluded(pattern)){
265+
continue;
266+
}
267+
245268
//add the bucket
246269
var bucket = new of.oBucket(bucketName);
247270

@@ -333,30 +356,39 @@ var patternlab_engine = function () {
333356
//if it is flat - we should not add the pattern to patternPaths
334357
if(flatPatternItem){
335358

359+
// skip underscore-prefixed files
360+
if(isPatternExcluded(pattern)){
361+
continue;
362+
}
363+
336364
//add the navItem to patternItems
337365
bucket.patternItems.push(navSubItem);
338366

339367
//add to patternPaths
340368
addToPatternPaths(bucketName, pattern);
341369

342370
} else{
343-
//check to see if navItem exists
344-
var navItemIndex = bucket.navItemsIndex.indexOf(navItemName);
345-
if(navItemIndex === -1){
346-
347-
var navItem = new of.oNavItem(navItemName);
348-
349-
//add the navItem and navSubItem
350-
navItem.navSubItems.push(navSubItem);
351-
navItem.navSubItemsIndex.push(navSubItemName);
352-
bucket.navItems.push(navItem);
353-
bucket.navItemsIndex.push(navItemName);
354-
355-
} else{
356-
//add the navSubItem
357-
var navItem = bucket.navItems[navItemIndex];
358-
navItem.navSubItems.push(navSubItem);
359-
navItem.navSubItemsIndex.push(navSubItemName);
371+
372+
// only do this if pattern is included
373+
if(!isPatternExcluded(pattern)){
374+
//check to see if navItem exists
375+
var navItemIndex = bucket.navItemsIndex.indexOf(navItemName);
376+
if(navItemIndex === -1){
377+
378+
var navItem = new of.oNavItem(navItemName);
379+
380+
//add the navItem and navSubItem
381+
navItem.navSubItems.push(navSubItem);
382+
navItem.navSubItemsIndex.push(navSubItemName);
383+
bucket.navItems.push(navItem);
384+
bucket.navItemsIndex.push(navItemName);
385+
386+
} else{
387+
//add the navSubItem
388+
var navItem = bucket.navItems[navItemIndex];
389+
navItem.navSubItems.push(navSubItem);
390+
navItem.navSubItemsIndex.push(navSubItemName);
391+
}
360392
}
361393

362394
//add the navViewAllSubItem
@@ -414,6 +446,12 @@ var patternlab_engine = function () {
414446
patternlab.patternPaths[bucketName][pattern.patternName] = pattern.subdir.replace(/\\/g, '/') + "/" + pattern.fileName;
415447
}
416448

449+
//todo: refactor this as a method on the pattern object itself once we merge dev with pattern-engines branch
450+
function isPatternExcluded(pattern){
451+
// returns whether or not the first character of the pattern filename is an underscore, or excluded
452+
return pattern.fileName.charAt(0) === '_';
453+
}
454+
417455
return {
418456
version: function(){
419457
return getVersion();

builder/patternlab_grunt.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)