clean-jsdoc-theme 4.1.7 → 4.1.8

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 (68) hide show
  1. package/.eslintignore +5 -5
  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/dependabot.yml +9 -9
  6. package/.github/pull_request_template.md +16 -16
  7. package/.github/workflows/codeql.yml +72 -72
  8. package/.github/workflows/greetings.yml +16 -16
  9. package/.prettierignore +1 -2
  10. package/.prettierrc +5 -5
  11. package/.stylelintignore +4 -4
  12. package/.stylelintrc +18 -23
  13. package/.travis.yml +30 -30
  14. package/CHANGELOG.md +256 -235
  15. package/CODE_OF_CONDUCT.md +76 -76
  16. package/CODE_OF_CONDUCT_HINDI.md +61 -46
  17. package/CONTRIBUTING.md +36 -24
  18. package/LICENSE +21 -21
  19. package/README.md +497 -456
  20. package/SECURITY.md +21 -21
  21. package/css.js +124 -0
  22. package/helpers/down-arrow.js +9 -9
  23. package/jsdoc-config.json +62 -61
  24. package/minify.js +60 -56
  25. package/package.json +52 -50
  26. package/publish.js +1130 -1129
  27. package/static/scripts/core.js +662 -656
  28. package/static/scripts/core.min.js +2 -2
  29. package/static/scripts/resize.js +90 -90
  30. package/static/scripts/search.js +262 -262
  31. package/static/scripts/third-party/Apache-License-2.0.txt +202 -202
  32. package/static/scripts/third-party/fuse.js +8 -8
  33. package/static/scripts/third-party/hljs-line-num-original.js +369 -365
  34. package/static/scripts/third-party/hljs-line-num.js +1 -1
  35. package/static/scripts/third-party/hljs-original.js +5162 -5162
  36. package/static/scripts/third-party/popper.js +5 -5
  37. package/static/scripts/third-party/tippy.js +1 -1
  38. package/static/scripts/third-party/tocbot.js +672 -1
  39. package/static/scripts/third-party/tocbot.min.js +1 -0
  40. package/static/styles/clean-jsdoc-theme-base.css +968 -968
  41. package/static/styles/clean-jsdoc-theme-dark.css +407 -407
  42. package/static/styles/clean-jsdoc-theme-light.css +388 -388
  43. package/tmpl/augments.tmpl +10 -10
  44. package/tmpl/container.tmpl +190 -190
  45. package/tmpl/details.tmpl +207 -207
  46. package/tmpl/example.tmpl +3 -3
  47. package/tmpl/examples.tmpl +40 -40
  48. package/tmpl/exceptions.tmpl +32 -32
  49. package/tmpl/icons.tmpl +72 -72
  50. package/tmpl/layout.tmpl +157 -157
  51. package/tmpl/mainpage.tmpl +10 -10
  52. package/tmpl/members.tmpl +42 -42
  53. package/tmpl/method.tmpl +139 -139
  54. package/tmpl/mobile-sidebar.tmpl +20 -20
  55. package/tmpl/navbar-actions.tmpl +18 -18
  56. package/tmpl/navbar-menu.tmpl +24 -24
  57. package/tmpl/navbar.tmpl +13 -13
  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 +16 -16
  62. package/tmpl/sidebar-items.tmpl +23 -23
  63. package/tmpl/sidebar-title.tmpl +9 -9
  64. package/tmpl/sidebar.tmpl +8 -8
  65. package/tmpl/source.tmpl +12 -12
  66. package/tmpl/toc.tmpl +3 -3
  67. package/tmpl/tutorial.tmpl +19 -19
  68. package/tmpl/type.tmpl +12 -7
