Skip to content

docs: sort class properties and methods #6893

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

Merged
merged 2 commits into from
Sep 8, 2017
Merged
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
38 changes: 38 additions & 0 deletions tools/dgeni/processors/categorizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ module.exports = function categorizer() {

decoratePublicDoc(classDoc);

// Sort members
classDoc.methods.sort(sortMembers);
classDoc.properties.sort(sortMembers);

// Categorize the current visited classDoc into its Angular type.
if (isDirective(classDoc)) {
classDoc.isDirective = true;
Expand Down Expand Up @@ -95,6 +99,40 @@ function filterDuplicateMembers(item, _index, array) {
return array.filter((memberDoc, i) => memberDoc.name === item.name)[0] === item;
}

/** Sorts members by deprecated status, member decorator, and name. */
function sortMembers(docA, docB) {
// Sort deprecated docs to the end
if (!docA.isDeprecated && docB.isDeprecated) {
return -1;
}

if (docA.isDeprecated && !docB.isDeprecated) {
return 1;
}

// Sort in the order of: Inputs, Outputs, neither
if ((isDirectiveInput(docA) && !isDirectiveInput(docB)) ||
(isDirectiveOutput(docA) && !isDirectiveInput(docB) && !isDirectiveOutput(docB))) {
return -1;
}

if ((isDirectiveInput(docB) && !isDirectiveInput(docA)) ||
(isDirectiveOutput(docB) && !isDirectiveInput(docA) && !isDirectiveOutput(docA))) {
return 1;
}

// Break ties by sorting alphabetically on the name
if (docA.name < docB.name) {
return -1;
}

if (docA.name > docB.name) {
return 1;
}

return 0;
}

/**
* The `parameters` property are the parameters extracted from TypeScript and are strings
* of the form "propertyName: propertyType" (literally what's written in the source).
Expand Down