Skip to content

Commit bcd2ebc

Browse files
committed
Add 'View All' for each subsection in menus and generate required files
1 parent bfe1289 commit bcd2ebc

File tree

3 files changed

+50
-6
lines changed

3 files changed

+50
-6
lines changed

builder/object_factory.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@
1414
var oPattern = function(subdir, filename, data){
1515
this.fileName = filename.substring(0, filename.indexOf('.'));
1616
this.subdir = subdir;
17-
this.name = (subdir.replace(/[\/\\]/g, '-') + '-' + this.fileName).replace(/\\/g, '-'); //this is the unique name with the subDir
17+
this.name = subdir.replace(/[\/\\]/g, '-') + '-' + this.fileName; //this is the unique name with the subDir
1818
this.data = data || null;
1919
this.patternName = this.fileName.substring(this.fileName.indexOf('-') + 1); //this is the display name for the ui
2020
this.patternLink = this.name + '/' + this.name + '.html';
2121
this.patternGroup = this.name.substring(this.name.indexOf('-') + 1, this.name.indexOf('-', 4) + 1 - this.name.indexOf('-') + 1);
2222
this.patternSubGroup = subdir.substring(subdir.indexOf('/') + 4);
23-
this.flatPatternPath = subdir.replace(/\//g, '-');
23+
this.flatPatternPath = subdir.replace(/[\/\\]/g, '-');
2424
this.key = this.patternGroup + '-' + this.patternName;
2525
this.template = '';
2626
this.patternPartial = '';

builder/patternlab.js

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ var patternlab_engine = function(){
7575

7676
//extract some information
7777
var abspath = file.substring(2);
78-
var subdir = path.dirname(path.relative('./source/_patterns', file));
78+
var subdir = path.dirname(path.relative('./source/_patterns', file)).replace('\\', '/');
7979
var filename = path.basename(file);
8080

8181
//ignore _underscored patterns, json (for now), and dotfiles
@@ -208,6 +208,33 @@ var patternlab_engine = function(){
208208
var styleguideHtml = renderPattern(styleguideTemplate, {partials: patternlab.patterns});
209209
fs.outputFileSync('./public/styleguide/html/styleguide.html', styleguideHtml);
210210

211+
//build the viewall pages
212+
var prevSubdir = '',
213+
i;
214+
215+
for (i = 0; i < patternlab.patterns.length; i++) {
216+
var pattern = patternlab.patterns[i];
217+
218+
// check if the current sub section is different from the previous one
219+
if (pattern.subdir !== prevSubdir) {
220+
prevSubdir = pattern.subdir;
221+
222+
var viewAllPatterns = [],
223+
patternPartial = "viewall-" + pattern.patternGroup + "-" + pattern.patternSubGroup,
224+
j;
225+
226+
for (j = 0; j < patternlab.patterns.length; j++) {
227+
if (patternlab.patterns[j].subdir == pattern.subdir) {
228+
viewAllPatterns.push(patternlab.patterns[j]);
229+
}
230+
}
231+
232+
var viewAllTemplate = fs.readFileSync('./source/_patternlab-files/viewall.mustache', 'utf8');
233+
var viewAllHtml = renderPattern(viewAllTemplate, {partials: viewAllPatterns, patternPartial: patternPartial});
234+
fs.outputFileSync('./public/patterns/' + pattern.flatPatternPath + '/index.html', viewAllHtml);
235+
}
236+
}
237+
211238
//build the patternlab website
212239
var patternlabSiteTemplate = fs.readFileSync('./source/_patternlab-files/index.mustache', 'utf8');
213240

@@ -222,8 +249,9 @@ var patternlab_engine = function(){
222249
//add the bucket
223250
var bucket = new of.oBucket(bucketName);
224251

225-
//add paternPath
252+
//add patternPath and viewAllPath
226253
patternlab.patternPaths[bucketName] = {};
254+
patternlab.viewAllPaths[bucketName] = {};
227255

228256
//get the navItem
229257
var navItemName = pattern.subdir.split('-').pop();
@@ -331,12 +359,26 @@ var patternlab_engine = function(){
331359
navItem.navSubItemsIndex.push(navSubItemName);
332360
}
333361

362+
//add the navViewAllSubItem
363+
var navViewAllSubItem = new of.oNavSubItem("");
364+
navViewAllSubItem.patternName = "View All";
365+
navViewAllSubItem.patternPath = pattern.flatPatternPath + "/index.html";
366+
navViewAllSubItem.patternPartial = "viewall-" + pattern.patternGroup + "-" + pattern.patternSubGroup;
367+
368+
//check if we are moving to a new sub section in the next loop
369+
if (pattern.patternSubGroup !== patternlab.patterns[i + 1].patternSubGroup) {
370+
navItem.navSubItems.push(navViewAllSubItem);
371+
navItem.navSubItemsIndex.push("View All");
372+
}
373+
334374
// just add to patternPaths
335375
addToPatternPaths(bucketName, pattern);
336376
}
337377

338378
}
339379

380+
patternlab.viewAllPaths[bucketName][pattern.patternSubGroup] = pattern.flatPatternPath;
381+
340382
}
341383

342384
//the patternlab site requires a lot of partials to be rendered.
@@ -355,14 +397,14 @@ var patternlab_engine = function(){
355397

356398
//viewAllPaths
357399
var viewAllPathsTemplate = fs.readFileSync('./source/_patternlab-files/partials/viewAllPaths.mustache', 'utf8');
358-
var viewAllPathersPartialHtml = renderPattern(viewAllPathsTemplate, {'viewallpaths': JSON.stringify(patternlab.viewAllPaths)});
400+
var viewAllPathsPartialHtml = renderPattern(viewAllPathsTemplate, {'viewallpaths': JSON.stringify(patternlab.viewAllPaths)});
359401

360402
//render the patternlab template, with all partials
361403
var patternlabSiteHtml = renderPattern(patternlabSiteTemplate, {}, {
362404
'ishControls': ishControlsPartialHtml,
363405
'patternNav': patternNavPartialHtml,
364406
'patternPaths': patternPathsPartialHtml,
365-
'viewAllPaths': viewAllPathersPartialHtml
407+
'viewAllPaths': viewAllPathsPartialHtml
366408
});
367409
fs.outputFileSync('./public/index.html', patternlabSiteHtml);
368410
}

source/_patternlab-files/viewall.mustache

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<meta charset="UTF-8">
66
<meta name="viewport" content="width=device-width" />
77
<link rel="stylesheet" href="../../styleguide/css/styleguide.css" media="all" />
8+
<link rel="stylesheet" href="../../styleguide/css/styleguide-specific.css" media="all" />
89
<link rel="stylesheet" href="../../css/style.css" media="all" />
910
</head>
1011
<body class="sg-pattern-list">
@@ -56,6 +57,7 @@
5657
var patternPartial = "{{ patternPartial }}";
5758
var lineage = "";
5859
</script>
60+
<script src="../../styleguide/js/vendor/jwerty.js"></script>
5961
<script src="../../styleguide/js/postmessage.js"></script>
6062
<script src="../../data/annotations.js"></script>
6163
<script src="../../styleguide/js/annotations-pattern.js"></script>

0 commit comments

Comments
 (0)