clean-jsdoc-theme 3.2.9 → 3.3.2

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