1
+ var makeDocMapInfo = require ( "./doc-map-info" ) ;
2
+
1
3
module . exports = function ( docMap , config , getCurrent , oldHelpers , OtherHandlebars ) {
4
+ var docMapInfo = makeDocMapInfo ( docMap ) ;
2
5
3
6
var lastPartOfName = function ( str ) {
4
7
var lastIndex = Math . max ( str . lastIndexOf ( "/" ) , str . lastIndexOf ( "." ) ) ;
@@ -78,6 +81,11 @@ module.exports = function(docMap, config, getCurrent, oldHelpers, OtherHandlebar
78
81
79
82
// GENERIC HELPERS
80
83
var helpers = {
84
+ makeChildrenContext : function ( docObject ) {
85
+ var children = docMapInfo . getChildren ( docObject ) || [ ] ;
86
+ return { children : children } ;
87
+ } ,
88
+
81
89
/**
82
90
* @function documentjs.generators.html.defaultHelpers.ifEqual
83
91
*/
@@ -148,35 +156,38 @@ module.exports = function(docMap, config, getCurrent, oldHelpers, OtherHandlebar
148
156
*/
149
157
generatedWarning : function ( ) {
150
158
var current = getCurrent ( ) ;
151
- return "<!--####################################################################\n" +
152
- "\tTHIS IS A GENERATED FILE -- ANY CHANGES MADE WILL BE OVERWRITTEN\n\n" +
153
- '\tINSTEAD CHANGE:\n' +
154
- "\tsource: " + current . src +
155
- ( current . type ? '\n\t@' + current . type + " " + current . name : '' ) +
156
- "\n######################################################################## -->" ;
159
+
160
+ return (
161
+ "<!--####################################################################\n" +
162
+ "\tTHIS IS A GENERATED FILE -- ANY CHANGES MADE WILL BE OVERWRITTEN\n\n" +
163
+ "\tINSTEAD CHANGE:\n" +
164
+ "\tsource: " + current . src + ( current . type ? '\n\t@' + current . type + " " + current . name : '' ) +
165
+ "\n######################################################################## -->"
166
+ ) ;
157
167
} ,
158
168
159
169
getParentsPathToSelf : function ( name ) {
160
170
var names = { } ;
161
171
162
172
// walk up parents until you don't have a parent
163
- var parent = docMap [ name ] ,
164
- parents = [ ] ;
173
+ var parent = docMap [ name ] ;
174
+ var parents = [ ] ;
175
+
176
+ // don't allow things that are their own parent
177
+ if ( parent . parent === name ) {
178
+ return parents ;
179
+ }
165
180
166
- // don't allow things that are their own parent
167
- if ( parent . parent === name ) {
181
+ while ( parent ) {
182
+ parents . unshift ( parent ) ;
183
+ if ( names [ parent . name ] ) {
168
184
return parents ;
169
185
}
186
+ names [ parent . name ] = true ;
187
+ parent = docMap [ parent . parent ] ;
188
+ }
170
189
171
- while ( parent ) {
172
- parents . unshift ( parent ) ;
173
- if ( names [ parent . name ] ) {
174
- return parents ;
175
- }
176
- names [ parent . name ] = true ;
177
- parent = docMap [ parent . parent ] ;
178
- }
179
- return parents ;
190
+ return parents ;
180
191
} ,
181
192
/**
182
193
* @function documentjs.generators.html.defaultHelpers.makeTitle
@@ -420,23 +431,27 @@ module.exports = function(docMap, config, getCurrent, oldHelpers, OtherHandlebar
420
431
* where `parents` is each parent docObject of the `current` docObject and
421
432
* `active` is the first docObject of current that has children.
422
433
*/
423
- getActiveAndParents : function ( options ) {
434
+ getActiveAndParents : function ( options ) {
424
435
var parents = helpers . getParentsPathToSelf ( getCurrent ( ) . name ) ;
425
436
var active = parents . pop ( ) ;
426
437
427
- if ( ! active ) {
428
- // there are no parents, possibly nothing active
429
- parents = [ ] ;
430
- active = docMap [ config . parent ] ;
431
- } else if ( ! active . children && parents . length ) {
432
- // we want to show this item along-side it's siblings
433
- // make it's parent active
434
- active = parents . pop ( ) ;
438
+ if ( active ) {
439
+ var children = docMapInfo . getChildren ( active ) || [ ] ;
435
440
436
- // if the original active was in a group, prototype, etc, move up again
437
- if ( parents . length && / g r o u p | p r o t o t y p e | s t a t i c / i. test ( active . type ) ) {
441
+ if ( ! children . length && parents . length ) {
442
+ // we want to show this item along-side its siblings
443
+ // make its parent active
438
444
active = parents . pop ( ) ;
445
+
446
+ // if the original active was in a group, prototype, etc, move up again
447
+ if ( parents . length && / g r o u p | p r o t o t y p e | s t a t i c / i. test ( active . type ) ) {
448
+ active = parents . pop ( ) ;
449
+ }
439
450
}
451
+ } else {
452
+ // there are no parents, possibly nothing active
453
+ parents = [ ] ;
454
+ active = docMap [ config . parent ] ;
440
455
}
441
456
442
457
// remove groups because we don't want them showing up
@@ -445,13 +460,12 @@ module.exports = function(docMap, config, getCurrent, oldHelpers, OtherHandlebar
445
460
} ) ;
446
461
447
462
// Make sure root is always here
448
- if ( active . name !== config . parent && ( ! parents . length || parents [ 0 ] . name !== config . parent ) ) {
463
+ if ( active . name !== config . parent &&
464
+ ( ! parents . length || parents [ 0 ] . name !== config . parent ) ) {
449
465
parents . unshift ( docMap [ config . parent ] ) ;
450
466
}
451
- return options . fn ( {
452
- parents : parents ,
453
- active : active
454
- } ) ;
467
+
468
+ return options . fn ( { parents : parents , active : active } ) ;
455
469
} ,
456
470
/**
457
471
* @function documentjs.generators.html.defaultHelpers.eachFirstLevelChildren
@@ -470,7 +484,7 @@ module.exports = function(docMap, config, getCurrent, oldHelpers, OtherHandlebar
470
484
*
471
485
* Goes through each `children` in the sorted order.
472
486
*/
473
- eachOrderedChildren : function ( children , options ) {
487
+ eachOrderedChildren : function ( children , options ) {
474
488
children = ( children || [ ] ) . slice ( 0 ) . sort ( sortChildren ) ;
475
489
var res = "" ;
476
490
children . forEach ( function ( child ) {
0 commit comments