Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: Add support for documenting top-level enums #4498

Merged
merged 1 commit into from
Sep 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions docs/jsdoc-template/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@ function buildNav(members) {
[members.externals, 'Externals', seen, linktoExternal],
[members.namespaces, 'Namespaces', seen, linkto],
[members.classes, 'Classes', seen, linkto],
[members.enums, 'Enums', seen, linkto],
[members.interfaces, 'Interfaces', seen, linkto],
[members.events, 'Events', seen, linkto],
[members.mixins, 'Mixins', seen, linkto],
Expand Down Expand Up @@ -484,6 +485,7 @@ function fixUpType(type) {
exports.publish = (taffyData, opts, tutorials) => {
let classes;
let conf;
let enums;
let externals;
let files;
let fromDir;
Expand Down Expand Up @@ -733,6 +735,31 @@ exports.publish = (taffyData, opts, tutorials) => {
});

members = helper.getMembers(data);
members.enums = [];

data().each(doclet => {
if (doclet.isEnum) {
const hasParent = !!docletMap[doclet.memberof];

// Enums without parents (not attached to a class, but directly to a
// namespace) aren't recognized by jsdoc by default and need to be
// massaged into the docs separately.
if (!hasParent) {
// Temporarily call this a "class", so that we can fix the URL.
doclet.kind = 'class';
// Regenerate the URL, so that this enum gets its own page
// instead of a URL that links to an ID within a non-existent
// parent page.
delete helper.longnameToUrl[doclet.longname];
helper.createLink(doclet);
// Mark this as an enum (custom type), so that it doesn't get
// slotted with the classes.
doclet.kind = 'enum';
members.enums.push(doclet);
}
}
});

members.tutorials = tutorials.children;
if (conf.default.sortTutorialsByConfigOrder) {
members.tutorials.sort((a, b) => {
Expand Down Expand Up @@ -778,6 +805,7 @@ exports.publish = (taffyData, opts, tutorials) => {

// set up the lists that we'll use to generate pages
classes = taffy(members.classes);
enums = taffy(members.enums);
modules = taffy(members.modules);
namespaces = taffy(members.namespaces);
mixins = taffy(members.mixins);
Expand All @@ -786,6 +814,7 @@ exports.publish = (taffyData, opts, tutorials) => {

Object.keys(helper.longnameToUrl).forEach(longname => {
const myClasses = helper.find(classes, {longname: longname});
const myEnums = helper.find(enums, {longname: longname});
const myExternals = helper.find(externals, {longname: longname});
const myInterfaces = helper.find(interfaces, {longname: longname});
const myMixins = helper.find(mixins, {longname: longname});
Expand All @@ -800,6 +829,10 @@ exports.publish = (taffyData, opts, tutorials) => {
generate(`Class: ${myClasses[0].longname}`, myClasses, helper.longnameToUrl[longname]);
}

if (myEnums.length) {
generate(`Enum: ${myEnums[0].longname}`, myEnums, helper.longnameToUrl[longname]);
}

if (myNamespaces.length) {
generate(`Namespace: ${myNamespaces[0].longname}`, myNamespaces, helper.longnameToUrl[longname]);
}
Expand Down
5 changes: 4 additions & 1 deletion docs/jsdoc-template/tmpl/container.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,10 @@
return m.longname && m.longname.indexOf('module:') !== 0;
});
}
if (members && members.length && members.forEach) {

// Skip enums, since they already have their values listed under
// "Properties".
if (members && members.length && members.forEach && doc.kind != 'enum') {
?>
<h3 class="subsection-title">Members</h3>

Expand Down
1 change: 1 addition & 0 deletions docs/jsdoc.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"navOrder": [
"Tutorials",
"Classes",
"Enums",
"Interfaces",
"Events"
]
Expand Down