clean-jsdoc-theme 3.3.4 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. package/.eslintignore +4 -4
  2. package/.eslintrc.js +3 -3
  3. package/.github/ISSUE_TEMPLATE/bug_report.md +43 -43
  4. package/.github/ISSUE_TEMPLATE/feature_request.md +27 -27
  5. package/.github/pull_request_template.md +16 -16
  6. package/.github/workflows/codeql-analysis.yml +67 -67
  7. package/.prettierignore +2 -2
  8. package/.prettierrc +5 -5
  9. package/.stylelintignore +3 -3
  10. package/.stylelintrc +23 -23
  11. package/.travis.yml +30 -30
  12. package/CHANGELOG.md +232 -216
  13. package/CODE_OF_CONDUCT.md +76 -76
  14. package/CODE_OF_CONDUCT_HINDI.md +46 -46
  15. package/CONTRIBUTING.md +24 -24
  16. package/LICENSE +21 -21
  17. package/README.md +439 -546
  18. package/SECURITY.md +21 -21
  19. package/helpers/down-arrow.js +9 -9
  20. package/jsdoc-config.json +62 -60
  21. package/minify.js +48 -0
  22. package/package.json +50 -46
  23. package/publish.js +1131 -1197
  24. package/static/fonts/Inconsolata-Regular.ttf +0 -0
  25. package/static/fonts/OpenSans-Regular.ttf +0 -0
  26. package/static/fonts/WorkSans-Bold.ttf +0 -0
  27. package/static/scripts/core.js +576 -0
  28. package/static/scripts/core.min.js +23 -0
  29. package/static/scripts/resize.js +90 -85
  30. package/static/scripts/search.js +244 -77
  31. package/static/scripts/search.min.js +11 -0
  32. package/static/scripts/third-party/Apache-License-2.0.txt +202 -202
  33. package/static/scripts/third-party/fuse.js +8 -8
  34. package/static/scripts/third-party/hljs-line-num.js +1 -0
  35. package/static/scripts/third-party/hljs.js +1173 -0
  36. package/static/scripts/third-party/popper.js +6 -0
  37. package/static/scripts/third-party/tippy.js +2 -0
  38. package/static/scripts/third-party/tocbot.js +1 -0
  39. package/static/styles/clean-jsdoc-theme-base.css +941 -393
  40. package/static/styles/clean-jsdoc-theme-dark.css +411 -324
  41. package/static/styles/clean-jsdoc-theme-light.css +392 -319
  42. package/static/styles/clean-jsdoc-theme.min.css +1 -0
  43. package/tmpl/augments.tmpl +10 -10
  44. package/tmpl/container.tmpl +190 -189
  45. package/tmpl/details.tmpl +208 -208
  46. package/tmpl/example.tmpl +3 -3
  47. package/tmpl/examples.tmpl +40 -38
  48. package/tmpl/exceptions.tmpl +32 -32
  49. package/tmpl/icons.tmpl +72 -34
  50. package/tmpl/layout.tmpl +146 -165
  51. package/tmpl/mainpage.tmpl +10 -10
  52. package/tmpl/members.tmpl +42 -43
  53. package/tmpl/method.tmpl +139 -140
  54. package/tmpl/mobile-sidebar.tmpl +21 -0
  55. package/tmpl/navbar-actions.tmpl +19 -0
  56. package/tmpl/navbar-menu.tmpl +21 -0
  57. package/tmpl/navbar.tmpl +14 -0
  58. package/tmpl/params.tmpl +124 -124
  59. package/tmpl/properties.tmpl +109 -109
  60. package/tmpl/returns.tmpl +18 -18
  61. package/tmpl/search.tmpl +17 -0
  62. package/tmpl/sidebar-items.tmpl +24 -0
  63. package/tmpl/sidebar-title.tmpl +10 -0
  64. package/tmpl/sidebar.tmpl +9 -0
  65. package/tmpl/source.tmpl +12 -7
  66. package/tmpl/toc.tmpl +4 -0
  67. package/tmpl/tutorial.tmpl +19 -19
  68. package/tmpl/type.tmpl +6 -6
  69. package/helpers/navbarBuilder.js +0 -0
  70. package/static/fonts/MavenPro-Regular.ttf +0 -0
  71. package/static/fonts/Montserrat-Regular.ttf +0 -0
  72. package/static/fonts/Muli-Black.ttf +0 -0
  73. package/static/fonts/OFL-hind.txt +0 -93
  74. package/static/fonts/OFL-montserrat.txt +0 -93
  75. package/static/scripts/fix-code-block.js +0 -53
  76. package/static/scripts/fix-navbar.js +0 -25
  77. package/static/scripts/linenumber.js +0 -25
  78. package/static/scripts/misc.js +0 -217
  79. package/static/scripts/third-party/lang-css.js +0 -2
  80. package/static/scripts/third-party/prettify.js +0 -28
  81. package/static/styles/reset.css +0 -351
  82. package/static/styles/third-party/ionicons.min.css +0 -11
  83. package/static/styles/third-party/prettify-jsdoc.css +0 -111
  84. package/static/styles/third-party/prettify-tomorrow.css +0 -5
