1- /*
2- * patternlab-node - v1.1.2 - 2016
3- *
1+ /*
2+ * patternlab-node - v1.1.2 - 2016
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
@@ -207,7 +207,8 @@ var patternlab_engine = function (config) {
207207
208208 //build the viewall pages
209209 var prevSubdir = '' ,
210- i ;
210+ prevGroup = '' ,
211+ i ;
211212
212213 for ( i = 0 ; i < patternlab . patterns . length ; i ++ ) {
213214 // skip underscore-prefixed files
@@ -220,6 +221,35 @@ var patternlab_engine = function (config) {
220221
221222 var pattern = patternlab . patterns [ i ] ;
222223
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
223253 // check if the current sub section is different from the previous one
224254 if ( pattern . subdir !== prevSubdir ) {
225255 prevSubdir = pattern . subdir ;
@@ -318,6 +348,14 @@ var patternlab_engine = function (config) {
318348 //add to patternPaths
319349 addToPatternPaths ( bucketName , pattern ) ;
320350
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+
321359 }
322360
323361 //add the bucket.
@@ -393,14 +431,15 @@ var patternlab_engine = function (config) {
393431 }
394432 }
395433
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-
402434 //check if we are moving to a new sub section in the next loop
403435 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+
404443 navItem . navSubItems . push ( navViewAllSubItem ) ;
405444 navItem . navSubItemsIndex . push ( "View All" ) ;
406445 }
0 commit comments