@@ -11,6 +11,9 @@ var eol = require('os').EOL;
11
11
12
12
function addToPatternPaths ( patternlab , patternTypeName , pattern ) {
13
13
//this is messy, could use a refactor.
14
+ if ( ! patternlab . patternPaths [ patternTypeName ] ) {
15
+ patternlab . patternPaths [ patternTypeName ] = { } ;
16
+ }
14
17
patternlab . patternPaths [ patternTypeName ] [ pattern . patternBaseName ] = pattern . subdir . replace ( / \\ / g, '/' ) + "/" + pattern . fileName . replace ( '~' , '-' ) ;
15
18
}
16
19
@@ -29,31 +32,52 @@ function assembleStyleguidePatterns(patternlab) {
29
32
if ( styleguideExcludes && styleguideExcludes . length ) {
30
33
for ( var i = 0 ; i < patternlab . patterns . length ; i ++ ) {
31
34
35
+ var pattern = patternlab . patterns [ i ] ;
36
+
32
37
// skip underscore-prefixed files
33
- if ( isPatternExcluded ( patternlab . patterns [ i ] ) ) {
38
+ if ( isPatternExcluded ( pattern ) ) {
34
39
if ( patternlab . config . debug ) {
35
- console . log ( 'Omitting ' + patternlab . patterns [ i ] . patternPartial + " from styleguide pattern exclusion." ) ;
40
+ console . log ( 'Omitting ' + pattern . patternPartial + " from styleguide pattern exclusion." ) ;
36
41
}
37
42
continue ;
38
43
}
39
44
40
- var partial = patternlab . patterns [ i ] . patternPartial ;
45
+ //this is meant to be a homepage that is not present anywhere else
46
+ if ( pattern . patternPartial === patternlab . config . defaultPattern ) {
47
+ if ( patternlab . config . debug ) {
48
+ console . log ( 'omitting ' + pattern . patternPartial + ' from styleguide patterns because it is defined as a defaultPattern' ) ;
49
+ }
50
+ continue ;
51
+ }
52
+
53
+ var partial = pattern . patternPartial ;
41
54
var partialType = partial . substring ( 0 , partial . indexOf ( '-' ) ) ;
42
55
var isExcluded = ( styleguideExcludes . indexOf ( partialType ) > - 1 ) ;
43
56
if ( ! isExcluded ) {
44
- styleguidePatterns . push ( patternlab . patterns [ i ] ) ;
57
+ styleguidePatterns . push ( pattern ) ;
45
58
}
46
59
}
47
60
} else {
48
61
for ( i = 0 ; i < patternlab . patterns . length ; i ++ ) {
62
+ var pattern = patternlab . patterns [ i ] ;
63
+
49
64
// skip underscore-prefixed files
50
- if ( isPatternExcluded ( patternlab . patterns [ i ] ) ) {
65
+ if ( isPatternExcluded ( pattern ) ) {
51
66
if ( patternlab . config . debug ) {
52
- console . log ( 'Omitting ' + patternlab . patterns [ i ] . patternPartial + " from styleguide pattern exclusion." ) ;
67
+ console . log ( 'Omitting ' + pattern . patternPartial + " from styleguide pattern exclusion." ) ;
53
68
}
54
69
continue ;
55
70
}
56
- styleguidePatterns . push ( patternlab . patterns [ i ] ) ;
71
+
72
+ //this is meant to be a homepage that is not present anywhere else
73
+ if ( pattern . patternPartial === patternlab . config . defaultPattern ) {
74
+ if ( patternlab . config . debug ) {
75
+ console . log ( 'omitting ' + pattern . patternPartial + ' from styleguide patterns because it is defined as a defaultPattern' ) ;
76
+ }
77
+ continue ;
78
+ }
79
+
80
+ styleguidePatterns . push ( pattern ) ;
57
81
}
58
82
}
59
83
@@ -68,6 +92,19 @@ function buildNavigation(patternlab) {
68
92
//todo: check if this is already available
69
93
var patternTypeName = pattern . name . replace ( / \\ / g, '-' ) . split ( '-' ) [ 1 ] ;
70
94
95
+ //exclude any named defaultPattern from the navigation.
96
+ //this is meant to be a homepage that is not navigable
97
+ if ( pattern . patternPartial === patternlab . config . defaultPattern ) {
98
+ if ( patternlab . config . debug ) {
99
+ console . log ( 'omitting ' + pattern . patternPartial + ' from navigation because it is defined as a defaultPattern' ) ;
100
+ }
101
+
102
+ //add to patternPaths before continuing
103
+ addToPatternPaths ( patternlab , patternTypeName , pattern ) ;
104
+
105
+ continue ;
106
+ }
107
+
71
108
// skip underscore-prefixed files. don't create a patternType on account of an underscored pattern
72
109
if ( isPatternExcluded ( pattern ) ) {
73
110
continue ;
@@ -101,7 +138,7 @@ function buildNavigation(patternlab) {
101
138
var patternType = new of . oPatternType ( patternTypeName ) ;
102
139
103
140
//add patternPath and viewAllPath
104
- patternlab . patternPaths [ patternTypeName ] = { } ;
141
+ patternlab . patternPaths [ patternTypeName ] = patternlab . patternPaths [ patternTypeName ] || { } ;
105
142
patternlab . viewAllPaths [ patternTypeName ] = { } ;
106
143
107
144
//test whether the pattern structure is flat or not - usually due to a template or page
@@ -246,15 +283,24 @@ function buildViewAllPages(mainPageHeadHtml, patternlab) {
246
283
var i ;
247
284
248
285
for ( i = 0 ; i < patternlab . patterns . length ; i ++ ) {
286
+
287
+ var pattern = patternlab . patterns [ i ] ;
288
+
249
289
// skip underscore-prefixed files
250
- if ( isPatternExcluded ( patternlab . patterns [ i ] ) ) {
290
+ if ( isPatternExcluded ( pattern ) ) {
251
291
if ( patternlab . config . debug ) {
252
- console . log ( 'Omitting ' + patternlab . patterns [ i ] . patternPartial + " from view all rendering." ) ;
292
+ console . log ( 'Omitting ' + pattern . patternPartial + " from view all rendering." ) ;
253
293
}
254
294
continue ;
255
295
}
256
296
257
- var pattern = patternlab . patterns [ i ] ;
297
+ //this is meant to be a homepage that is not present anywhere else
298
+ if ( pattern . patternPartial === patternlab . config . defaultPattern ) {
299
+ if ( patternlab . config . debug ) {
300
+ console . log ( 'Omitting ' + pattern . patternPartial + ' from view all rendering because it is defined as a defaultPattern' ) ;
301
+ }
302
+ continue ;
303
+ }
258
304
259
305
//create the view all for the section
260
306
// check if the current section is different from the previous one
@@ -275,6 +321,14 @@ function buildViewAllPages(mainPageHeadHtml, patternlab) {
275
321
continue ;
276
322
}
277
323
324
+ //this is meant to be a homepage that is not present anywhere else
325
+ if ( patternlab . patterns [ j ] . patternPartial === patternlab . config . defaultPattern ) {
326
+ if ( patternlab . config . debug ) {
327
+ console . log ( 'Omitting ' + pattern . patternPartial + ' from view all sibling rendering because it is defined as a defaultPattern' ) ;
328
+ }
329
+ continue ;
330
+ }
331
+
278
332
viewAllPatterns . push ( patternlab . patterns [ j ] ) ;
279
333
}
280
334
}
@@ -306,6 +360,14 @@ function buildViewAllPages(mainPageHeadHtml, patternlab) {
306
360
continue ;
307
361
}
308
362
363
+ //this is meant to be a homepage that is not present anywhere else
364
+ if ( patternlab . patterns [ j ] . patternPartial === patternlab . config . defaultPattern ) {
365
+ if ( patternlab . config . debug ) {
366
+ console . log ( 'Omitting ' + pattern . patternPartial + ' from view all sibling rendering because it is defined as a defaultPattern' ) ;
367
+ }
368
+ continue ;
369
+ }
370
+
309
371
viewAllPatterns . push ( patternlab . patterns [ j ] ) ;
310
372
}
311
373
}
@@ -428,11 +490,17 @@ function buildFrontEnd(patternlab) {
428
490
429
491
//plugins someday
430
492
output += 'var plugins = [];' + eol ;
493
+
494
+ //smaller config elements
495
+ output += 'var defaultShowPatternInfo = ' + ( patternlab . config . defaultShowPatternInfo ? patternlab . config . defaultShowPatternInfo : 'false' ) + ';' + eol ;
496
+ output += 'var defaultPattern = "' + ( patternlab . config . defaultPattern ? patternlab . config . defaultPattern : 'all' ) + '";' + eol ;
497
+
498
+ //write all ouytput to patternlab-data
431
499
fs . outputFileSync ( path . resolve ( paths . public . data , 'patternlab-data.js' ) , output ) ;
432
500
433
501
//annotations
434
502
var annotationsJSON = annotation_exporter . gather ( ) ;
435
- var annotations = 'var comments = ' + JSON . stringify ( annotationsJSON ) ;
503
+ var annotations = 'var comments = { "comments" : ' + JSON . stringify ( annotationsJSON ) + '};' ;
436
504
fs . outputFileSync ( path . resolve ( paths . public . annotations , 'annotations.js' ) , annotations ) ;
437
505
438
506
}
0 commit comments