-
Notifications
You must be signed in to change notification settings - Fork 68
Expand file tree
/
Copy pathIdentifiersDocBuilder.js
More file actions
83 lines (72 loc) · 2.69 KB
/
IdentifiersDocBuilder.js
File metadata and controls
83 lines (72 loc) · 2.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import IceCap from 'ice-cap';
import DocBuilder from './DocBuilder.js';
import path from 'path';
import {escapeURLHash} from './util';
/**
* Identifier output builder class.
*/
export default class IdentifiersDocBuilder extends DocBuilder {
exec({writeFile, copyDir}) {
const ice = this._buildLayoutDoc();
const title = this._getTitle('Reference');
ice.load('content', this._buildIdentifierDoc());
ice.text('title', title, IceCap.MODE_WRITE);
writeFile('identifiers.html', ice.html);
}
/**
* build identifier output.
* @return {IceCap} built output.
* @private
*/
_buildIdentifierDoc() {
const ice = new IceCap(this._readTemplate('identifiers.html'));
// traverse docs and create Map<dirPath, doc[]>
const dirDocs = new Map();
const kinds = ['class', 'interface', 'function', 'variable', 'typedef', 'external'];
for (const doc of this._tags) {
if (!kinds.includes(doc.kind)) continue;
if (doc.builtinExternal) continue;
if (doc.ignore) continue;
const filePath = doc.memberof.replace(/^.*?[/]/, '');
const dirPath = path.dirname(filePath);
if (!dirDocs.has(dirPath)) dirDocs.set(dirPath, []);
dirDocs.get(dirPath).push(doc);
}
// create a summary of dir
const dirPaths = Array.from(dirDocs.keys()).sort((a, b) => a > b ? 1 : -1);
const kindOrder = {class: 0, interface: 1, function: 2, variable: 3, typedef: 4, external: 5};
ice.loop('dirSummaryWrap', dirPaths, (i, dirPath, ice) =>{
const docs = dirDocs.get(dirPath);
// see: DocBuilder#_buildNavDoc
docs.sort((a, b) => {
const kindA = a.interface ? 'interface' : a.kind;
const kindB = b.interface ? 'interface' : b.kind;
if (kindA === kindB) {
return a.longname > b.longname ? 1 : -1;
} else {
return kindOrder[kindA] > kindOrder[kindB] ? 1 : -1;
}
});
const dirPathLabel = dirPath === '.' ? '' : dirPath;
const summary = this._buildSummaryDoc(docs, `summary`, false, true);
ice.text('dirPath', dirPathLabel);
ice.attr('dirPath', 'id', escapeURLHash(dirPath));
ice.load('dirSummary', summary);
});
const dirTree = this._buildDirTree(dirPaths);
ice.load('dirTree', dirTree);
ice.drop('dirTreeWrap', !dirTree);
return ice;
}
_buildDirTree(dirPaths) {
const lines = [];
for (const dirPath of dirPaths) {
const padding = dirPath.split('/').length - 1;
const dirName = path.basename(dirPath);
if (dirName === '.') continue;
const hash = escapeURLHash(dirPath);
lines.push(`<div style="padding-left: ${padding}em"><a href="#${hash}">${dirName}</a></div>`);
}
return lines.join('\n');
}
}