package/publish.js CHANGED
@@ -1,1197 +1,1131 @@
1
- /* global env: true */
2
-
3
- var doop = require('jsdoc/util/doop');
4
- var fs = require('jsdoc/fs');
5
- var helper = require('jsdoc/util/templateHelper');
6
- var logger = require('jsdoc/util/logger');
7
- var path = require('jsdoc/path');
8
- var taffy = require('taffydb').taffy;
9
- var template = require('jsdoc/template');
10
- var util = require('util');
11
- var fse = require('fs-extra');
12
-
13
- var htmlsafe = helper.htmlsafe;
14
- var linkto = helper.linkto;
15
- var resolveAuthorLinks = helper.resolveAuthorLinks;
16
- var hasOwnProp = Object.prototype.hasOwnProperty;
17
-
18
- /* prettier-ignore-start */
19
- // eslint-disable-next-line
20
- var themeOpts = (env && env.opts && env.opts['theme_opts']) || {};
21
- /* prettier-ignore-end */
22
-
23
- var data;
24
- var view;
25
- var searchListArray = [];
26
- var haveSearch =
27
- themeOpts.search === undefined ? true : Boolean(themeOpts.search);
28
-
29
- // eslint-disable-next-line no-restricted-globals
30
- var outdir = path.normalize(env.opts.destination);
31
-
32
- var SECTION_TYPE = {
33
- Classes: 'Classes',
34
- Modules: 'Modules',
35
- Externals: 'Externals',
36
- Events: 'Events',
37
- Namespaces: 'Namespaces',
38
- Mixins: 'Mixins',
39
- Tutorials: 'Tutorials',
40
- Interfaces: 'Interfaces',
41
- Global: 'Global',
42
- Menu: 'Menu'
43
- };
44
-
45
- var defaultSections = [
46
- SECTION_TYPE.Menu,
47
- SECTION_TYPE.Modules,
48
- SECTION_TYPE.Classes,
49
- SECTION_TYPE.Externals,
50
- SECTION_TYPE.Events,
51
- SECTION_TYPE.Namespaces,
52
- SECTION_TYPE.Mixins,
53
- SECTION_TYPE.Tutorials,
54
- SECTION_TYPE.Interfaces,
55
- SECTION_TYPE.Global
56
- ];
57
-
58
- function copyStaticFolder() {
59
- var staticDir = themeOpts.static_dir || undefined;
60
-
61
- if (staticDir) {
62
- for (var i = 0; i < staticDir.length; i++) {
63
- var output = path.join(outdir, staticDir[i]);
64
-
65
- fse.copySync(staticDir[i], output);
66
- }
67
- }
68
- }
69
-
70
- copyStaticFolder();
71
-
72
- function copyToOutputFolder(filePath) {
73
- var filePathNormalized = path.normalize(filePath);
74
-
75
- fs.copyFileSync(filePathNormalized, outdir);
76
- }
77
-
78
- function copyToOutputFolderFromArray(filePathArray) {
79
- var i = 0;
80
- var outputList = [];
81
-
82
- if (Array.isArray(filePathArray)) {
83
- for (; i < filePathArray.length; i++) {
84
- copyToOutputFolder(filePathArray[i]);
85
- outputList.push(path.basename(filePathArray[i]));
86
- }
87
- }
88
-
89
- return outputList;
90
- }
91
-
92
- function find(spec) {
93
- return helper.find(data, spec);
94
- }
95
-
96
- function tutoriallink(tutorial) {
97
- return helper.toTutorial(tutorial, null, {
98
- tag: 'em',
99
- classname: 'disabled',
100
- prefix: 'Tutorial: '
101
- });
102
- }
103
-
104
- function getAncestorLinks(doclet) {
105
- return helper.getAncestorLinks(data, doclet);
106
- }
107
-
108
- function hashToLink(doclet, hash) {
109
- if (!/^(#.+)/.test(hash)) {
110
- return hash;
111
- }
112
-
113
- var url = helper.createLink(doclet);
114
-
115
- url = url.replace(/(#.+|$)/, hash);
116
-
117
- return '<a href="' + url + '">' + hash + '</a>';
118
- }
119
-
120
- function needsSignature(doclet) {
121
- var needsSig = false;
122
-
123
- // function and class definitions always get a signature
124
- if (doclet.kind === 'function' || doclet.kind === 'class') {
125
- needsSig = true;
126
- }
127
- // typedefs that contain functions get a signature, too
128
- else if (
129
- doclet.kind === 'typedef' &&
130
- doclet.type &&
131
- doclet.type.names &&
132
- doclet.type.names.length
133
- ) {
134
- for (var i = 0, l = doclet.type.names.length; i < l; i++) {
135
- if (doclet.type.names[i].toLowerCase() === 'function') {
136
- needsSig = true;
137
- break;
138
- }
139
- }
140
- }
141
-
142
- return needsSig;
143
- }
144
-
145
- function getSignatureAttributes(item) {
146
- var attributes = [];
147
-
148
- if (item.optional) {
149
- attributes.push('opt');
150
- }
151
-
152
- if (item.nullable === true) {
153
- attributes.push('nullable');
154
- } else if (item.nullable === false) {
155
- attributes.push('non-null');
156
- }
157
-
158
- return attributes;
159
- }
160
-
161
- function updateItemName(item) {
162
- var attributes = getSignatureAttributes(item);
163
- var itemName = item.name || '';
164
-
165
- if (item.variable) {
166
- itemName = '&hellip;' + itemName;
167
- }
168
-
169
- if (attributes && attributes.length) {
170
- itemName = util.format(
171
- '%s<span class="signature-attributes">%s</span>',
172
- itemName,
173
- attributes.join(', ')
174
- );
175
- }
176
-
177
- return itemName;
178
- }
179
-
180
- function addParamAttributes(params) {
181
- return params
182
- .filter(function(param) {
183
- return param.name && param.name.indexOf('.') === -1;
184
- })
185
- .map(updateItemName);
186
- }
187
-
188
- function buildItemTypeStrings(item) {
189
- var types = [];
190
-
191
- if (item && item.type && item.type.names) {
192
- item.type.names.forEach(function(name) {
193
- types.push(linkto(name, htmlsafe(name)));
194
- });
195
- }
196
-
197
- return types;
198
- }
199
-
200
- function buildAttribsString(attribs) {
201
- var attribsString = '';
202
-
203
- if (attribs && attribs.length) {
204
- attribsString = htmlsafe(util.format('(%s) ', attribs.join(', ')));
205
- }
206
-
207
- return attribsString;
208
- }
209
-
210
- function addNonParamAttributes(items) {
211
- var types = [];
212
-
213
- items.forEach(function(item) {
214
- types = types.concat(buildItemTypeStrings(item));
215
- });
216
-
217
- return types;
218
- }
219
-
220
- function addSignatureParams(f) {
221
- var params = f.params ? addParamAttributes(f.params) : [];
222
-
223
- f.signature = util.format('%s(%s)', f.signature || '', params.join(', '));
224
- }
225
-
226
- function addSignatureReturns(f) {
227
- var attribs = [];
228
- var attribsString = '';
229
- var returnTypes = [];
230
- var returnTypesString = '';
231
-
232
- // jam all the return-type attributes into an array. this could create odd results (for example,
233
- // if there are both nullable and non-nullable return types), but let's assume that most people
234
- // who use multiple @return tags aren't using Closure Compiler type annotations, and vice-versa.
235
- if (f.returns) {
236
- f.returns.forEach(function(item) {
237
- helper.getAttribs(item).forEach(function(attrib) {
238
- if (attribs.indexOf(attrib) === -1) {
239
- attribs.push(attrib);
240
- }
241
- });
242
- });
243
-
244
- attribsString = buildAttribsString(attribs);
245
- }
246
-
247
- if (f.returns) {
248
- returnTypes = addNonParamAttributes(f.returns);
249
- }
250
- if (returnTypes.length) {
251
- returnTypesString = util.format(
252
- ' &rarr; %s{%s}',
253
- attribsString,
254
- returnTypes.join('|')
255
- );
256
- }
257
-
258
- f.signature =
259
- '<span class="signature">' +
260
- (f.signature || '') +
261
- '</span>' +
262
- '<span class="type-signature">' +
263
- returnTypesString +
264
- '</span>';
265
- }
266
-
267
- function addSignatureTypes(f) {
268
- var types = f.type ? buildItemTypeStrings(f) : [];
269
-
270
- f.signature =
271
- (f.signature || '') +
272
- '<span class="type-signature">' +
273
- (types.length ? ' :' + types.join('|') : '') +
274
- '</span>';
275
- }
276
-
277
- function addAttribs(f) {
278
- var attribs = helper.getAttribs(f);
279
- var attribsString = buildAttribsString(attribs);
280
-
281
- f.attribs = util.format(
282
- '<span class="type-signature">%s</span>',
283
- attribsString
284
- );
285
- }
286
-
287
- function shortenPaths(files, commonPrefix) {
288
- Object.keys(files).forEach(function(file) {
289
- files[file].shortened = files[file].resolved
290
- .replace(commonPrefix, '')
291
- // always use forward slashes
292
- .replace(/\\/g, '/');
293
- });
294
-
295
- return files;
296
- }
297
-
298
- function getPathFromDoclet(doclet) {
299
- if (!doclet.meta) {
300
- return null;
301
- }
302
-
303
- return doclet.meta.path && doclet.meta.path !== 'null' ?
304
- path.join(doclet.meta.path, doclet.meta.filename) :
305
- doclet.meta.filename;
306
- }
307
-
308
- function generate(type, title, docs, filename, resolveLinks) {
309
- resolveLinks = resolveLinks !== false;
310
-
311
- var docData = {
312
- type: type,
313
- title: title,
314
- docs: docs
315
- };
316
-
317
- var outpath = path.join(outdir, filename),
318
- html = view.render('container.tmpl', docData);
319
-
320
- if (resolveLinks) {
321
- html = helper.resolveLinks(html); // turn {@link foo} into <a href="foodoc.html">foo</a>
322
- }
323
-
324
- fs.writeFileSync(outpath, html, 'utf8');
325
- }
326
-
327
- function generateSourceFiles(sourceFiles, encoding) {
328
- encoding = encoding || 'utf8';
329
- Object.keys(sourceFiles).forEach(function(file) {
330
- var source;
331
- // links are keyed to the shortened path in each doclet's `meta.shortpath` property
332
- var sourceOutfile = helper.getUniqueFilename(
333
- sourceFiles[file].shortened
334
- );
335
-
336
- helper.registerLink(sourceFiles[file].shortened, sourceOutfile);
337
-
338
- try {
339
- source = {
340
- kind: 'source',
341
- code: helper.htmlsafe(
342
- fs.readFileSync(sourceFiles[file].resolved, encoding)
343
- )
344
- };
345
- } catch (e) {
346
- logger.error(
347
- 'Error while generating source file %s: %s',
348
- file,
349
- e.message
350
- );
351
- }
352
-
353
- generate(
354
- 'Source',
355
- sourceFiles[file].shortened,
356
- [source],
357
- sourceOutfile,
358
- false
359
- );
360
- });
361
- }
362
-
363
- /**
364
- * Look for classes or functions with the same name as modules (which indicates that the module
365
- * exports only that class or function), then attach the classes or functions to the `module`
366
- * property of the appropriate module doclets. The name of each class or function is also updated
367
- * for display purposes. This function mutates the original arrays.
368
- *
369
- * @private
370
- * @param {Array.<module:jsdoc/doclet.Doclet>} doclets - The array of classes and functions to
371
- * check.
372
- * @param {Array.<module:jsdoc/doclet.Doclet>} modules - The array of module doclets to search.
373
- */
374
- function attachModuleSymbols(doclets, modules) {
375
- var symbols = {};
376
-
377
- // build a lookup table
378
- doclets.forEach(function(symbol) {
379
- symbols[symbol.longname] = symbols[symbol.longname] || [];
380
- symbols[symbol.longname].push(symbol);
381
- });
382
-
383
- // eslint-disable-next-line array-callback-return
384
- return modules.map(function(module) {
385
- if (symbols[module.longname]) {
386
- module.modules = symbols[module.longname]
387
- // Only show symbols that have a description. Make an exception for classes, because
388
- // we want to show the constructor-signature heading no matter what.
389
- .filter(function(symbol) {
390
- return symbol.description || symbol.kind === 'class';
391
- })
392
- .map(function(symbol) {
393
- symbol = doop(symbol);
394
-
395
- if (symbol.kind === 'class' || symbol.kind === 'function') {
396
- symbol.name =
397
- symbol.name.replace('module:', '(require("') +
398
- '"))';
399
- }
400
-
401
- return symbol;
402
- });
403
- }
404
- });
405
- }
406
-
407
- function buildMenuNav(menu) {
408
- if (menu === undefined) {
409
- return '';
410
- }
411
-
412
- var m = '<ul>';
413
-
414
- menu.forEach(function(item) {
415
- // Setting default value for optional parameter
416
- var c = item.class || '';
417
- var id = item.id || '';
418
- var target = item.target || '';
419
-
420
- c += ' menu-link';
421
-
422
- m +=
423
- '<li class="menu-li">' +
424
- "<a href='" +
425
- item.link +
426
- "' class='" +
427
- c +
428
- "' id='" +
429
- id +
430
- "' target='" +
431
- target +
432
- "'>" +
433
- item.title +
434
- '</a></li>';
435
- });
436
-
437
- m += '</ul>';
438
-
439
- return m;
440
- }
441
-
442
- function buildSearch() {
443
- var searchHTML =
444
- '<div class="search-box" id="search-box">' +
445
- '<div class="search-box-input-container">' +
446
- '<input class="search-box-input" type="text" placeholder="Search..." id="search-box-input" />' +
447
- '<svg class="search-icon" alt="search-icon"><use xlink:href="#search-icon"></use></svg>' +
448
- '</div>';
449
-
450
- var searchItemContainer =
451
- '<div class="search-item-container" id="search-item-container"><ul class="search-item-ul" id="search-item-ul"></ul></div></div>';
452
-
453
- searchHTML += searchItemContainer;
454
-
455
- return searchHTML;
456
- }
457
-
458
- function buildFooter() {
459
- var footer = themeOpts.footer || '';
460
-
461
- return footer;
462
- }
463
-
464
- function getFavicon() {
465
- var favicon = themeOpts.favicon || undefined;
466
-
467
- return favicon;
468
- }
469
-
470
- // function copy
471
- function createDynamicStyleSheet() {
472
- var styleClass = themeOpts.create_style || undefined;
473
- /* prettier-ignore-start */
474
-
475
- return styleClass;
476
- }
477
-
478
- function createDynamicsScripts() {
479
- var scripts = themeOpts.add_scripts || undefined;
480
-
481
- return scripts;
482
- }
483
-
484
- function returnPathOfScriptScr() {
485
- var scriptPath = themeOpts.add_script_path || undefined;
486
-
487
- return scriptPath;
488
- }
489
-
490
- function returnPathOfStyleSrc() {
491
- var stylePath = themeOpts.add_style_path || undefined;
492
-
493
- return stylePath;
494
- }
495
-
496
- function includeCss() {
497
- var stylePath = themeOpts.include_css || undefined;
498
-
499
- if (stylePath) {
500
- stylePath = copyToOutputFolderFromArray(stylePath);
501
- }
502
-
503
- return stylePath;
504
- }
505
-
506
- function resizeable() {
507
- var resizeOpts = themeOpts.resizeable || {};
508
-
509
- return resizeOpts;
510
- }
511
-
512
- function codepen() {
513
- var codepenOpts = themeOpts.codepen || {};
514
-
515
- return codepenOpts;
516
- }
517
-
518
- function overlayScrollbarOptions() {
519
- var overlayOptions = themeOpts.overlay_scrollbar || undefined;
520
-
521
- if (overlayOptions) {
522
- return JSON.stringify(overlayOptions);
523
- }
524
-
525
- return undefined;
526
- }
527
-
528
- function includeScript() {
529
- var scriptPath = themeOpts.include_js || undefined;
530
-
531
- if (scriptPath) {
532
- scriptPath = copyToOutputFolderFromArray(scriptPath);
533
- }
534
-
535
- return scriptPath;
536
- }
537
-
538
- function getMetaTagData() {
539
- var meta = themeOpts.meta || undefined;
540
-
541
- return meta;
542
- }
543
-
544
- function getTheme() {
545
- var theme = themeOpts.theme || 'light';
546
- var baseThemeName = 'clean-jsdoc-theme';
547
- var themeSrc = `${baseThemeName}-${theme}.css`.trim();
548
-
549
- return themeSrc;
550
- }
551
-
552
- function search() {
553
- var searchOption = themeOpts.search;
554
-
555
- var obj = {
556
- list: searchListArray,
557
- options: JSON.stringify(searchOption)
558
- };
559
-
560
- return obj;
561
- }
562
-
563
- function buildMemberNav({
564
- items,
565
- itemHeading,
566
- itemsSeen,
567
- linktoFn,
568
- sectionName
569
- }) {
570
- var nav = '';
571
-
572
- if (items.length) {
573
- var itemsNav = '';
574
-
575
- items.forEach(function(item) {
576
- var methods =
577
- sectionName === SECTION_TYPE.Tutorials ||
578
- sectionName === SECTION_TYPE.Global ?
579
- [] :
580
- find({
581
- kind: 'function',
582
- memberof: item.longname,
583
- inherited: {'!is': Boolean(themeOpts.exclude_inherited)}
584
- });
585
-
586
- if (!hasOwnProp.call(item, 'longname')) {
587
- itemsNav += '<li>' + linktoFn('', item.name);
588
- itemsNav += '</li>';
589
- } else if (!hasOwnProp.call(itemsSeen, item.longname)) {
590
- /**
591
- * Only have accordion class name if it have any child.
592
- * Otherwise it didn't makes any sense.
593
- */
594
- var accordionClassName = methods.length ?
595
- '"accordion collapsed child"' :
596
- '"accordion-list"';
597
-
598
- /**
599
- * Id give to accordion.
600
- */
601
- var accordionId = methods.length ?
602
- Math.floor(Math.random() * 10000000) :
603
- '""';
604
-
605
- itemsNav +=
606
- '<li class=' +
607
- accordionClassName +
608
- ' id=' +
609
- accordionId +
610
- '>';
611
-
612
- var linkTitle = linktoFn(
613
- item.longname,
614
- item.name.replace(/^module:/, '')
615
- );
616
-
617
- if (methods.length) {
618
- itemsNav +=
619
- '<div class="accordion-heading child">' +
620
- linkTitle +
621
- '<svg><use xlink:href="#down-icon"></use></svg>' +
622
- '</div>';
623
- } else {
624
- itemsNav += linkTitle;
625
- }
626
-
627
- if (haveSearch) {
628
- searchListArray.push(
629
- JSON.stringify({
630
- title: item.name,
631
- link: linkto(item.longname, item.name)
632
- })
633
- );
634
- }
635
-
636
- if (methods.length) {
637
- itemsNav += "<ul class='methods accordion-content'>";
638
-
639
- methods.forEach(function(method) {
640
- var name = method.longname.split(method.scope === 'static' ? '.' : '#');
641
- var first = name[0];
642
- var last = name[1];
643
-
644
- name = first + ' &rtrif; ' + last;
645
-
646
- if (haveSearch) {
647
- searchListArray.push(
648
- JSON.stringify({
649
- title: method.longname,
650
- link: linkto(method.longname, name)
651
- })
652
- );
653
- }
654
- itemsNav += "<li data-type='method'>";
655
- itemsNav += linkto(method.longname, method.name);
656
- itemsNav += '</li>';
657
- });
658
-
659
- itemsNav += '</ul>';
660
- }
661
- itemsNav += '</li>';
662
- itemsSeen[item.longname] = true;
663
- }
664
- });
665
-
666
- if (itemsNav !== '') {
667
- nav +=
668
- '<div class="accordion collapsed" id="' +
669
- Math.floor(Math.random() * 10000000) +
670
- '" > <h3 class="accordion-heading">' +
671
- itemHeading +
672
- '<svg><use xlink:href="#down-icon"></use></svg>' +
673
- '</h3><ul class="accordion-content">' +
674
- itemsNav +
675
- '</ul> </div>';
676
- }
677
- }
678
-
679
- return nav;
680
- }
681
-
682
- function linktoTutorial(longName, name) {
683
- return tutoriallink(name);
684
- }
685
-
686
- function linktoExternal(longName, name) {
687
- return linkto(longName, name.replace(/(^"|"$)/g, ''));
688
- }
689
-
690
- /**
691
- * Create the navigation sidebar.
692
- * @param {object} members The members that will be used to create the sidebar.
693
- * @param {array<object>} members.classes
694
- * @param {array<object>} members.externals
695
- * @param {array<object>} members.globals
696
- * @param {array<object>} members.mixins
697
- * @param {array<object>} members.modules
698
- * @param {array<object>} members.namespaces
699
- * @param {array<object>} members.tutorials
700
- * @param {array<object>} members.events
701
- * @param {array<object>} members.interfaces
702
- * @return {string} The HTML for the navigation sidebar.
703
- */
704
- function buildNav(members) {
705
- var title = themeOpts.title || 'Home';
706
-
707
- var isHTML = RegExp.prototype.test.bind(/(<([^>]+)>)/i);
708
- var nav;
709
-
710
- if (!isHTML(title)) {
711
- nav =
712
- '<div class="navbar-heading" id="navbar-heading"><a href="index.html"><h2 class="navbar-heading-text">' +
713
- title +
714
- '</h2></a></div>';
715
- } else {
716
- nav = '<h2><a href="index.html">' + title + '</a></h2>';
717
- }
718
-
719
- if (haveSearch) {
720
- nav += buildSearch();
721
- }
722
- nav += '<div class="sidebar-main-content" id="sidebar-main-content">';
723
- var seen = {};
724
- var seenTutorials = {};
725
- var seenGlobal = {};
726
-
727
- var menu = themeOpts.menu || undefined;
728
- var sectionsOrder = themeOpts.sections || defaultSections;
729
-
730
- var sections = {
731
- [SECTION_TYPE.Menu]: buildMenuNav(menu),
732
-
733
- [SECTION_TYPE.Modules]: buildMemberNav({
734
- itemHeading: 'Modules',
735
- items: members.modules,
736
- itemsSeen: seen,
737
- linktoFn: linkto,
738
- sectionName: SECTION_TYPE.Modules
739
- }),
740
-
741
- [SECTION_TYPE.Classes]: buildMemberNav({
742
- itemHeading: 'Classes',
743
- items: members.classes,
744
- itemsSeen: seen,
745
- linktoFn: linkto,
746
- sectionName: SECTION_TYPE.Classes
747
- }),
748
-
749
- [SECTION_TYPE.Externals]: buildMemberNav({
750
- itemHeading: 'Externals',
751
- items: members.externals,
752
- itemsSeen: seen,
753
- linktoFn: linktoExternal,
754
- sectionName: SECTION_TYPE.Externals
755
- }),
756
-
757
- [SECTION_TYPE.Events]: buildMemberNav({
758
- itemHeading: 'Events',
759
- items: members.events,
760
- itemsSeen: seen,
761
- linktoFn: linkto,
762
- sectionName: SECTION_TYPE.Events
763
- }),
764
-
765
- [SECTION_TYPE.Namespaces]: buildMemberNav({
766
- itemHeading: 'Namespaces',
767
- items: members.namespaces,
768
- itemsSeen: seen,
769
- linktoFn: linkto,
770
- sectionName: SECTION_TYPE.Namespaces
771
- }),
772
-
773
- [SECTION_TYPE.Mixins]: buildMemberNav({
774
- itemHeading: 'Mixins',
775
- items: members.mixins,
776
- itemsSeen: seen,
777
- linktoFn: linkto,
778
- sectionName: SECTION_TYPE.Mixins
779
- }),
780
-
781
- [SECTION_TYPE.Tutorials]: buildMemberNav({
782
- itemHeading: 'Tutorials',
783
- items: members.tutorials,
784
- itemsSeen: seenTutorials,
785
- linktoFn: linktoTutorial,
786
- sectionName: SECTION_TYPE.Tutorials
787
- }),
788
-
789
- [SECTION_TYPE.Interfaces]: buildMemberNav({
790
- itemHeading: 'Interfaces',
791
- items: members.interfaces,
792
- itemsSeen: seen,
793
- linktoFn: linkto,
794
- sectionName: SECTION_TYPE.Interfaces
795
- }),
796
-
797
- [SECTION_TYPE.Global]: buildMemberNav({
798
- itemHeading: 'Global',
799
- items: members.globals,
800
- itemsSeen: seenGlobal,
801
- linktoFn: linkto,
802
- sectionName: SECTION_TYPE.Global
803
- })
804
- };
805
-
806
- sectionsOrder.forEach((section) => {
807
- if (SECTION_TYPE[section] !== undefined) {
808
- nav += sections[section];
809
- } else {
810
- var errorMsg = `While building nav. Section name: ${section} is not recognized.
811
- Accepted sections are: ${defaultSections.join(', ')}
812
- `;
813
-
814
- throw new Error(errorMsg);
815
- }
816
- });
817
-
818
- return nav;
819
- }
820
-
821
- /**
822
- @param {TAFFY} taffyData See <http://taffydb.com/>.
823
- @param {object} opts
824
- @param {Tutorial} tutorials
825
- */
826
- exports.publish = function(taffyData, opts, tutorials) {
827
- data = taffyData;
828
-
829
- // eslint-disable-next-line no-restricted-globals
830
- var conf = env.conf.templates || {};
831
-
832
- conf.default = conf.default || {};
833
-
834
- var templatePath = path.normalize(opts.template);
835
-
836
- view = new template.Template(path.join(templatePath, 'tmpl'));
837
-
838
- // claim some special filenames in advance, so the All-Powerful Overseer of Filename Uniqueness
839
- // doesn't try to hand them out later
840
- var indexUrl = helper.getUniqueFilename('index');
841
- // don't call registerLink() on this one! 'index' is also a valid longname
842
-
843
- var globalUrl = helper.getUniqueFilename('global');
844
-
845
- helper.registerLink('global', globalUrl);
846
-
847
- // set up templating
848
- view.layout = conf.default.layoutFile ?
849
- path.getResourcePath(
850
- path.dirname(conf.default.layoutFile),
851
- path.basename(conf.default.layoutFile)
852
- ) :
853
- 'layout.tmpl';
854
-
855
- // set up tutorials for helper
856
- helper.setTutorials(tutorials);
857
-
858
- data = helper.prune(data);
859
- data.sort('longname, version, since');
860
- helper.addEventListeners(data);
861
-
862
- var sourceFiles = {};
863
- var sourceFilePaths = [];
864
-
865
- data().each(function(doclet) {
866
- doclet.attribs = '';
867
-
868
- if (doclet.examples) {
869
- doclet.examples = doclet.examples.map(function(example) {
870
- var caption, code;
871
-
872
- if (example === undefined) {
873
- return {
874
- caption: '',
875
- code: ''
876
- };
877
- }
878
-
879
- if (
880
- example.match(
881
- /^\s*<caption>([\s\S]+?)<\/caption>(\s*[\n\r])([\s\S]+)$/i
882
- )
883
- ) {
884
- caption = RegExp.$1;
885
- code = RegExp.$3;
886
- }
887
-
888
- return {
889
- caption: caption || '',
890
- code: code || example
891
- };
892
- });
893
- }
894
- if (doclet.see) {
895
- doclet.see.forEach(function(seeItem, i) {
896
- doclet.see[i] = hashToLink(doclet, seeItem);
897
- });
898
- }
899
-
900
- // build a list of source files
901
- var sourcePath;
902
-
903
- if (doclet.meta) {
904
- sourcePath = getPathFromDoclet(doclet);
905
- sourceFiles[sourcePath] = {
906
- resolved: sourcePath,
907
- shortened: null
908
- };
909
- if (sourceFilePaths.indexOf(sourcePath) === -1) {
910
- sourceFilePaths.push(sourcePath);
911
- }
912
- }
913
- });
914
-
915
- // update outdir if necessary, then create outdir
916
- var packageInfo = (find({ kind: 'package' }) || [])[0];
917
-
918
- if (packageInfo && packageInfo.name) {
919
- outdir = path.join(outdir, packageInfo.name, packageInfo.version || '');
920
- }
921
- fs.mkPath(outdir);
922
-
923
- // copy the template's static files to outdir
924
- var fromDir = path.join(templatePath, 'static');
925
- var staticFiles = fs.ls(fromDir, 3);
926
-
927
- staticFiles.forEach(function(fileName) {
928
- var toDir = fs.toDir(fileName.replace(fromDir, outdir));
929
-
930
- fs.mkPath(toDir);
931
- fs.copyFileSync(fileName, toDir);
932
- });
933
-
934
- // copy user-specified static files to outdir
935
- var staticFilePaths;
936
- var staticFileFilter;
937
- var staticFileScanner;
938
-
939
- if (conf.default.staticFiles) {
940
- // The canonical property name is `include`. We accept `paths` for backwards compatibility
941
- // with a bug in JSDoc 3.2.x.
942
- staticFilePaths =
943
- conf.default.staticFiles.include ||
944
- conf.default.staticFiles.paths ||
945
- [];
946
- staticFileFilter = new (require('jsdoc/src/filter').Filter)(
947
- conf.default.staticFiles
948
- );
949
- staticFileScanner = new (require('jsdoc/src/scanner').Scanner)();
950
-
951
- staticFilePaths.forEach(function(filePath) {
952
- var extraStaticFiles = staticFileScanner.scan(
953
- [filePath],
954
- 10,
955
- staticFileFilter
956
- );
957
-
958
- extraStaticFiles.forEach(function(fileName) {
959
- var sourcePath = fs.toDir(filePath);
960
- var toDir = fs.toDir(fileName.replace(sourcePath, outdir));
961
-
962
- fs.mkPath(toDir);
963
- fs.copyFileSync(fileName, toDir);
964
- });
965
- });
966
- }
967
-
968
- if (sourceFilePaths.length) {
969
- sourceFiles = shortenPaths(
970
- sourceFiles,
971
- path.commonPrefix(sourceFilePaths)
972
- );
973
- }
974
- data().each(function(doclet) {
975
- var url = helper.createLink(doclet);
976
-
977
- helper.registerLink(doclet.longname, url);
978
-
979
- // add a shortened version of the full path
980
- var docletPath;
981
-
982
- if (doclet.meta) {
983
- docletPath = getPathFromDoclet(doclet);
984
- docletPath = sourceFiles[docletPath].shortened;
985
- if (docletPath) {
986
- doclet.meta.shortpath = docletPath;
987
- }
988
- }
989
- });
990
-
991
- data().each(function(doclet) {
992
- var url = helper.longnameToUrl[doclet.longname];
993
-
994
- if (url.indexOf('#') > -1) {
995
- doclet.id = helper.longnameToUrl[doclet.longname].split(/#/).pop();
996
- } else {
997
- doclet.id = doclet.name;
998
- }
999
-
1000
- if (needsSignature(doclet)) {
1001
- addSignatureParams(doclet);
1002
- addSignatureReturns(doclet);
1003
- addAttribs(doclet);
1004
- }
1005
- });
1006
-
1007
- // do this after the urls have all been generated
1008
- data().each(function(doclet) {
1009
- doclet.ancestors = getAncestorLinks(doclet);
1010
-
1011
- if (doclet.kind === 'member') {
1012
- addSignatureTypes(doclet);
1013
- addAttribs(doclet);
1014
- }
1015
-
1016
- if (doclet.kind === 'constant') {
1017
- addSignatureTypes(doclet);
1018
- addAttribs(doclet);
1019
- doclet.kind = 'member';
1020
- }
1021
- });
1022
-
1023
- var members = helper.getMembers(data);
1024
-
1025
- members.tutorials = tutorials.children;
1026
-
1027
- // output pretty-printed source files by default
1028
- var outputSourceFiles = Boolean(
1029
- conf.default && conf.default.outputSourceFiles !== false
1030
- );
1031
-
1032
- // add template helpers
1033
- view.find = find;
1034
- view.linkto = linkto;
1035
- view.resolveAuthorLinks = resolveAuthorLinks;
1036
- view.tutoriallink = tutoriallink;
1037
- view.htmlsafe = htmlsafe;
1038
- view.outputSourceFiles = outputSourceFiles;
1039
- view.footer = buildFooter();
1040
- view.favicon = getFavicon();
1041
- view.dynamicStyle = createDynamicStyleSheet();
1042
- view.dynamicStyleSrc = returnPathOfStyleSrc();
1043
- view.dynamicScript = createDynamicsScripts();
1044
- view.dynamicScriptSrc = returnPathOfScriptScr();
1045
- view.includeScript = includeScript();
1046
- view.includeCss = includeCss();
1047
- view.meta = getMetaTagData();
1048
- view.overlayScrollbar = overlayScrollbarOptions();
1049
- view.theme = getTheme();
1050
- // once for all
1051
- view.nav = buildNav(members);
1052
- view.search = search();
1053
- view.resizeable = resizeable();
1054
- view.codepen = codepen();
1055
- view.excludeInherited = Boolean(themeOpts.exclude_inherited);
1056
- attachModuleSymbols(
1057
- find({ longname: { left: 'module:' } }),
1058
- members.modules
1059
- );
1060
-
1061
- // generate the pretty-printed source files first so other pages can link to them
1062
- if (outputSourceFiles) {
1063
- generateSourceFiles(sourceFiles, opts.encoding);
1064
- }
1065
-
1066
- if (members.globals.length) {
1067
- generate('', 'Global', [{ kind: 'globalobj' }], globalUrl);
1068
- }
1069
-
1070
- // index page displays information from package.json and lists files
1071
- var files = find({ kind: 'file' });
1072
- var packages = find({ kind: 'package' });
1073
-
1074
- generate(
1075
- '',
1076
- 'Home',
1077
- packages
1078
- .concat([
1079
- {
1080
- kind: 'mainpage',
1081
- readme: opts.readme,
1082
- longname: opts.mainpagetitle ?
1083
- opts.mainpagetitle :
1084
- 'Main Page'
1085
- }
1086
- ])
1087
- .concat(files),
1088
- indexUrl
1089
- );
1090
-
1091
- // set up the lists that we'll use to generate pages
1092
- var classes = taffy(members.classes);
1093
- var modules = taffy(members.modules);
1094
- var namespaces = taffy(members.namespaces);
1095
- var mixins = taffy(members.mixins);
1096
- var externals = taffy(members.externals);
1097
- var interfaces = taffy(members.interfaces);
1098
-
1099
- Object.keys(helper.longnameToUrl).forEach(function(longname) {
1100
- var myModules = helper.find(modules, { longname: longname });
1101
-
1102
- if (myModules.length) {
1103
- generate(
1104
- 'Module',
1105
- myModules[0].name,
1106
- myModules,
1107
- helper.longnameToUrl[longname]
1108
- );
1109
- }
1110
-
1111
- var myClasses = helper.find(classes, { longname: longname });
1112
-
1113
- if (myClasses.length) {
1114
- generate(
1115
- 'Class',
1116
- myClasses[0].name,
1117
- myClasses,
1118
- helper.longnameToUrl[longname]
1119
- );
1120
- }
1121
-
1122
- var myNamespaces = helper.find(namespaces, { longname: longname });
1123
-
1124
- if (myNamespaces.length) {
1125
- generate(
1126
- 'Namespace',
1127
- myNamespaces[0].name,
1128
- myNamespaces,
1129
- helper.longnameToUrl[longname]
1130
- );
1131
- }
1132
-
1133
- var myMixins = helper.find(mixins, { longname: longname });
1134
-
1135
- if (myMixins.length) {
1136
- generate(
1137
- 'Mixin',
1138
- myMixins[0].name,
1139
- myMixins,
1140
- helper.longnameToUrl[longname]
1141
- );
1142
- }
1143
-
1144
- var myExternals = helper.find(externals, { longname: longname });
1145
-
1146
- if (myExternals.length) {
1147
- generate(
1148
- 'External',
1149
- myExternals[0].name,
1150
- myExternals,
1151
- helper.longnameToUrl[longname]
1152
- );
1153
- }
1154
-
1155
- var myInterfaces = helper.find(interfaces, { longname: longname });
1156
-
1157
- if (myInterfaces.length) {
1158
- generate(
1159
- 'Interface',
1160
- myInterfaces[0].name,
1161
- myInterfaces,
1162
- helper.longnameToUrl[longname]
1163
- );
1164
- }
1165
- });
1166
-
1167
- // TODO: move the tutorial functions to templateHelper.js
1168
- function generateTutorial(title, tutorial, filename) {
1169
- var tutorialData = {
1170
- title: title,
1171
- header: tutorial.title,
1172
- content: tutorial.parse(),
1173
- children: tutorial.children
1174
- };
1175
-
1176
- var tutorialPath = path.join(outdir, filename);
1177
- var html = view.render('tutorial.tmpl', tutorialData);
1178
-
1179
- // yes, you can use {@link} in tutorials too!
1180
- html = helper.resolveLinks(html); // turn {@link foo} into <a href="foodoc.html">foo</a>
1181
- fs.writeFileSync(tutorialPath, html, 'utf8');
1182
- }
1183
-
1184
- // tutorials can have only one parent so there is no risk for loops
1185
- function saveChildren(node) {
1186
- node.children.forEach(function(child) {
1187
- generateTutorial(
1188
- 'Tutorial: ' + child.title,
1189
- child,
1190
- helper.tutorialToUrl(child.name)
1191
- );
1192
- saveChildren(child);
1193
- });
1194
- }
1195
-
1196
- saveChildren(tutorials);
1197
- };
1
+ /* global env: true */
2
+
3
+ var doop = require('jsdoc/util/doop');
4
+ var fs = require('jsdoc/fs');
5
+ var helper = require('jsdoc/util/templateHelper');
6
+ var logger = require('jsdoc/util/logger');
7
+ var path = require('jsdoc/path');
8
+ var taffy = require('taffydb').taffy;
9
+ var template = require('jsdoc/template');
10
+ var util = require('util');
11
+ var fse = require('fs-extra');
12
+ var nanoid = require('nanoid').nanoid;
13
+ var htmlMinify = require('html-minifier');
14
+
15
+ var htmlsafe = helper.htmlsafe;
16
+ var linkto = helper.linkto;
17
+ var resolveAuthorLinks = helper.resolveAuthorLinks;
18
+ var hasOwnProp = Object.prototype.hasOwnProperty;
19
+
20
+ /* prettier-ignore-start */
21
+ // eslint-disable-next-line
22
+ var themeOpts = (env && env.opts && env.opts['theme_opts']) || {};
23
+ /* prettier-ignore-end */
24
+
25
+ var data;
26
+ var view;
27
+ var searchListArray = [];
28
+ var hasSearch =
29
+ themeOpts.search === undefined ? true : Boolean(themeOpts.search);
30
+
31
+ // eslint-disable-next-line no-restricted-globals
32
+ var outdir = path.normalize(env.opts.destination);
33
+
34
+ var SECTION_TYPE = {
35
+ Classes: 'Classes',
36
+ Modules: 'Modules',
37
+ Externals: 'Externals',
38
+ Events: 'Events',
39
+ Namespaces: 'Namespaces',
40
+ Mixins: 'Mixins',
41
+ Tutorials: 'Tutorials',
42
+ Interfaces: 'Interfaces',
43
+ Global: 'Global'
44
+ };
45
+
46
+ var defaultSections = [
47
+ SECTION_TYPE.Modules,
48
+ SECTION_TYPE.Classes,
49
+ SECTION_TYPE.Externals,
50
+ SECTION_TYPE.Events,
51
+ SECTION_TYPE.Namespaces,
52
+ SECTION_TYPE.Mixins,
53
+ SECTION_TYPE.Tutorials,
54
+ SECTION_TYPE.Interfaces,
55
+ SECTION_TYPE.Global
56
+ ];
57
+
58
+ var HTML_MINIFY_OPTIONS = {
59
+ collapseWhitespace: true,
60
+ removeComments: true,
61
+ html5: true,
62
+ minifyJS: true,
63
+ minifyCSS: true
64
+ };
65
+
66
+ function copyStaticFolder() {
67
+ var staticDir = themeOpts.static_dir || undefined;
68
+
69
+ if (staticDir) {
70
+ for (var i = 0; i < staticDir.length; i++) {
71
+ var output = path.join(outdir, staticDir[i]);
72
+
73
+ fse.copySync(staticDir[i], output);
74
+ }
75
+ }
76
+ }
77
+
78
+ copyStaticFolder();
79
+
80
+ function copyToOutputFolder(filePath) {
81
+ var filePathNormalized = path.normalize(filePath);
82
+
83
+ fs.copyFileSync(filePathNormalized, outdir);
84
+ }
85
+
86
+ function copyToOutputFolderFromArray(filePathArray) {
87
+ var i = 0;
88
+ var outputList = [];
89
+
90
+ if (Array.isArray(filePathArray)) {
91
+ for (; i < filePathArray.length; i++) {
92
+ copyToOutputFolder(filePathArray[i]);
93
+ outputList.push(path.basename(filePathArray[i]));
94
+ }
95
+ }
96
+
97
+ return outputList;
98
+ }
99
+
100
+ function find(spec) {
101
+ return helper.find(data, spec);
102
+ }
103
+
104
+ function tutoriallink(tutorial) {
105
+ return helper.toTutorial(tutorial, null, {
106
+ tag: 'em',
107
+ classname: 'disabled',
108
+ prefix: 'Tutorial: '
109
+ });
110
+ }
111
+
112
+ function getAncestorLinks(doclet) {
113
+ return helper.getAncestorLinks(data, doclet);
114
+ }
115
+
116
+ function hashToLink(doclet, hash) {
117
+ if (!/^(#.+)/.test(hash)) {
118
+ return hash;
119
+ }
120
+
121
+ var url = helper.createLink(doclet);
122
+
123
+ url = url.replace(/(#.+|$)/, hash);
124
+
125
+ return '<a href="' + url + '">' + hash + '</a>';
126
+ }
127
+
128
+ function needsSignature(doclet) {
129
+ var needsSig = false;
130
+
131
+ // function and class definitions always get a signature
132
+ if (doclet.kind === 'function' || doclet.kind === 'class') {
133
+ needsSig = true;
134
+ }
135
+ // typedefs that contain functions get a signature, too
136
+ else if (
137
+ doclet.kind === 'typedef' &&
138
+ doclet.type &&
139
+ doclet.type.names &&
140
+ doclet.type.names.length
141
+ ) {
142
+ for (var i = 0, l = doclet.type.names.length; i < l; i++) {
143
+ if (doclet.type.names[i].toLowerCase() === 'function') {
144
+ needsSig = true;
145
+ break;
146
+ }
147
+ }
148
+ }
149
+
150
+ return needsSig;
151
+ }
152
+
153
+ function getSignatureAttributes(item) {
154
+ var attributes = [];
155
+
156
+ if (item.optional) {
157
+ attributes.push('opt');
158
+ }
159
+
160
+ if (item.nullable === true) {
161
+ attributes.push('nullable');
162
+ } else if (item.nullable === false) {
163
+ attributes.push('non-null');
164
+ }
165
+
166
+ return attributes;
167
+ }
168
+
169
+ function updateItemName(item) {
170
+ var attributes = getSignatureAttributes(item);
171
+ var itemName = item.name || '';
172
+
173
+ if (item.variable) {
174
+ itemName = '&hellip;' + itemName;
175
+ }
176
+
177
+ if (attributes && attributes.length) {
178
+ itemName = util.format(
179
+ '%s<span class="signature-attributes">%s</span>',
180
+ itemName,
181
+ attributes.join(', ')
182
+ );
183
+ }
184
+
185
+ return itemName;
186
+ }
187
+
188
+ function addParamAttributes(params) {
189
+ return params
190
+ .filter(function(param) {
191
+ return param.name && param.name.indexOf('.') === -1;
192
+ })
193
+ .map(updateItemName);
194
+ }
195
+
196
+ function buildItemTypeStrings(item) {
197
+ var types = [];
198
+
199
+ if (item && item.type && item.type.names) {
200
+ item.type.names.forEach(function(name) {
201
+ types.push(linkto(name, htmlsafe(name)));
202
+ });
203
+ }
204
+
205
+ return types;
206
+ }
207
+
208
+ function buildAttribsString(attribs) {
209
+ var attribsString = '';
210
+
211
+ if (attribs && attribs.length) {
212
+ attribsString = htmlsafe(util.format('(%s) ', attribs.join(', ')));
213
+ }
214
+
215
+ return attribsString;
216
+ }
217
+
218
+ function addNonParamAttributes(items) {
219
+ var types = [];
220
+
221
+ items.forEach(function(item) {
222
+ types = types.concat(buildItemTypeStrings(item));
223
+ });
224
+
225
+ return types;
226
+ }
227
+
228
+ function addSignatureParams(f) {
229
+ var params = f.params ? addParamAttributes(f.params) : [];
230
+
231
+ f.signature = util.format('%s(%s)', f.signature || '', params.join(', '));
232
+ }
233
+
234
+ function addSignatureReturns(f) {
235
+ var attribs = [];
236
+ var attribsString = '';
237
+ var returnTypes = [];
238
+ var returnTypesString = '';
239
+
240
+ // jam all the return-type attributes into an array. this could create odd results (for example,
241
+ // if there are both nullable and non-nullable return types), but let's assume that most people
242
+ // who use multiple @return tags aren't using Closure Compiler type annotations, and vice-versa.
243
+ if (f.returns) {
244
+ f.returns.forEach(function(item) {
245
+ helper.getAttribs(item).forEach(function(attrib) {
246
+ if (attribs.indexOf(attrib) === -1) {
247
+ attribs.push(attrib);
248
+ }
249
+ });
250
+ });
251
+
252
+ attribsString = buildAttribsString(attribs);
253
+ }
254
+
255
+ if (f.returns) {
256
+ returnTypes = addNonParamAttributes(f.returns);
257
+ }
258
+ if (returnTypes.length) {
259
+ returnTypesString = util.format(
260
+ ' &rarr; %s{%s}',
261
+ attribsString,
262
+ returnTypes.join('|')
263
+ );
264
+ }
265
+
266
+ f.signature =
267
+ '<span class="signature">' +
268
+ (f.signature || '') +
269
+ '</span>' +
270
+ '<span class="type-signature">' +
271
+ returnTypesString +
272
+ '</span>';
273
+ }
274
+
275
+ function addSignatureTypes(f) {
276
+ var types = f.type ? buildItemTypeStrings(f) : [];
277
+
278
+ f.signature =
279
+ (f.signature || '') +
280
+ '<span class="type-signature">' +
281
+ (types.length ? ' :' + types.join('|') : '') +
282
+ '</span>';
283
+ }
284
+
285
+ function addAttribs(f) {
286
+ var attribs = helper.getAttribs(f);
287
+ var attribsString = buildAttribsString(attribs);
288
+
289
+ f.attribs = util.format(
290
+ '<span class="type-signature">%s</span>',
291
+ attribsString
292
+ );
293
+ }
294
+
295
+ function shortenPaths(files, commonPrefix) {
296
+ Object.keys(files).forEach(function(file) {
297
+ files[file].shortened = files[file].resolved
298
+ .replace(commonPrefix, '')
299
+ // always use forward slashes
300
+ .replace(/\\/g, '/');
301
+ });
302
+
303
+ return files;
304
+ }
305
+
306
+ function getPathFromDoclet(doclet) {
307
+ if (!doclet.meta) {
308
+ return null;
309
+ }
310
+
311
+ return doclet.meta.path && doclet.meta.path !== 'null' ?
312
+ path.join(doclet.meta.path, doclet.meta.filename) :
313
+ doclet.meta.filename;
314
+ }
315
+
316
+ function generate(type, title, docs, filename, resolveLinks) {
317
+ resolveLinks = resolveLinks !== false;
318
+
319
+ var docData = {
320
+ type: type,
321
+ title: title,
322
+ docs: docs
323
+ };
324
+
325
+ var outpath = path.join(outdir, filename),
326
+ html = view.render('container.tmpl', docData);
327
+
328
+ if (resolveLinks) {
329
+ html = helper.resolveLinks(html); // turn {@link foo} into <a href="foodoc.html">foo</a>
330
+ }
331
+
332
+ fs.writeFileSync(
333
+ outpath,
334
+ htmlMinify.minify(html, HTML_MINIFY_OPTIONS),
335
+ 'utf8'
336
+ );
337
+ }
338
+
339
+ function generateSourceFiles(sourceFiles, encoding) {
340
+ encoding = encoding || 'utf8';
341
+ Object.keys(sourceFiles).forEach(function(file) {
342
+ var source;
343
+ // links are keyed to the shortened path in each doclet's `meta.shortpath` property
344
+ var sourceOutfile = helper.getUniqueFilename(
345
+ sourceFiles[file].shortened
346
+ );
347
+
348
+ helper.registerLink(sourceFiles[file].shortened, sourceOutfile);
349
+
350
+ try {
351
+ source = {
352
+ kind: 'source',
353
+ title: sourceOutfile.replace('.html', ''),
354
+ code: helper.htmlsafe(
355
+ fs.readFileSync(sourceFiles[file].resolved, encoding)
356
+ )
357
+ };
358
+ } catch (e) {
359
+ logger.error(
360
+ 'Error while generating source file %s: %s',
361
+ file,
362
+ e.message
363
+ );
364
+ }
365
+
366
+ generate(
367
+ 'Source',
368
+ sourceFiles[file].shortened,
369
+ [source],
370
+ sourceOutfile,
371
+ false
372
+ );
373
+ });
374
+ }
375
+
376
+ /**
377
+ * Look for classes or functions with the same name as modules (which indicates that the module
378
+ * exports only that class or function), then attach the classes or functions to the `module`
379
+ * property of the appropriate module doclets. The name of each class or function is also updated
380
+ * for display purposes. This function mutates the original arrays.
381
+ *
382
+ * @private
383
+ * @param {Array.<module:jsdoc/doclet.Doclet>} doclets - The array of classes and functions to
384
+ * check.
385
+ * @param {Array.<module:jsdoc/doclet.Doclet>} modules - The array of module doclets to search.
386
+ */
387
+ function attachModuleSymbols(doclets, modules) {
388
+ var symbols = {};
389
+
390
+ // build a lookup table
391
+ doclets.forEach(function(symbol) {
392
+ symbols[symbol.longname] = symbols[symbol.longname] || [];
393
+ symbols[symbol.longname].push(symbol);
394
+ });
395
+
396
+ // eslint-disable-next-line array-callback-return
397
+ return modules.map(function(module) {
398
+ if (symbols[module.longname]) {
399
+ module.modules = symbols[module.longname]
400
+ // Only show symbols that have a description. Make an exception for classes, because
401
+ // we want to show the constructor-signature heading no matter what.
402
+ .filter(function(symbol) {
403
+ return symbol.description || symbol.kind === 'class';
404
+ })
405
+ .map(function(symbol) {
406
+ symbol = doop(symbol);
407
+
408
+ if (symbol.kind === 'class' || symbol.kind === 'function') {
409
+ symbol.name =
410
+ symbol.name.replace('module:', '(require("') +
411
+ '"))';
412
+ }
413
+
414
+ return symbol;
415
+ });
416
+ }
417
+ });
418
+ }
419
+
420
+ function buildFooter() {
421
+ var footer = themeOpts.footer;
422
+
423
+ return footer;
424
+ }
425
+
426
+ function getFavicon() {
427
+ var favicon = themeOpts.favicon || undefined;
428
+
429
+ return favicon;
430
+ }
431
+
432
+ // function copy
433
+ function createDynamicStyleSheet() {
434
+ var styleClass = themeOpts.create_style || undefined;
435
+ /* prettier-ignore-start */
436
+
437
+ return styleClass;
438
+ }
439
+
440
+ function createDynamicsScripts() {
441
+ var scripts = themeOpts.add_scripts || undefined;
442
+
443
+ return scripts;
444
+ }
445
+
446
+ function returnPathOfScriptScr() {
447
+ var scriptPath = themeOpts.add_script_path || undefined;
448
+
449
+ return scriptPath;
450
+ }
451
+
452
+ function returnPathOfStyleSrc() {
453
+ var stylePath = themeOpts.add_style_path || undefined;
454
+
455
+ return stylePath;
456
+ }
457
+
458
+ function includeCss() {
459
+ var stylePath = themeOpts.include_css || undefined;
460
+
461
+ if (stylePath) {
462
+ stylePath = copyToOutputFolderFromArray(stylePath);
463
+ }
464
+
465
+ return stylePath;
466
+ }
467
+
468
+ function resizeable() {
469
+ var resizeOpts = themeOpts.resizeable || {};
470
+
471
+ return resizeOpts;
472
+ }
473
+
474
+ function codepen() {
475
+ var codepenOpts = themeOpts.codepen || {};
476
+
477
+ return codepenOpts;
478
+ }
479
+
480
+ function includeScript() {
481
+ var scriptPath = themeOpts.include_js || undefined;
482
+
483
+ if (scriptPath) {
484
+ scriptPath = copyToOutputFolderFromArray(scriptPath);
485
+ }
486
+
487
+ return scriptPath;
488
+ }
489
+
490
+ function getMetaTagData() {
491
+ var meta = themeOpts.meta || undefined;
492
+
493
+ return meta;
494
+ }
495
+
496
+ function getTheme() {
497
+ var theme = themeOpts.default_theme || 'dark';
498
+
499
+ return theme;
500
+ }
501
+
502
+ function getBaseURL() {
503
+ var url = themeOpts.base_url || '/';
504
+
505
+ return url;
506
+ }
507
+
508
+ function buildSidebarMembers({
509
+ items,
510
+ itemHeading,
511
+ itemsSeen,
512
+ linktoFn,
513
+ sectionName
514
+ }) {
515
+ const navProps = {
516
+ name: itemHeading,
517
+ items: [],
518
+ id: nanoid()
519
+ };
520
+
521
+ if (items.length) {
522
+ items.forEach(function(item) {
523
+ const currentItem = {
524
+ name: item.name,
525
+ anchor: item.longname ?
526
+ linktoFn(item.longname, item.name) :
527
+ linktoFn('', item.name),
528
+ children: []
529
+ };
530
+
531
+ var methods =
532
+ sectionName === SECTION_TYPE.Tutorials ||
533
+ sectionName === SECTION_TYPE.Global ?
534
+ [] :
535
+ find({
536
+ kind: 'function',
537
+ memberof: item.longname,
538
+ inherited: {
539
+ '!is': Boolean(themeOpts.exclude_inherited)
540
+ }
541
+ });
542
+
543
+ if (!hasOwnProp.call(itemsSeen, item.longname)) {
544
+ currentItem.anchor = linktoFn(
545
+ item.longname,
546
+ item.name.replace(/^module:/, '')
547
+ );
548
+
549
+ if (hasSearch) {
550
+ searchListArray.push({
551
+ title: item.name,
552
+ link: linkto(item.longname, item.name),
553
+ description: item.description
554
+ });
555
+ }
556
+
557
+ if (methods.length) {
558
+ methods.forEach(function(method) {
559
+ const itemChild = {
560
+ name: method.longName,
561
+ link: linkto(method.longname, method.name)
562
+ };
563
+
564
+ currentItem.children.push(itemChild);
565
+
566
+ var name = method.longname.split(
567
+ method.scope === 'static' ? '.' : '#'
568
+ );
569
+ var first = name[0];
570
+ var last = name[1];
571
+
572
+ name = first + ' &rtrif; ' + last;
573
+
574
+ if (hasSearch) {
575
+ searchListArray.push({
576
+ title: method.longname,
577
+ link: linkto(method.longname, name),
578
+ description: item.classdesc
579
+ });
580
+ }
581
+ });
582
+ }
583
+ itemsSeen[item.longname] = true;
584
+ }
585
+
586
+ navProps.items.push(currentItem);
587
+ });
588
+ }
589
+
590
+ return navProps;
591
+ }
592
+
593
+ function linktoTutorial(longName, name) {
594
+ return tutoriallink(name);
595
+ }
596
+
597
+ function linktoExternal(longName, name) {
598
+ return linkto(longName, name.replace(/(^"|"$)/g, ''));
599
+ }
600
+
601
+ function buildNavbar() {
602
+ return {
603
+ menu: themeOpts.menu || undefined,
604
+ search: hasSearch
605
+ };
606
+ }
607
+
608
+ /**
609
+ * Create the navigation sidebar.
610
+ * @param {object} members The members that will be used to create the sidebar.
611
+ * @param {array<object>} members.classes
612
+ * @param {array<object>} members.externals
613
+ * @param {array<object>} members.globals
614
+ * @param {array<object>} members.mixins
615
+ * @param {array<object>} members.modules
616
+ * @param {array<object>} members.namespaces
617
+ * @param {array<object>} members.tutorials
618
+ * @param {array<object>} members.events
619
+ * @param {array<object>} members.interfaces
620
+ * @return {string} The HTML for the navigation sidebar.
621
+ */
622
+ function buildSidebar(members) {
623
+ var title = themeOpts.title || 'Home';
624
+
625
+ var isHTML = RegExp.prototype.test.bind(/(<([^>]+)>)/i);
626
+
627
+ var nav = {
628
+ sections: []
629
+ };
630
+
631
+ if (!isHTML(title)) {
632
+ nav.title = {
633
+ title,
634
+ isHTML: false
635
+ };
636
+ } else {
637
+ nav.title = {
638
+ title,
639
+ isHTML: true
640
+ };
641
+ }
642
+
643
+ var seen = {};
644
+ var seenTutorials = {};
645
+ var seenGlobal = {};
646
+
647
+ var sectionsOrder = themeOpts.sections || defaultSections;
648
+
649
+ var sections = {
650
+ [SECTION_TYPE.Modules]: buildSidebarMembers({
651
+ itemHeading: 'Modules',
652
+ items: members.modules,
653
+ itemsSeen: seen,
654
+ linktoFn: linkto,
655
+ sectionName: SECTION_TYPE.Modules
656
+ }),
657
+
658
+ [SECTION_TYPE.Classes]: buildSidebarMembers({
659
+ itemHeading: 'Classes',
660
+ items: members.classes,
661
+ itemsSeen: seen,
662
+ linktoFn: linkto,
663
+ sectionName: SECTION_TYPE.Classes
664
+ }),
665
+
666
+ [SECTION_TYPE.Externals]: buildSidebarMembers({
667
+ itemHeading: 'Externals',
668
+ items: members.externals,
669
+ itemsSeen: seen,
670
+ linktoFn: linktoExternal,
671
+ sectionName: SECTION_TYPE.Externals
672
+ }),
673
+
674
+ [SECTION_TYPE.Events]: buildSidebarMembers({
675
+ itemHeading: 'Events',
676
+ items: members.events,
677
+ itemsSeen: seen,
678
+ linktoFn: linkto,
679
+ sectionName: SECTION_TYPE.Events
680
+ }),
681
+
682
+ [SECTION_TYPE.Namespaces]: buildSidebarMembers({
683
+ itemHeading: 'Namespaces',
684
+ items: members.namespaces,
685
+ itemsSeen: seen,
686
+ linktoFn: linkto,
687
+ sectionName: SECTION_TYPE.Namespaces
688
+ }),
689
+
690
+ [SECTION_TYPE.Mixins]: buildSidebarMembers({
691
+ itemHeading: 'Mixins',
692
+ items: members.mixins,
693
+ itemsSeen: seen,
694
+ linktoFn: linkto,
695
+ sectionName: SECTION_TYPE.Mixins
696
+ }),
697
+
698
+ [SECTION_TYPE.Tutorials]: buildSidebarMembers({
699
+ itemHeading: 'Tutorials',
700
+ items: members.tutorials,
701
+ itemsSeen: seenTutorials,
702
+ linktoFn: linktoTutorial,
703
+ sectionName: SECTION_TYPE.Tutorials
704
+ }),
705
+
706
+ [SECTION_TYPE.Interfaces]: buildSidebarMembers({
707
+ itemHeading: 'Interfaces',
708
+ items: members.interfaces,
709
+ itemsSeen: seen,
710
+ linktoFn: linkto,
711
+ sectionName: SECTION_TYPE.Interfaces
712
+ }),
713
+
714
+ [SECTION_TYPE.Global]: buildSidebarMembers({
715
+ itemHeading: 'Global',
716
+ items: members.globals,
717
+ itemsSeen: seenGlobal,
718
+ linktoFn: linkto,
719
+ sectionName: SECTION_TYPE.Global
720
+ })
721
+ };
722
+
723
+ sectionsOrder.forEach((section) => {
724
+ if (SECTION_TYPE[section] !== undefined) {
725
+ nav.sections.push(sections[section]);
726
+ } else {
727
+ var errorMsg = `While building nav. Section name: ${section} is not recognized.
728
+ Accepted sections are: ${defaultSections.join(', ')}
729
+ `;
730
+
731
+ throw new Error(errorMsg);
732
+ }
733
+ });
734
+
735
+ return nav;
736
+ }
737
+
738
+ /**
739
+ @param {TAFFY} taffyData See <http://taffydb.com/>.
740
+ @param {object} opts
741
+ @param {Tutorial} tutorials
742
+ */
743
+ exports.publish = function(taffyData, opts, tutorials) {
744
+ data = taffyData;
745
+
746
+ // eslint-disable-next-line no-restricted-globals
747
+ var conf = env.conf.templates || {};
748
+
749
+ conf.default = conf.default || {};
750
+
751
+ var templatePath = path.normalize(opts.template);
752
+
753
+ view = new template.Template(path.join(templatePath, 'tmpl'));
754
+
755
+ // claim some special filenames in advance, so the All-Powerful Overseer of Filename Uniqueness
756
+ // doesn't try to hand them out later
757
+ var indexUrl = helper.getUniqueFilename('index');
758
+ // don't call registerLink() on this one! 'index' is also a valid longname
759
+
760
+ var globalUrl = helper.getUniqueFilename('global');
761
+
762
+ helper.registerLink('global', globalUrl);
763
+
764
+ // set up templating
765
+ view.layout = conf.default.layoutFile ?
766
+ path.getResourcePath(
767
+ path.dirname(conf.default.layoutFile),
768
+ path.basename(conf.default.layoutFile)
769
+ ) :
770
+ 'layout.tmpl';
771
+
772
+ // set up tutorials for helper
773
+ helper.setTutorials(tutorials);
774
+
775
+ data = helper.prune(data);
776
+ data.sort('longname, version, since');
777
+ helper.addEventListeners(data);
778
+
779
+ var sourceFiles = {};
780
+ var sourceFilePaths = [];
781
+
782
+ data().each(function(doclet) {
783
+ doclet.attribs = '';
784
+
785
+ if (doclet.examples) {
786
+ doclet.examples = doclet.examples.map(function(example) {
787
+ var caption, code;
788
+
789
+ if (example === undefined) {
790
+ return {
791
+ caption: '',
792
+ code: ''
793
+ };
794
+ }
795
+
796
+ if (
797
+ example.match(
798
+ /^\s*<caption>([\s\S]+?)<\/caption>(\s*[\n\r])([\s\S]+)$/i
799
+ )
800
+ ) {
801
+ caption = RegExp.$1;
802
+ code = RegExp.$3;
803
+ }
804
+
805
+ return {
806
+ caption: caption || '',
807
+ code: code || example
808
+ };
809
+ });
810
+ }
811
+ if (doclet.see) {
812
+ doclet.see.forEach(function(seeItem, i) {
813
+ doclet.see[i] = hashToLink(doclet, seeItem);
814
+ });
815
+ }
816
+
817
+ // build a list of source files
818
+ var sourcePath;
819
+
820
+ if (doclet.meta) {
821
+ sourcePath = getPathFromDoclet(doclet);
822
+ sourceFiles[sourcePath] = {
823
+ resolved: sourcePath,
824
+ shortened: null
825
+ };
826
+ if (sourceFilePaths.indexOf(sourcePath) === -1) {
827
+ sourceFilePaths.push(sourcePath);
828
+ }
829
+ }
830
+ });
831
+
832
+ // update outdir if necessary, then create outdir
833
+ var packageInfo = (find({ kind: 'package' }) || [])[0];
834
+
835
+ if (packageInfo && packageInfo.name) {
836
+ outdir = path.join(outdir, packageInfo.name, packageInfo.version || '');
837
+ }
838
+ fs.mkPath(outdir);
839
+
840
+ // copy the template's static files to outdir
841
+ var fromDir = path.join(templatePath, 'static');
842
+ var staticFiles = fs.ls(fromDir, 3);
843
+
844
+ staticFiles.forEach(function(fileName) {
845
+ var toDir = fs.toDir(fileName.replace(fromDir, outdir));
846
+
847
+ fs.mkPath(toDir);
848
+ fs.copyFileSync(fileName, toDir);
849
+ });
850
+
851
+ // copy user-specified static files to outdir
852
+ var staticFilePaths;
853
+ var staticFileFilter;
854
+ var staticFileScanner;
855
+
856
+ if (conf.default.staticFiles) {
857
+ // The canonical property name is `include`. We accept `paths` for backwards compatibility
858
+ // with a bug in JSDoc 3.2.x.
859
+ staticFilePaths =
860
+ conf.default.staticFiles.include ||
861
+ conf.default.staticFiles.paths ||
862
+ [];
863
+ staticFileFilter = new (require('jsdoc/src/filter').Filter)(
864
+ conf.default.staticFiles
865
+ );
866
+ staticFileScanner = new (require('jsdoc/src/scanner').Scanner)();
867
+
868
+ staticFilePaths.forEach(function(filePath) {
869
+ var extraStaticFiles = staticFileScanner.scan(
870
+ [filePath],
871
+ 10,
872
+ staticFileFilter
873
+ );
874
+
875
+ extraStaticFiles.forEach(function(fileName) {
876
+ var sourcePath = fs.toDir(filePath);
877
+ var toDir = fs.toDir(fileName.replace(sourcePath, outdir));
878
+
879
+ fs.mkPath(toDir);
880
+ fs.copyFileSync(fileName, toDir);
881
+ });
882
+ });
883
+ }
884
+
885
+ if (sourceFilePaths.length) {
886
+ sourceFiles = shortenPaths(
887
+ sourceFiles,
888
+ path.commonPrefix(sourceFilePaths)
889
+ );
890
+ }
891
+ data().each(function(doclet) {
892
+ var url = helper.createLink(doclet);
893
+
894
+ helper.registerLink(doclet.longname, url);
895
+
896
+ // add a shortened version of the full path
897
+ var docletPath;
898
+
899
+ if (doclet.meta) {
900
+ docletPath = getPathFromDoclet(doclet);
901
+ docletPath = sourceFiles[docletPath].shortened;
902
+ if (docletPath) {
903
+ doclet.meta.shortpath = docletPath;
904
+ }
905
+ }
906
+ });
907
+
908
+ data().each(function(doclet) {
909
+ var url = helper.longnameToUrl[doclet.longname];
910
+
911
+ if (url.indexOf('#') > -1) {
912
+ doclet.id = helper.longnameToUrl[doclet.longname].split(/#/).pop();
913
+ } else {
914
+ doclet.id = doclet.name;
915
+ }
916
+
917
+ if (needsSignature(doclet)) {
918
+ addSignatureParams(doclet);
919
+ addSignatureReturns(doclet);
920
+ addAttribs(doclet);
921
+ }
922
+ });
923
+
924
+ // do this after the urls have all been generated
925
+ data().each(function(doclet) {
926
+ doclet.ancestors = getAncestorLinks(doclet);
927
+
928
+ if (doclet.kind === 'member') {
929
+ addSignatureTypes(doclet);
930
+ addAttribs(doclet);
931
+ }
932
+
933
+ if (doclet.kind === 'constant') {
934
+ addSignatureTypes(doclet);
935
+ addAttribs(doclet);
936
+ doclet.kind = 'member';
937
+ }
938
+ });
939
+
940
+ var members = helper.getMembers(data);
941
+
942
+ members.tutorials = tutorials.children;
943
+
944
+ // output pretty-printed source files by default
945
+ var outputSourceFiles = Boolean(
946
+ conf.default && conf.default.outputSourceFiles !== false
947
+ );
948
+
949
+ // add template helpers
950
+ view.find = find;
951
+ view.linkto = linkto;
952
+ view.resolveAuthorLinks = resolveAuthorLinks;
953
+ view.tutoriallink = tutoriallink;
954
+ view.htmlsafe = htmlsafe;
955
+ view.outputSourceFiles = outputSourceFiles;
956
+ view.footer = buildFooter();
957
+ view.favicon = getFavicon();
958
+ view.dynamicStyle = createDynamicStyleSheet();
959
+ view.dynamicStyleSrc = returnPathOfStyleSrc();
960
+ view.dynamicScript = createDynamicsScripts();
961
+ view.dynamicScriptSrc = returnPathOfScriptScr();
962
+ view.includeScript = includeScript();
963
+ view.includeCss = includeCss();
964
+ view.meta = getMetaTagData();
965
+ view.theme = getTheme();
966
+ // once for all
967
+ view.sidebar = buildSidebar(members);
968
+ view.navbar = buildNavbar();
969
+ view.resizeable = resizeable();
970
+ view.codepen = codepen();
971
+ view.baseURL = getBaseURL();
972
+ view.excludeInherited = Boolean(themeOpts.exclude_inherited);
973
+ attachModuleSymbols(
974
+ find({ longname: { left: 'module:' } }),
975
+ members.modules
976
+ );
977
+
978
+ // output search file if search
979
+
980
+ if (hasSearch) {
981
+ fs.mkPath(path.join(outdir, 'data'));
982
+ fs.writeFileSync(
983
+ path.join(outdir, 'data', 'search.json'),
984
+ JSON.stringify({
985
+ list: searchListArray
986
+ })
987
+ );
988
+ }
989
+
990
+ // generate the pretty-printed source files first so other pages can link to them
991
+ if (outputSourceFiles) {
992
+ generateSourceFiles(sourceFiles, opts.encoding);
993
+ }
994
+
995
+ if (members.globals.length) {
996
+ generate('', 'Global', [{ kind: 'globalobj' }], globalUrl);
997
+ }
998
+
999
+ // index page displays information from package.json and lists files
1000
+ var files = find({ kind: 'file' });
1001
+ var packages = find({ kind: 'package' });
1002
+
1003
+ generate(
1004
+ '',
1005
+ 'Home',
1006
+ packages
1007
+ .concat([
1008
+ {
1009
+ kind: 'mainpage',
1010
+ readme: opts.readme,
1011
+ longname: opts.mainpagetitle ?
1012
+ opts.mainpagetitle :
1013
+ 'Main Page'
1014
+ }
1015
+ ])
1016
+ .concat(files),
1017
+ indexUrl
1018
+ );
1019
+
1020
+ // set up the lists that we'll use to generate pages
1021
+ var classes = taffy(members.classes);
1022
+ var modules = taffy(members.modules);
1023
+ var namespaces = taffy(members.namespaces);
1024
+ var mixins = taffy(members.mixins);
1025
+ var externals = taffy(members.externals);
1026
+ var interfaces = taffy(members.interfaces);
1027
+
1028
+ Object.keys(helper.longnameToUrl).forEach(function(longname) {
1029
+ var myModules = helper.find(modules, { longname: longname });
1030
+
1031
+ if (myModules.length) {
1032
+ generate(
1033
+ 'Module',
1034
+ myModules[0].name,
1035
+ myModules,
1036
+ helper.longnameToUrl[longname]
1037
+ );
1038
+ }
1039
+
1040
+ var myClasses = helper.find(classes, { longname: longname });
1041
+
1042
+ if (myClasses.length) {
1043
+ generate(
1044
+ 'Class',
1045
+ myClasses[0].name,
1046
+ myClasses,
1047
+ helper.longnameToUrl[longname]
1048
+ );
1049
+ }
1050
+
1051
+ var myNamespaces = helper.find(namespaces, { longname: longname });
1052
+
1053
+ if (myNamespaces.length) {
1054
+ generate(
1055
+ 'Namespace',
1056
+ myNamespaces[0].name,
1057
+ myNamespaces,
1058
+ helper.longnameToUrl[longname]
1059
+ );
1060
+ }
1061
+
1062
+ var myMixins = helper.find(mixins, { longname: longname });
1063
+
1064
+ if (myMixins.length) {
1065
+ generate(
1066
+ 'Mixin',
1067
+ myMixins[0].name,
1068
+ myMixins,
1069
+ helper.longnameToUrl[longname]
1070
+ );
1071
+ }
1072
+
1073
+ var myExternals = helper.find(externals, { longname: longname });
1074
+
1075
+ if (myExternals.length) {
1076
+ generate(
1077
+ 'External',
1078
+ myExternals[0].name,
1079
+ myExternals,
1080
+ helper.longnameToUrl[longname]
1081
+ );
1082
+ }
1083
+
1084
+ var myInterfaces = helper.find(interfaces, { longname: longname });
1085
+
1086
+ if (myInterfaces.length) {
1087
+ generate(
1088
+ 'Interface',
1089
+ myInterfaces[0].name,
1090
+ myInterfaces,
1091
+ helper.longnameToUrl[longname]
1092
+ );
1093
+ }
1094
+ });
1095
+
1096
+ // TODO: move the tutorial functions to templateHelper.js
1097
+ function generateTutorial(title, tutorial, filename) {
1098
+ var tutorialData = {
1099
+ title: title,
1100
+ header: tutorial.title,
1101
+ content: tutorial.parse(),
1102
+ children: tutorial.children
1103
+ };
1104
+
1105
+ var tutorialPath = path.join(outdir, filename);
1106
+ var html = view.render('tutorial.tmpl', tutorialData);
1107
+
1108
+ // yes, you can use {@link} in tutorials too!
1109
+ html = helper.resolveLinks(html); // turn {@link foo} into <a href="foodoc.html">foo</a>
1110
+
1111
+ fs.writeFileSync(
1112
+ tutorialPath,
1113
+ htmlMinify.minify(html, HTML_MINIFY_OPTIONS),
1114
+ 'utf8'
1115
+ );
1116
+ }
1117
+
1118
+ // tutorials can have only one parent so there is no risk for loops
1119
+ function saveChildren(node) {
1120
+ node.children.forEach(function(child) {
1121
+ generateTutorial(
1122
+ 'Tutorial: ' + child.title,
1123
+ child,
1124
+ helper.tutorialToUrl(child.name)
1125
+ );
1126
+ saveChildren(child);
1127
+ });
1128
+ }
1129
+
1130
+ saveChildren(tutorials);
1131
+ };