@@ -7,8 +7,8 @@ var template = require('jsdoc/template'),
77 handle = require ( 'jsdoc/util/error' ) . handle ,
88 helper = require ( 'jsdoc/util/templateHelper' ) ,
99 logger = require ( 'jsdoc/util/logger' ) ,
10- typeLinks = require ( './typeLinkExt' ) . typeLinks ,
11-
10+ typeLinks = require ( './typeLinkExt' ) . typeLinks ,
11+
1212 _ = require ( 'underscore' ) ,
1313 htmlsafe = helper . htmlsafe ,
1414 linkto = helper . linkto ,
@@ -19,21 +19,28 @@ var template = require('jsdoc/template'),
1919 view ,
2020 language ,
2121 outdir = env . opts . destination ;
22- var util = require ( 'util' ) ;
22+ var util = require ( 'util' ) ;
23+
2324function find ( spec ) {
2425 return helper . find ( data , spec ) ;
2526}
2627
2728function tutoriallink ( tutorial ) {
28- return helper . toTutorial ( tutorial , null , { tag : 'em' , classname : 'disabled' , prefix : 'Tutorial: ' } ) ;
29+ return helper . toTutorial ( tutorial , null , {
30+ tag : 'em' ,
31+ classname : 'disabled' ,
32+ prefix : 'Tutorial: '
33+ } ) ;
2934}
3035
3136function getAncestorLinks ( doclet ) {
3237 return helper . getAncestorLinks ( data , doclet ) ;
3338}
3439
3540function hashToLink ( doclet , hash ) {
36- if ( ! / ^ ( # .+ ) / . test ( hash ) ) { return hash ; }
41+ if ( ! / ^ ( # .+ ) / . test ( hash ) ) {
42+ return hash ;
43+ }
3744
3845 var url = helper . createLink ( doclet ) ;
3946
@@ -111,6 +118,7 @@ function getPathFromDoclet(doclet) {
111118
112119 return filepath ;
113120}
121+
114122function generateNav ( navObject ) {
115123
116124 // var docData = {
@@ -131,14 +139,17 @@ function generateNav(navObject) {
131139
132140 fs . writeFileSync ( outpath , html , 'utf8' ) ;
133141}
142+
134143function generate ( title , docs , filename , resolveLinks ) {
135144 resolveLinks = resolveLinks === false ? false : true ;
136145
137146 var docData = {
138147 filename : filename ,
139148 title : title ,
140149 docs : docs ,
141- packageInfo : ( find ( { kind : 'package' } ) || [ ] ) [ 0 ]
150+ packageInfo : ( find ( {
151+ kind : 'package'
152+ } ) || [ ] ) [ 0 ]
142153 } ;
143154
144155 var outpath = path . join ( outdir , filename ) ,
@@ -150,6 +161,7 @@ function generate(title, docs, filename, resolveLinks) {
150161
151162 fs . writeFileSync ( outpath , html , 'utf8' ) ;
152163}
164+
153165function getCustomTagValue ( item , title ) {
154166 var tags = item . tags ;
155167 if ( ! tags || ! tags . length ) {
@@ -162,6 +174,7 @@ function getCustomTagValue(item, title) {
162174 }
163175 return null ;
164176}
177+
165178function generateSourceFiles ( sourceFiles ) {
166179 Object . keys ( sourceFiles ) . forEach ( function ( file ) {
167180 var source ;
@@ -174,8 +187,7 @@ function generateSourceFiles(sourceFiles) {
174187 kind : 'source' ,
175188 code : helper . htmlsafe ( fs . readFileSync ( sourceFiles [ file ] . resolved , 'utf8' ) )
176189 } ;
177- }
178- catch ( e ) {
190+ } catch ( e ) {
179191 handle ( e ) ;
180192 }
181193
@@ -237,37 +249,29 @@ function sortNav(members) {
237249 } ) ;
238250 return merged ;
239251}
252+
240253function buildCategories ( members , templatePath ) {
241254 var categories = { } ;
242- if ( language === 'en' ) {
243- var exists = fs . existsSync ( path . resolve ( templatePath , "categories.json" ) ) ;
244- if ( exists ) {
245- categories = JSON . parse ( fs . readFileSync ( path . resolve ( templatePath , "categories.json" ) ) ) ;
246- } else {
247- logger . error ( 'Please generate a Chinese JSdoc first' )
255+ _ . each ( members , function ( v ) {
256+
257+ var category = getCustomTagValue ( v , 'category' ) ;
258+ if ( ! category ) {
259+ category = "BaseTypes" ;
248260 }
249- } else {
250- _ . each ( members , function ( v ) {
251-
252- var category = getCustomTagValue ( v , 'category' ) ;
253- if ( ! category ) {
254- category = "BaseTypes" ;
261+ var arr = category . split ( " " ) ;
262+ var aa = categories ;
263+ for ( let index = 0 ; index < arr . length ; index ++ ) {
264+ const element = arr [ index ] ;
265+ if ( ! aa [ element ] ) {
266+ aa [ element ] = { } ;
267+ aa [ element ] . default = [ ] ;
255268 }
256- var arr = category . split ( " " ) ;
257- var aa = categories ;
258- for ( let index = 0 ; index < arr . length ; index ++ ) {
259- const element = arr [ index ] ;
260- if ( ! aa [ element ] ) {
261- aa [ element ] = { } ;
262- aa [ element ] . default = [ ] ;
263- }
264- aa = aa [ element ] ;
265- }
266- aa . default . push ( v . longname ) ;
267- } ) ;
268- var outpath = path . resolve ( templatePath , "categories.json" ) ;
269- fs . writeFileSync ( outpath , JSON . stringify ( categories ) , 'utf8' ) ;
270- }
269+ aa = aa [ element ] ;
270+ }
271+ aa . default . push ( v . longname ) ;
272+ } ) ;
273+ var outpath = path . resolve ( templatePath , "categories.json" ) ;
274+ fs . writeFileSync ( outpath , JSON . stringify ( categories ) , 'utf8' ) ;
271275 return categories ;
272276}
273277
@@ -366,7 +370,7 @@ exports.publish = function (taffyData, opts, tutorials) {
366370
367371 var globalUrl = helper . getUniqueFilename ( 'global' ) ;
368372 helper . registerLink ( 'global' , globalUrl ) ;
369- view . typeLinks = typeLinks ;
373+ view . typeLinks = typeLinks ;
370374 // set up templating
371375 view . layout = 'layout.tmpl' ;
372376
@@ -417,7 +421,9 @@ exports.publish = function (taffyData, opts, tutorials) {
417421 }
418422 } ) ;
419423 // update outdir if necessary, then create outdir
420- var packageInfo = ( find ( { kind : 'package' } ) || [ ] ) [ 0 ] ;
424+ var packageInfo = ( find ( {
425+ kind : 'package'
426+ } ) || [ ] ) [ 0 ] ;
421427 if ( packageInfo && packageInfo . name ) {
422428 outdir = path . join ( outdir , packageInfo . name , packageInfo . version ) ;
423429 }
@@ -439,8 +445,8 @@ exports.publish = function (taffyData, opts, tutorials) {
439445 var staticFileScanner ;
440446 if ( conf [ 'default' ] . staticFiles ) {
441447 staticFilePaths = conf [ 'default' ] . staticFiles . paths || [ ] ;
442- staticFileFilter = new ( require ( 'jsdoc/src/filter' ) ) . Filter ( conf [ 'default' ] . staticFiles ) ;
443- staticFileScanner = new ( require ( 'jsdoc/src/scanner' ) ) . Scanner ( ) ;
448+ staticFileFilter = new ( require ( 'jsdoc/src/filter' ) ) . Filter ( conf [ 'default' ] . staticFiles ) ;
449+ staticFileScanner = new ( require ( 'jsdoc/src/scanner' ) ) . Scanner ( ) ;
444450
445451 staticFilePaths . forEach ( function ( filePath ) {
446452 var extraStaticFiles = staticFileScanner . scan ( [ filePath ] , 10 , staticFileFilter ) ;
@@ -478,8 +484,7 @@ exports.publish = function (taffyData, opts, tutorials) {
478484
479485 if ( url . indexOf ( '#' ) > - 1 ) {
480486 doclet . id = helper . longnameToUrl [ doclet . longname ] . split ( / # / ) . pop ( ) ;
481- }
482- else {
487+ } else {
483488 doclet . id = doclet . name ;
484489 }
485490
@@ -491,7 +496,7 @@ exports.publish = function (taffyData, opts, tutorials) {
491496
492497 // do this after the urls have all been generated
493498 data ( ) . each ( function ( doclet ) {
494-
499+
495500 doclet . ancestors = getAncestorLinks ( doclet ) ;
496501 if ( doclet . kind === 'member' ) {
497502 addSignatureTypes ( doclet ) ;
@@ -501,7 +506,7 @@ exports.publish = function (taffyData, opts, tutorials) {
501506 addSignatureTypes ( doclet ) ;
502507 var attribs = helper . getAttribs ( doclet ) ;
503508 var attribsString = buildAttribsString ( attribs ) ;
504-
509+
505510 doclet . attribs = util . format ( '<span class="type-signature">%s</span>' , attribsString ) ;
506511 doclet . kind = 'member' ;
507512 }
@@ -529,7 +534,12 @@ exports.publish = function (taffyData, opts, tutorials) {
529534 view . navOrder = JSON . parse ( fs . readFileSync ( path . resolve ( templatePath , "./config.json" ) ) ) ;
530535 view . language = language ;
531536 generateNav ( view . nav ) ;
532- attachModuleSymbols ( find ( { kind : [ 'class' , 'function' ] , longname : { left : 'module:' } } ) ,
537+ attachModuleSymbols ( find ( {
538+ kind : [ 'class' , 'function' ] ,
539+ longname : {
540+ left : 'module:'
541+ }
542+ } ) ,
533543 members . modules ) ;
534544
535545 // only output pretty-printed source files if requested; do this before generating any other
@@ -538,13 +548,22 @@ exports.publish = function (taffyData, opts, tutorials) {
538548 generateSourceFiles ( sourceFiles ) ;
539549 }
540550
541- if ( members . globals . length ) { generate ( 'Global' , [ { kind : 'globalobj' } ] , globalUrl ) ; }
551+ if ( members . globals . length ) {
552+ generate ( 'Global' , [ {
553+ kind : 'globalobj'
554+ } ] , globalUrl ) ;
555+ }
542556
543557 // index page displays information from package.json and lists files
544- var files = find ( { kind : 'file' } ) ;
558+ var files = find ( {
559+ kind : 'file'
560+ } ) ;
545561
546- generate ( 'Index' ,
547- [ { kind : 'mainpage' , readme : opts . readme , longname : ( opts . mainpagetitle ) ? opts . mainpagetitle : 'Main Page' } ] . concat ( files ) ,
562+ generate ( 'Index' , [ {
563+ kind : 'mainpage' ,
564+ readme : opts . readme ,
565+ longname : ( opts . mainpagetitle ) ? opts . mainpagetitle : 'Main Page'
566+ } ] . concat ( files ) ,
548567 indexUrl ) ;
549568
550569 // set up the lists that we'll use to generate pages
@@ -556,27 +575,37 @@ exports.publish = function (taffyData, opts, tutorials) {
556575
557576 for ( var longname in helper . longnameToUrl ) {
558577 if ( hasOwnProp . call ( helper . longnameToUrl , longname ) ) {
559- var myClasses = helper . find ( classes , { longname : longname } ) ;
578+ var myClasses = helper . find ( classes , {
579+ longname : longname
580+ } ) ;
560581 if ( myClasses . length ) {
561582 generate ( 'Class: ' + myClasses [ 0 ] . name , myClasses , helper . longnameToUrl [ longname ] ) ;
562583 }
563584
564- var myModules = helper . find ( modules , { longname : longname } ) ;
585+ var myModules = helper . find ( modules , {
586+ longname : longname
587+ } ) ;
565588 if ( myModules . length ) {
566589 generate ( 'Module: ' + myModules [ 0 ] . name , myModules , helper . longnameToUrl [ longname ] ) ;
567590 }
568591
569- var myNamespaces = helper . find ( namespaces , { longname : longname } ) ;
592+ var myNamespaces = helper . find ( namespaces , {
593+ longname : longname
594+ } ) ;
570595 if ( myNamespaces . length ) {
571596 generate ( 'Namespace: ' + myNamespaces [ 0 ] . name , myNamespaces , helper . longnameToUrl [ longname ] ) ;
572597 }
573598
574- var myMixins = helper . find ( mixins , { longname : longname } ) ;
599+ var myMixins = helper . find ( mixins , {
600+ longname : longname
601+ } ) ;
575602 if ( myMixins . length ) {
576603 generate ( 'Mixin: ' + myMixins [ 0 ] . name , myMixins , helper . longnameToUrl [ longname ] ) ;
577604 }
578605
579- var myExternals = helper . find ( externals , { longname : longname } ) ;
606+ var myExternals = helper . find ( externals , {
607+ longname : longname
608+ } ) ;
580609 if ( myExternals . length ) {
581610 generate ( 'External: ' + myExternals [ 0 ] . name , myExternals , helper . longnameToUrl [ longname ] ) ;
582611 }
@@ -609,13 +638,14 @@ exports.publish = function (taffyData, opts, tutorials) {
609638 } ) ;
610639 }
611640 saveChildren ( tutorials ) ;
641+
612642 function buildAttribsString ( attribs ) {
613643 var attribsString = '' ;
614-
644+
615645 if ( attribs && attribs . length ) {
616- attribsString = htmlsafe ( util . format ( '(%s) ' , attribs . join ( ', ' ) ) ) ;
646+ attribsString = htmlsafe ( util . format ( '(%s) ' , attribs . join ( ', ' ) ) ) ;
617647 }
618-
648+
619649 return attribsString ;
620650 }
621- } ;
651+ } ;
0 commit comments