package/publish.js CHANGED
@@ -1,1129 +1,1130 @@
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
- return themeOpts.base_url;
504
- }
505
-
506
- function buildSidebarMembers({
507
- items,
508
- itemHeading,
509
- itemsSeen,
510
- linktoFn,
511
- sectionName
512
- }) {
513
- const navProps = {
514
- name: itemHeading,
515
- items: [],
516
- id: nanoid()
517
- };
518
-
519
- if (items.length) {
520
- items.forEach(function(item) {
521
- const currentItem = {
522
- name: item.name,
523
- anchor: item.longname ?
524
- linktoFn(item.longname, item.name) :
525
- linktoFn('', item.name),
526
- children: []
527
- };
528
-
529
- var methods =
530
- sectionName === SECTION_TYPE.Tutorials ||
531
- sectionName === SECTION_TYPE.Global ?
532
- [] :
533
- find({
534
- kind: 'function',
535
- memberof: item.longname,
536
- inherited: {
537
- '!is': Boolean(themeOpts.exclude_inherited)
538
- }
539
- });
540
-
541
- if (!hasOwnProp.call(itemsSeen, item.longname)) {
542
- currentItem.anchor = linktoFn(
543
- item.longname,
544
- item.name.replace(/^module:/, '')
545
- );
546
-
547
- if (hasSearch) {
548
- searchListArray.push({
549
- title: item.name,
550
- link: linktoFn(item.longname, item.name),
551
- description: item.description
552
- });
553
- }
554
-
555
- if (methods.length) {
556
- methods.forEach(function(method) {
557
- const itemChild = {
558
- name: method.longName,
559
- link: linktoFn(method.longname, method.name)
560
- };
561
-
562
- currentItem.children.push(itemChild);
563
-
564
- var name = method.longname.split(
565
- method.scope === 'static' ? '.' : '#'
566
- );
567
- var first = name[0];
568
- var last = name[1];
569
-
570
- name = first + ' &rtrif; ' + last;
571
-
572
- if (hasSearch) {
573
- searchListArray.push({
574
- title: method.longname,
575
- link: linktoFn(method.longname, name),
576
- description: item.classdesc
577
- });
578
- }
579
- });
580
- }
581
- itemsSeen[item.longname] = true;
582
- }
583
-
584
- navProps.items.push(currentItem);
585
- });
586
- }
587
-
588
- return navProps;
589
- }
590
-
591
- function linktoTutorial(longName, name) {
592
- return tutoriallink(name);
593
- }
594
-
595
- function linktoExternal(longName, name) {
596
- return linkto(longName, name.replace(/(^"|"$)/g, ''));
597
- }
598
-
599
- function buildNavbar() {
600
- return {
601
- menu: themeOpts.menu || undefined,
602
- search: hasSearch
603
- };
604
- }
605
-
606
- /**
607
- * Create the navigation sidebar.
608
- * @param {object} members The members that will be used to create the sidebar.
609
- * @param {array<object>} members.classes
610
- * @param {array<object>} members.externals
611
- * @param {array<object>} members.globals
612
- * @param {array<object>} members.mixins
613
- * @param {array<object>} members.modules
614
- * @param {array<object>} members.namespaces
615
- * @param {array<object>} members.tutorials
616
- * @param {array<object>} members.events
617
- * @param {array<object>} members.interfaces
618
- * @return {string} The HTML for the navigation sidebar.
619
- */
620
- function buildSidebar(members) {
621
- var title = themeOpts.title || 'Home';
622
-
623
- var isHTML = RegExp.prototype.test.bind(/(<([^>]+)>)/i);
624
-
625
- var nav = {
626
- sections: []
627
- };
628
-
629
- if (!isHTML(title)) {
630
- nav.title = {
631
- title,
632
- isHTML: false
633
- };
634
- } else {
635
- nav.title = {
636
- title,
637
- isHTML: true
638
- };
639
- }
640
-
641
- var seen = {};
642
- var seenTutorials = {};
643
- var seenGlobal = {};
644
-
645
- var sectionsOrder = themeOpts.sections || defaultSections;
646
-
647
- var sections = {
648
- [SECTION_TYPE.Modules]: buildSidebarMembers({
649
- itemHeading: 'Modules',
650
- items: members.modules,
651
- itemsSeen: seen,
652
- linktoFn: linkto,
653
- sectionName: SECTION_TYPE.Modules
654
- }),
655
-
656
- [SECTION_TYPE.Classes]: buildSidebarMembers({
657
- itemHeading: 'Classes',
658
- items: members.classes,
659
- itemsSeen: seen,
660
- linktoFn: linkto,
661
- sectionName: SECTION_TYPE.Classes
662
- }),
663
-
664
- [SECTION_TYPE.Externals]: buildSidebarMembers({
665
- itemHeading: 'Externals',
666
- items: members.externals,
667
- itemsSeen: seen,
668
- linktoFn: linktoExternal,
669
- sectionName: SECTION_TYPE.Externals
670
- }),
671
-
672
- [SECTION_TYPE.Events]: buildSidebarMembers({
673
- itemHeading: 'Events',
674
- items: members.events,
675
- itemsSeen: seen,
676
- linktoFn: linkto,
677
- sectionName: SECTION_TYPE.Events
678
- }),
679
-
680
- [SECTION_TYPE.Namespaces]: buildSidebarMembers({
681
- itemHeading: 'Namespaces',
682
- items: members.namespaces,
683
- itemsSeen: seen,
684
- linktoFn: linkto,
685
- sectionName: SECTION_TYPE.Namespaces
686
- }),
687
-
688
- [SECTION_TYPE.Mixins]: buildSidebarMembers({
689
- itemHeading: 'Mixins',
690
- items: members.mixins,
691
- itemsSeen: seen,
692
- linktoFn: linkto,
693
- sectionName: SECTION_TYPE.Mixins
694
- }),
695
-
696
- [SECTION_TYPE.Tutorials]: buildSidebarMembers({
697
- itemHeading: 'Tutorials',
698
- items: members.tutorials,
699
- itemsSeen: seenTutorials,
700
- linktoFn: linktoTutorial,
701
- sectionName: SECTION_TYPE.Tutorials
702
- }),
703
-
704
- [SECTION_TYPE.Interfaces]: buildSidebarMembers({
705
- itemHeading: 'Interfaces',
706
- items: members.interfaces,
707
- itemsSeen: seen,
708
- linktoFn: linkto,
709
- sectionName: SECTION_TYPE.Interfaces
710
- }),
711
-
712
- [SECTION_TYPE.Global]: buildSidebarMembers({
713
- itemHeading: 'Global',
714
- items: members.globals,
715
- itemsSeen: seenGlobal,
716
- linktoFn: linkto,
717
- sectionName: SECTION_TYPE.Global
718
- })
719
- };
720
-
721
- sectionsOrder.forEach((section) => {
722
- if (SECTION_TYPE[section] !== undefined) {
723
- nav.sections.push(sections[section]);
724
- } else {
725
- var errorMsg = `While building nav. Section name: ${section} is not recognized.
726
- Accepted sections are: ${defaultSections.join(', ')}
727
- `;
728
-
729
- throw new Error(errorMsg);
730
- }
731
- });
732
-
733
- return nav;
734
- }
735
-
736
- /**
737
- @param {TAFFY} taffyData See <http://taffydb.com/>.
738
- @param {object} opts
739
- @param {Tutorial} tutorials
740
- */
741
- exports.publish = function(taffyData, opts, tutorials) {
742
- data = taffyData;
743
-
744
- // eslint-disable-next-line no-restricted-globals
745
- var conf = env.conf.templates || {};
746
-
747
- conf.default = conf.default || {};
748
-
749
- var templatePath = path.normalize(opts.template);
750
-
751
- view = new template.Template(path.join(templatePath, 'tmpl'));
752
-
753
- // claim some special filenames in advance, so the All-Powerful Overseer of Filename Uniqueness
754
- // doesn't try to hand them out later
755
- var indexUrl = helper.getUniqueFilename('index');
756
- // don't call registerLink() on this one! 'index' is also a valid longname
757
-
758
- var globalUrl = helper.getUniqueFilename('global');
759
-
760
- helper.registerLink('global', globalUrl);
761
-
762
- // set up templating
763
- view.layout = conf.default.layoutFile ?
764
- path.getResourcePath(
765
- path.dirname(conf.default.layoutFile),
766
- path.basename(conf.default.layoutFile)
767
- ) :
768
- 'layout.tmpl';
769
-
770
- // set up tutorials for helper
771
- helper.setTutorials(tutorials);
772
-
773
- data = helper.prune(data);
774
- data.sort('longname, version, since');
775
- helper.addEventListeners(data);
776
-
777
- var sourceFiles = {};
778
- var sourceFilePaths = [];
779
-
780
- data().each(function(doclet) {
781
- doclet.attribs = '';
782
-
783
- if (doclet.examples) {
784
- doclet.examples = doclet.examples.map(function(example) {
785
- var caption, code;
786
-
787
- if (example === undefined) {
788
- return {
789
- caption: '',
790
- code: ''
791
- };
792
- }
793
-
794
- if (
795
- example.match(
796
- /^\s*<caption>([\s\S]+?)<\/caption>(\s*[\n\r])([\s\S]+)$/i
797
- )
798
- ) {
799
- caption = RegExp.$1;
800
- code = RegExp.$3;
801
- }
802
-
803
- return {
804
- caption: caption || '',
805
- code: code || example
806
- };
807
- });
808
- }
809
- if (doclet.see) {
810
- doclet.see.forEach(function(seeItem, i) {
811
- doclet.see[i] = hashToLink(doclet, seeItem);
812
- });
813
- }
814
-
815
- // build a list of source files
816
- var sourcePath;
817
-
818
- if (doclet.meta) {
819
- sourcePath = getPathFromDoclet(doclet);
820
- sourceFiles[sourcePath] = {
821
- resolved: sourcePath,
822
- shortened: null
823
- };
824
- if (sourceFilePaths.indexOf(sourcePath) === -1) {
825
- sourceFilePaths.push(sourcePath);
826
- }
827
- }
828
- });
829
-
830
- // update outdir if necessary, then create outdir
831
- var packageInfo = (find({ kind: 'package' }) || [])[0];
832
-
833
- if (packageInfo && packageInfo.name) {
834
- outdir = path.join(outdir, packageInfo.name, packageInfo.version || '');
835
- }
836
- fs.mkPath(outdir);
837
-
838
- // copy the template's static files to outdir
839
- var fromDir = path.join(templatePath, 'static');
840
- var staticFiles = fs.ls(fromDir, 3);
841
-
842
- staticFiles.forEach(function(fileName) {
843
- var toDir = fs.toDir(fileName.replace(fromDir, outdir));
844
-
845
- fs.mkPath(toDir);
846
- fs.copyFileSync(fileName, toDir);
847
- });
848
-
849
- // copy user-specified static files to outdir
850
- var staticFilePaths;
851
- var staticFileFilter;
852
- var staticFileScanner;
853
-
854
- if (conf.default.staticFiles) {
855
- // The canonical property name is `include`. We accept `paths` for backwards compatibility
856
- // with a bug in JSDoc 3.2.x.
857
- staticFilePaths =
858
- conf.default.staticFiles.include ||
859
- conf.default.staticFiles.paths ||
860
- [];
861
- staticFileFilter = new (require('jsdoc/src/filter').Filter)(
862
- conf.default.staticFiles
863
- );
864
- staticFileScanner = new (require('jsdoc/src/scanner').Scanner)();
865
-
866
- staticFilePaths.forEach(function(filePath) {
867
- var extraStaticFiles = staticFileScanner.scan(
868
- [filePath],
869
- 10,
870
- staticFileFilter
871
- );
872
-
873
- extraStaticFiles.forEach(function(fileName) {
874
- var sourcePath = fs.toDir(filePath);
875
- var toDir = fs.toDir(fileName.replace(sourcePath, outdir));
876
-
877
- fs.mkPath(toDir);
878
- fs.copyFileSync(fileName, toDir);
879
- });
880
- });
881
- }
882
-
883
- if (sourceFilePaths.length) {
884
- sourceFiles = shortenPaths(
885
- sourceFiles,
886
- path.commonPrefix(sourceFilePaths)
887
- );
888
- }
889
- data().each(function(doclet) {
890
- var url = helper.createLink(doclet);
891
-
892
- helper.registerLink(doclet.longname, url);
893
-
894
- // add a shortened version of the full path
895
- var docletPath;
896
-
897
- if (doclet.meta) {
898
- docletPath = getPathFromDoclet(doclet);
899
- docletPath = sourceFiles[docletPath].shortened;
900
- if (docletPath) {
901
- doclet.meta.shortpath = docletPath;
902
- }
903
- }
904
- });
905
-
906
- data().each(function(doclet) {
907
- var url = helper.longnameToUrl[doclet.longname];
908
-
909
- if (url.indexOf('#') > -1) {
910
- doclet.id = helper.longnameToUrl[doclet.longname].split(/#/).pop();
911
- } else {
912
- doclet.id = doclet.name;
913
- }
914
-
915
- if (needsSignature(doclet)) {
916
- addSignatureParams(doclet);
917
- addSignatureReturns(doclet);
918
- addAttribs(doclet);
919
- }
920
- });
921
-
922
- // do this after the urls have all been generated
923
- data().each(function(doclet) {
924
- doclet.ancestors = getAncestorLinks(doclet);
925
-
926
- if (doclet.kind === 'member') {
927
- addSignatureTypes(doclet);
928
- addAttribs(doclet);
929
- }
930
-
931
- if (doclet.kind === 'constant') {
932
- addSignatureTypes(doclet);
933
- addAttribs(doclet);
934
- doclet.kind = 'member';
935
- }
936
- });
937
-
938
- var members = helper.getMembers(data);
939
-
940
- members.tutorials = tutorials.children;
941
-
942
- // output pretty-printed source files by default
943
- var outputSourceFiles = Boolean(
944
- conf.default && conf.default.outputSourceFiles !== false
945
- );
946
-
947
- // add template helpers
948
- view.find = find;
949
- view.linkto = linkto;
950
- view.resolveAuthorLinks = resolveAuthorLinks;
951
- view.tutoriallink = tutoriallink;
952
- view.htmlsafe = htmlsafe;
953
- view.outputSourceFiles = outputSourceFiles;
954
- view.footer = buildFooter();
955
- view.favicon = getFavicon();
956
- view.dynamicStyle = createDynamicStyleSheet();
957
- view.dynamicStyleSrc = returnPathOfStyleSrc();
958
- view.dynamicScript = createDynamicsScripts();
959
- view.dynamicScriptSrc = returnPathOfScriptScr();
960
- view.includeScript = includeScript();
961
- view.includeCss = includeCss();
962
- view.meta = getMetaTagData();
963
- view.theme = getTheme();
964
- // once for all
965
- view.sidebar = buildSidebar(members);
966
- view.navbar = buildNavbar();
967
- view.resizeable = resizeable();
968
- view.codepen = codepen();
969
- view.baseURL = getBaseURL();
970
- view.excludeInherited = Boolean(themeOpts.exclude_inherited);
971
- attachModuleSymbols(
972
- find({ longname: { left: 'module:' } }),
973
- members.modules
974
- );
975
-
976
- // output search file if search
977
-
978
- if (hasSearch) {
979
- fs.mkPath(path.join(outdir, 'data'));
980
- fs.writeFileSync(
981
- path.join(outdir, 'data', 'search.json'),
982
- JSON.stringify({
983
- list: searchListArray
984
- })
985
- );
986
- }
987
-
988
- // generate the pretty-printed source files first so other pages can link to them
989
- if (outputSourceFiles) {
990
- generateSourceFiles(sourceFiles, opts.encoding);
991
- }
992
-
993
- if (members.globals.length) {
994
- generate('', 'Global', [{ kind: 'globalobj' }], globalUrl);
995
- }
996
-
997
- // index page displays information from package.json and lists files
998
- var files = find({ kind: 'file' });
999
- var packages = find({ kind: 'package' });
1000
-
1001
- generate(
1002
- '',
1003
- 'Home',
1004
- packages
1005
- .concat([
1006
- {
1007
- kind: 'mainpage',
1008
- readme: opts.readme,
1009
- longname: opts.mainpagetitle ?
1010
- opts.mainpagetitle :
1011
- 'Main Page'
1012
- }
1013
- ])
1014
- .concat(files),
1015
- indexUrl
1016
- );
1017
-
1018
- // set up the lists that we'll use to generate pages
1019
- var classes = taffy(members.classes);
1020
- var modules = taffy(members.modules);
1021
- var namespaces = taffy(members.namespaces);
1022
- var mixins = taffy(members.mixins);
1023
- var externals = taffy(members.externals);
1024
- var interfaces = taffy(members.interfaces);
1025
-
1026
- Object.keys(helper.longnameToUrl).forEach(function(longname) {
1027
- var myModules = helper.find(modules, { longname: longname });
1028
-
1029
- if (myModules.length) {
1030
- generate(
1031
- 'Module',
1032
- myModules[0].name,
1033
- myModules,
1034
- helper.longnameToUrl[longname]
1035
- );
1036
- }
1037
-
1038
- var myClasses = helper.find(classes, { longname: longname });
1039
-
1040
- if (myClasses.length) {
1041
- generate(
1042
- 'Class',
1043
- myClasses[0].name,
1044
- myClasses,
1045
- helper.longnameToUrl[longname]
1046
- );
1047
- }
1048
-
1049
- var myNamespaces = helper.find(namespaces, { longname: longname });
1050
-
1051
- if (myNamespaces.length) {
1052
- generate(
1053
- 'Namespace',
1054
- myNamespaces[0].name,
1055
- myNamespaces,
1056
- helper.longnameToUrl[longname]
1057
- );
1058
- }
1059
-
1060
- var myMixins = helper.find(mixins, { longname: longname });
1061
-
1062
- if (myMixins.length) {
1063
- generate(
1064
- 'Mixin',
1065
- myMixins[0].name,
1066
- myMixins,
1067
- helper.longnameToUrl[longname]
1068
- );
1069
- }
1070
-
1071
- var myExternals = helper.find(externals, { longname: longname });
1072
-
1073
- if (myExternals.length) {
1074
- generate(
1075
- 'External',
1076
- myExternals[0].name,
1077
- myExternals,
1078
- helper.longnameToUrl[longname]
1079
- );
1080
- }
1081
-
1082
- var myInterfaces = helper.find(interfaces, { longname: longname });
1083
-
1084
- if (myInterfaces.length) {
1085
- generate(
1086
- 'Interface',
1087
- myInterfaces[0].name,
1088
- myInterfaces,
1089
- helper.longnameToUrl[longname]
1090
- );
1091
- }
1092
- });
1093
-
1094
- // TODO: move the tutorial functions to templateHelper.js
1095
- function generateTutorial(title, tutorial, filename) {
1096
- var tutorialData = {
1097
- title: title,
1098
- header: tutorial.title,
1099
- content: tutorial.parse(),
1100
- children: tutorial.children
1101
- };
1102
-
1103
- var tutorialPath = path.join(outdir, filename);
1104
- var html = view.render('tutorial.tmpl', tutorialData);
1105
-
1106
- // yes, you can use {@link} in tutorials too!
1107
- html = helper.resolveLinks(html); // turn {@link foo} into <a href="foodoc.html">foo</a>
1108
-
1109
- fs.writeFileSync(
1110
- tutorialPath,
1111
- htmlMinify.minify(html, HTML_MINIFY_OPTIONS),
1112
- 'utf8'
1113
- );
1114
- }
1115
-
1116
- // tutorials can have only one parent so there is no risk for loops
1117
- function saveChildren(node) {
1118
- node.children.forEach(function(child) {
1119
- generateTutorial(
1120
- 'Tutorial: ' + child.title,
1121
- child,
1122
- helper.tutorialToUrl(child.name)
1123
- );
1124
- saveChildren(child);
1125
- });
1126
- }
1127
-
1128
- saveChildren(tutorials);
1129
- };
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
+ return themeOpts.base_url;
504
+ }
505
+
506
+ function buildSidebarMembers({
507
+ items,
508
+ itemHeading,
509
+ itemsSeen,
510
+ linktoFn,
511
+ sectionName
512
+ }) {
513
+ const navProps = {
514
+ name: itemHeading,
515
+ items: [],
516
+ id: nanoid()
517
+ };
518
+
519
+ if (items.length) {
520
+ items.forEach(function (item) {
521
+ const currentItem = {
522
+ name: item.name,
523
+ anchor: item.longname
524
+ ? linktoFn(item.longname, item.name)
525
+ : linktoFn('', item.name),
526
+ children: []
527
+ };
528
+
529
+ var methods =
530
+ sectionName === SECTION_TYPE.Tutorials ||
531
+ sectionName === SECTION_TYPE.Global
532
+ ? []
533
+ : find({
534
+ kind: 'function',
535
+ memberof: item.longname,
536
+ inherited: {
537
+ '!is': Boolean(themeOpts.exclude_inherited)
538
+ }
539
+ });
540
+
541
+ if (!hasOwnProp.call(itemsSeen, item.longname)) {
542
+ currentItem.anchor = linktoFn(
543
+ item.longname,
544
+ item.name.replace(/^module:/, '')
545
+ );
546
+
547
+ if (hasSearch) {
548
+ searchListArray.push({
549
+ title: item.name,
550
+ link: linktoFn(item.longname, item.name),
551
+ description: item.description
552
+ });
553
+ }
554
+
555
+ if (methods.length) {
556
+ methods.forEach(function (method) {
557
+ const itemChild = {
558
+ name: method.longName,
559
+ link: linktoFn(method.longname, method.name)
560
+ };
561
+
562
+ currentItem.children.push(itemChild);
563
+
564
+ var name = method.longname.split(
565
+ method.scope === 'static' ? '.' : '#'
566
+ );
567
+ var first = name[0];
568
+ var last = name[1];
569
+
570
+ name = first + ' &rtrif; ' + last;
571
+
572
+ if (hasSearch) {
573
+ searchListArray.push({
574
+ title: method.longname,
575
+ link: linktoFn(method.longname, name),
576
+ description: item.classdesc
577
+ });
578
+ }
579
+ });
580
+ }
581
+ itemsSeen[item.longname] = true;
582
+ }
583
+
584
+ navProps.items.push(currentItem);
585
+ });
586
+ }
587
+
588
+ return navProps;
589
+ }
590
+
591
+ function linktoTutorial(longName, name) {
592
+ return tutoriallink(name);
593
+ }
594
+
595
+ function linktoExternal(longName, name) {
596
+ return linkto(longName, name.replace(/(^"|"$)/g, ''));
597
+ }
598
+
599
+ function buildNavbar() {
600
+ return {
601
+ menu: themeOpts.menu || undefined,
602
+ search: hasSearch
603
+ };
604
+ }
605
+
606
+ /**
607
+ * Create the navigation sidebar.
608
+ * @param {object} members The members that will be used to create the sidebar.
609
+ * @param {array<object>} members.classes
610
+ * @param {array<object>} members.externals
611
+ * @param {array<object>} members.globals
612
+ * @param {array<object>} members.mixins
613
+ * @param {array<object>} members.modules
614
+ * @param {array<object>} members.namespaces
615
+ * @param {array<object>} members.tutorials
616
+ * @param {array<object>} members.events
617
+ * @param {array<object>} members.interfaces
618
+ * @return {string} The HTML for the navigation sidebar.
619
+ */
620
+ function buildSidebar(members) {
621
+ var title = themeOpts.title || 'Home';
622
+
623
+ var isHTML = RegExp.prototype.test.bind(/(<([^>]+)>)/i);
624
+
625
+ var nav = {
626
+ sections: []
627
+ };
628
+
629
+ if (!isHTML(title)) {
630
+ nav.title = {
631
+ title,
632
+ isHTML: false
633
+ };
634
+ } else {
635
+ nav.title = {
636
+ title,
637
+ isHTML: true
638
+ };
639
+ }
640
+
641
+ var seen = {};
642
+ var seenTutorials = {};
643
+ var seenGlobal = {};
644
+
645
+ var sectionsOrder = themeOpts.sections || defaultSections;
646
+
647
+ var sections = {
648
+ [SECTION_TYPE.Modules]: buildSidebarMembers({
649
+ itemHeading: 'Modules',
650
+ items: members.modules,
651
+ itemsSeen: seen,
652
+ linktoFn: linkto,
653
+ sectionName: SECTION_TYPE.Modules
654
+ }),
655
+
656
+ [SECTION_TYPE.Classes]: buildSidebarMembers({
657
+ itemHeading: 'Classes',
658
+ items: members.classes,
659
+ itemsSeen: seen,
660
+ linktoFn: linkto,
661
+ sectionName: SECTION_TYPE.Classes
662
+ }),
663
+
664
+ [SECTION_TYPE.Externals]: buildSidebarMembers({
665
+ itemHeading: 'Externals',
666
+ items: members.externals,
667
+ itemsSeen: seen,
668
+ linktoFn: linktoExternal,
669
+ sectionName: SECTION_TYPE.Externals
670
+ }),
671
+
672
+ [SECTION_TYPE.Events]: buildSidebarMembers({
673
+ itemHeading: 'Events',
674
+ items: members.events,
675
+ itemsSeen: seen,
676
+ linktoFn: linkto,
677
+ sectionName: SECTION_TYPE.Events
678
+ }),
679
+
680
+ [SECTION_TYPE.Namespaces]: buildSidebarMembers({
681
+ itemHeading: 'Namespaces',
682
+ items: members.namespaces,
683
+ itemsSeen: seen,
684
+ linktoFn: linkto,
685
+ sectionName: SECTION_TYPE.Namespaces
686
+ }),
687
+
688
+ [SECTION_TYPE.Mixins]: buildSidebarMembers({
689
+ itemHeading: 'Mixins',
690
+ items: members.mixins,
691
+ itemsSeen: seen,
692
+ linktoFn: linkto,
693
+ sectionName: SECTION_TYPE.Mixins
694
+ }),
695
+
696
+ [SECTION_TYPE.Tutorials]: buildSidebarMembers({
697
+ itemHeading: 'Tutorials',
698
+ items: members.tutorials,
699
+ itemsSeen: seenTutorials,
700
+ linktoFn: linktoTutorial,
701
+ sectionName: SECTION_TYPE.Tutorials
702
+ }),
703
+
704
+ [SECTION_TYPE.Interfaces]: buildSidebarMembers({
705
+ itemHeading: 'Interfaces',
706
+ items: members.interfaces,
707
+ itemsSeen: seen,
708
+ linktoFn: linkto,
709
+ sectionName: SECTION_TYPE.Interfaces
710
+ }),
711
+
712
+ [SECTION_TYPE.Global]: buildSidebarMembers({
713
+ itemHeading: 'Global',
714
+ items: members.globals,
715
+ itemsSeen: seenGlobal,
716
+ linktoFn: linkto,
717
+ sectionName: SECTION_TYPE.Global
718
+ })
719
+ };
720
+
721
+ sectionsOrder.forEach((section) => {
722
+ if (SECTION_TYPE[section] !== undefined) {
723
+ nav.sections.push(sections[section]);
724
+ } else {
725
+ var errorMsg = `While building nav. Section name: ${section} is not recognized.
726
+ Accepted sections are: ${defaultSections.join(', ')}
727
+ `;
728
+
729
+ throw new Error(errorMsg);
730
+ }
731
+ });
732
+
733
+ return nav;
734
+ }
735
+
736
+ /**
737
+ @param {TAFFY} taffyData See <http://taffydb.com/>.
738
+ @param {object} opts
739
+ @param {Tutorial} tutorials
740
+ */
741
+ exports.publish = function (taffyData, opts, tutorials) {
742
+ data = taffyData;
743
+
744
+ // eslint-disable-next-line no-restricted-globals
745
+ var conf = env.conf.templates || {};
746
+
747
+ conf.default = conf.default || {};
748
+
749
+ var templatePath = path.normalize(opts.template);
750
+
751
+ view = new template.Template(path.join(templatePath, 'tmpl'));
752
+
753
+ // claim some special filenames in advance, so the All-Powerful Overseer of Filename Uniqueness
754
+ // doesn't try to hand them out later
755
+ var indexUrl = helper.getUniqueFilename('index');
756
+ // don't call registerLink() on this one! 'index' is also a valid longname
757
+
758
+ var globalUrl = helper.getUniqueFilename('global');
759
+
760
+ helper.registerLink('global', globalUrl);
761
+
762
+ // set up templating
763
+ view.layout = conf.default.layoutFile
764
+ ? path.getResourcePath(
765
+ path.dirname(conf.default.layoutFile),
766
+ path.basename(conf.default.layoutFile)
767
+ )
768
+ : 'layout.tmpl';
769
+
770
+ // set up tutorials for helper
771
+ helper.setTutorials(tutorials);
772
+
773
+ data = helper.prune(data);
774
+ data.sort('longname, version, since');
775
+ helper.addEventListeners(data);
776
+
777
+ var sourceFiles = {};
778
+ var sourceFilePaths = [];
779
+
780
+ data().each(function (doclet) {
781
+ doclet.attribs = '';
782
+
783
+ if (doclet.examples) {
784
+ doclet.examples = doclet.examples.map(function (example) {
785
+ var caption, code;
786
+
787
+ if (example === undefined) {
788
+ return {
789
+ caption: '',
790
+ code: ''
791
+ };
792
+ }
793
+
794
+ if (
795
+ example.match(
796
+ /^\s*<caption>([\s\S]+?)<\/caption>(\s*[\n\r])([\s\S]+)$/i
797
+ )
798
+ ) {
799
+ caption = RegExp.$1;
800
+ code = RegExp.$3;
801
+ }
802
+
803
+ return {
804
+ caption: caption || '',
805
+ code: code || example
806
+ };
807
+ });
808
+ }
809
+ if (doclet.see) {
810
+ doclet.see.forEach(function (seeItem, i) {
811
+ doclet.see[i] = hashToLink(doclet, seeItem);
812
+ });
813
+ }
814
+
815
+ // build a list of source files
816
+ var sourcePath;
817
+
818
+ if (doclet.meta) {
819
+ sourcePath = getPathFromDoclet(doclet);
820
+ sourceFiles[sourcePath] = {
821
+ resolved: sourcePath,
822
+ shortened: null
823
+ };
824
+ if (sourceFilePaths.indexOf(sourcePath) === -1) {
825
+ sourceFilePaths.push(sourcePath);
826
+ }
827
+ }
828
+ });
829
+
830
+ // update outdir if necessary, then create outdir
831
+ var packageInfo = (find({ kind: 'package' }) || [])[0];
832
+
833
+ if (packageInfo && packageInfo.name) {
834
+ outdir = path.join(outdir, packageInfo.name, packageInfo.version || '');
835
+ }
836
+ fs.mkPath(outdir);
837
+
838
+ // copy the template's static files to outdir
839
+ var fromDir = path.join(templatePath, 'static');
840
+ var staticFiles = fs.ls(fromDir, 3);
841
+
842
+ staticFiles.forEach(function (fileName) {
843
+ var toDir = fs.toDir(fileName.replace(fromDir, outdir));
844
+
845
+ fs.mkPath(toDir);
846
+ fs.copyFileSync(fileName, toDir);
847
+ });
848
+
849
+ // copy user-specified static files to outdir
850
+ var staticFilePaths;
851
+ var staticFileFilter;
852
+ var staticFileScanner;
853
+
854
+ if (conf.default.staticFiles) {
855
+ // The canonical property name is `include`. We accept `paths` for backwards compatibility
856
+ // with a bug in JSDoc 3.2.x.
857
+ staticFilePaths =
858
+ conf.default.staticFiles.include ||
859
+ conf.default.staticFiles.paths ||
860
+ [];
861
+ staticFileFilter = new (require('jsdoc/src/filter').Filter)(
862
+ conf.default.staticFiles
863
+ );
864
+ staticFileScanner = new (require('jsdoc/src/scanner').Scanner)();
865
+
866
+ staticFilePaths.forEach(function (filePath) {
867
+ var extraStaticFiles = staticFileScanner.scan(
868
+ [filePath],
869
+ 10,
870
+ staticFileFilter
871
+ );
872
+
873
+ extraStaticFiles.forEach(function (fileName) {
874
+ var sourcePath = fs.toDir(filePath);
875
+ var toDir = fs.toDir(fileName.replace(sourcePath, outdir));
876
+
877
+ fs.mkPath(toDir);
878
+ fs.copyFileSync(fileName, toDir);
879
+ });
880
+ });
881
+ }
882
+
883
+ if (sourceFilePaths.length) {
884
+ sourceFiles = shortenPaths(
885
+ sourceFiles,
886
+ path.commonPrefix(sourceFilePaths)
887
+ );
888
+ }
889
+ data().each(function (doclet) {
890
+ var url = helper.createLink(doclet);
891
+
892
+ helper.registerLink(doclet.longname, url);
893
+
894
+ // add a shortened version of the full path
895
+ var docletPath;
896
+
897
+ if (doclet.meta) {
898
+ docletPath = getPathFromDoclet(doclet);
899
+ docletPath = sourceFiles[docletPath].shortened;
900
+ if (docletPath) {
901
+ doclet.meta.shortpath = docletPath;
902
+ }
903
+ }
904
+ });
905
+
906
+ data().each(function (doclet) {
907
+ var url = helper.longnameToUrl[doclet.longname];
908
+
909
+ if (url.indexOf('#') > -1) {
910
+ doclet.id = helper.longnameToUrl[doclet.longname].split(/#/).pop();
911
+ } else {
912
+ doclet.id = doclet.name;
913
+ }
914
+
915
+ if (needsSignature(doclet)) {
916
+ addSignatureParams(doclet);
917
+ addSignatureReturns(doclet);
918
+ addAttribs(doclet);
919
+ }
920
+ });
921
+
922
+ // do this after the urls have all been generated
923
+ data().each(function (doclet) {
924
+ doclet.ancestors = getAncestorLinks(doclet);
925
+
926
+ if (doclet.kind === 'member') {
927
+ addSignatureTypes(doclet);
928
+ addAttribs(doclet);
929
+ }
930
+
931
+ if (doclet.kind === 'constant') {
932
+ addSignatureTypes(doclet);
933
+ addAttribs(doclet);
934
+ doclet.kind = 'member';
935
+ }
936
+ });
937
+
938
+ var members = helper.getMembers(data);
939
+
940
+ members.tutorials = tutorials.children;
941
+
942
+ // output pretty-printed source files by default
943
+ var outputSourceFiles = Boolean(
944
+ conf.default && conf.default.outputSourceFiles !== false
945
+ );
946
+
947
+ // add template helpers
948
+ view.find = find;
949
+ view.linkto = linkto;
950
+ view.resolveAuthorLinks = resolveAuthorLinks;
951
+ view.tutoriallink = tutoriallink;
952
+ view.htmlsafe = htmlsafe;
953
+ view.outputSourceFiles = outputSourceFiles;
954
+ view.footer = buildFooter();
955
+ view.favicon = getFavicon();
956
+ view.dynamicStyle = createDynamicStyleSheet();
957
+ view.dynamicStyleSrc = returnPathOfStyleSrc();
958
+ view.dynamicScript = createDynamicsScripts();
959
+ view.dynamicScriptSrc = returnPathOfScriptScr();
960
+ view.includeScript = includeScript();
961
+ view.includeCss = includeCss();
962
+ view.meta = getMetaTagData();
963
+ view.theme = getTheme();
964
+ // once for all
965
+ view.sidebar = buildSidebar(members);
966
+ view.navbar = buildNavbar();
967
+ view.resizeable = resizeable();
968
+ view.codepen = codepen();
969
+ view.baseURL = getBaseURL();
970
+ view.excludeInherited = Boolean(themeOpts.exclude_inherited);
971
+ attachModuleSymbols(
972
+ find({ longname: { left: 'module:' } }),
973
+ members.modules
974
+ );
975
+
976
+ // output search file if search
977
+
978
+ if (hasSearch) {
979
+ fs.mkPath(path.join(outdir, 'data'));
980
+ fs.writeFileSync(
981
+ path.join(outdir, 'data', 'search.json'),
982
+ JSON.stringify({
983
+ list: searchListArray
984
+ })
985
+ );
986
+ }
987
+
988
+ // generate the pretty-printed source files first so other pages can link to them
989
+ if (outputSourceFiles) {
990
+ generateSourceFiles(sourceFiles, opts.encoding);
991
+ }
992
+
993
+ if (members.globals.length) {
994
+ generate('', 'Global', [{ kind: 'globalobj' }], globalUrl);
995
+ }
996
+
997
+ // index page displays information from package.json and lists files
998
+ var files = find({ kind: 'file' });
999
+ var packages = find({ kind: 'package' });
1000
+ var homepageTitle = themeOpts.homepageTitle || 'Home';
1001
+
1002
+ generate(
1003
+ '',
1004
+ homepageTitle,
1005
+ packages
1006
+ .concat([
1007
+ {
1008
+ kind: 'mainpage',
1009
+ readme: opts.readme,
1010
+ longname: opts.mainpagetitle
1011
+ ? opts.mainpagetitle
1012
+ : 'Main Page'
1013
+ }
1014
+ ])
1015
+ .concat(files),
1016
+ indexUrl
1017
+ );
1018
+
1019
+ // set up the lists that we'll use to generate pages
1020
+ var classes = taffy(members.classes);
1021
+ var modules = taffy(members.modules);
1022
+ var namespaces = taffy(members.namespaces);
1023
+ var mixins = taffy(members.mixins);
1024
+ var externals = taffy(members.externals);
1025
+ var interfaces = taffy(members.interfaces);
1026
+
1027
+ Object.keys(helper.longnameToUrl).forEach(function (longname) {
1028
+ var myModules = helper.find(modules, { longname: longname });
1029
+
1030
+ if (myModules.length) {
1031
+ generate(
1032
+ 'Module',
1033
+ myModules[0].name,
1034
+ myModules,
1035
+ helper.longnameToUrl[longname]
1036
+ );
1037
+ }
1038
+
1039
+ var myClasses = helper.find(classes, { longname: longname });
1040
+
1041
+ if (myClasses.length) {
1042
+ generate(
1043
+ 'Class',
1044
+ myClasses[0].name,
1045
+ myClasses,
1046
+ helper.longnameToUrl[longname]
1047
+ );
1048
+ }
1049
+
1050
+ var myNamespaces = helper.find(namespaces, { longname: longname });
1051
+
1052
+ if (myNamespaces.length) {
1053
+ generate(
1054
+ 'Namespace',
1055
+ myNamespaces[0].name,
1056
+ myNamespaces,
1057
+ helper.longnameToUrl[longname]
1058
+ );
1059
+ }
1060
+
1061
+ var myMixins = helper.find(mixins, { longname: longname });
1062
+
1063
+ if (myMixins.length) {
1064
+ generate(
1065
+ 'Mixin',
1066
+ myMixins[0].name,
1067
+ myMixins,
1068
+ helper.longnameToUrl[longname]
1069
+ );
1070
+ }
1071
+
1072
+ var myExternals = helper.find(externals, { longname: longname });
1073
+
1074
+ if (myExternals.length) {
1075
+ generate(
1076
+ 'External',
1077
+ myExternals[0].name,
1078
+ myExternals,
1079
+ helper.longnameToUrl[longname]
1080
+ );
1081
+ }
1082
+
1083
+ var myInterfaces = helper.find(interfaces, { longname: longname });
1084
+
1085
+ if (myInterfaces.length) {
1086
+ generate(
1087
+ 'Interface',
1088
+ myInterfaces[0].name,
1089
+ myInterfaces,
1090
+ helper.longnameToUrl[longname]
1091
+ );
1092
+ }
1093
+ });
1094
+
1095
+ // TODO: move the tutorial functions to templateHelper.js
1096
+ function generateTutorial(title, tutorial, filename) {
1097
+ var tutorialData = {
1098
+ title: title,
1099
+ header: tutorial.title,
1100
+ content: tutorial.parse(),
1101
+ children: tutorial.children
1102
+ };
1103
+
1104
+ var tutorialPath = path.join(outdir, filename);
1105
+ var html = view.render('tutorial.tmpl', tutorialData);
1106
+
1107
+ // yes, you can use {@link} in tutorials too!
1108
+ html = helper.resolveLinks(html); // turn {@link foo} into <a href="foodoc.html">foo</a>
1109
+
1110
+ fs.writeFileSync(
1111
+ tutorialPath,
1112
+ htmlMinify.minify(html, HTML_MINIFY_OPTIONS),
1113
+ 'utf8'
1114
+ );
1115
+ }
1116
+
1117
+ // tutorials can have only one parent so there is no risk for loops
1118
+ function saveChildren(node) {
1119
+ node.children.forEach(function (child) {
1120
+ generateTutorial(
1121
+ 'Tutorial: ' + child.title,
1122
+ child,
1123
+ helper.tutorialToUrl(child.name)
1124
+ );
1125
+ saveChildren(child);
1126
+ });
1127
+ }
1128
+
1129
+ saveChildren(tutorials);
1130
+ };