1
- /*
2
- * patternlab-node - v1.1.2 - 2016
3
- *
1
+ /*
2
+ * patternlab-node - v1.1.2 - 2016
3
+ *
4
4
* 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.
8
8
*
9
9
*/
10
10
@@ -207,7 +207,8 @@ var patternlab_engine = function (config) {
207
207
208
208
//build the viewall pages
209
209
var prevSubdir = '' ,
210
- i ;
210
+ prevGroup = '' ,
211
+ i ;
211
212
212
213
for ( i = 0 ; i < patternlab . patterns . length ; i ++ ) {
213
214
// skip underscore-prefixed files
@@ -220,6 +221,35 @@ var patternlab_engine = function (config) {
220
221
221
222
var pattern = patternlab . patterns [ i ] ;
222
223
224
+ //create the view all for the section
225
+ // check if the current section is different from the previous one
226
+ if ( pattern . patternGroup != prevGroup ) {
227
+ prevGroup = pattern . patternGroup ;
228
+
229
+ var viewAllPatterns = [ ] ,
230
+ patternPartial = "viewall-" + pattern . patternGroup ,
231
+ j ;
232
+
233
+ for ( j = 0 ; j < patternlab . patterns . length ; j ++ ) {
234
+ if ( patternlab . patterns [ j ] . patternGroup === pattern . patternGroup ) {
235
+ //again, skip any sibling patterns to the current one that may have underscores
236
+ if ( isPatternExcluded ( patternlab . patterns [ j ] ) ) {
237
+ if ( patternlab . config . debug ) {
238
+ console . log ( 'Omitting ' + patternlab . patterns [ j ] . key + " from view all sibling rendering." ) ;
239
+ }
240
+ continue ;
241
+ }
242
+
243
+ viewAllPatterns . push ( patternlab . patterns [ j ] ) ;
244
+ }
245
+ }
246
+
247
+ var viewAllTemplate = fs . readFileSync ( path . resolve ( paths . source . patternlabFiles , 'viewall.mustache' ) , 'utf8' ) ;
248
+ var viewAllHtml = pattern_assembler . renderPattern ( viewAllTemplate , { partials : viewAllPatterns , patternPartial : patternPartial } ) ;
249
+ fs . outputFileSync ( paths . public . patterns + pattern . subdir . slice ( 0 , pattern . subdir . indexOf ( pattern . patternGroup ) + pattern . patternGroup . length ) + '/index.html' , viewAllHtml ) ;
250
+ }
251
+
252
+ //create the view all for the subsection
223
253
// check if the current sub section is different from the previous one
224
254
if ( pattern . subdir !== prevSubdir ) {
225
255
prevSubdir = pattern . subdir ;
@@ -318,6 +348,14 @@ var patternlab_engine = function (config) {
318
348
//add to patternPaths
319
349
addToPatternPaths ( bucketName , pattern ) ;
320
350
351
+ //add the navViewAllItem
352
+ var navViewAllItem = new of . oNavSubItem ( "View All" ) ;
353
+ navViewAllItem . patternPath = pattern . subdir . slice ( 0 , pattern . subdir . indexOf ( pattern . patternGroup ) + pattern . patternGroup . length ) + "/index.html" ;
354
+ navViewAllItem . patternPartial = "viewall-" + pattern . patternGroup ;
355
+
356
+ bucket . patternItems . push ( navViewAllItem ) ;
357
+ patternlab . viewAllPaths [ bucketName ] [ 'viewall' ] = pattern . subdir . slice ( 0 , pattern . subdir . indexOf ( pattern . patternGroup ) + pattern . patternGroup . length ) ;
358
+
321
359
}
322
360
323
361
//add the bucket.
@@ -393,14 +431,15 @@ var patternlab_engine = function (config) {
393
431
}
394
432
}
395
433
396
- //add the navViewAllSubItem
397
- var navViewAllSubItem = new of . oNavSubItem ( "" ) ;
398
- navViewAllSubItem . patternName = "View All" ;
399
- navViewAllSubItem . patternPath = pattern . flatPatternPath + "/index.html" ;
400
- navViewAllSubItem . patternPartial = "viewall-" + pattern . patternGroup + "-" + pattern . patternSubGroup ;
401
-
402
434
//check if we are moving to a new sub section in the next loop
403
435
if ( ! patternlab . patterns [ i + 1 ] || pattern . patternSubGroup !== patternlab . patterns [ i + 1 ] . patternSubGroup ) {
436
+
437
+ //add the navViewAllSubItem
438
+ var navViewAllSubItem = new of . oNavSubItem ( "" ) ;
439
+ navViewAllSubItem . patternName = "View All" ;
440
+ navViewAllSubItem . patternPath = pattern . flatPatternPath + "/index.html" ;
441
+ navViewAllSubItem . patternPartial = "viewall-" + pattern . patternGroup + "-" + pattern . patternSubGroup ;
442
+
404
443
navItem . navSubItems . push ( navViewAllSubItem ) ;
405
444
navItem . navSubItemsIndex . push ( "View All" ) ;
406
445
}
0 commit comments