docs: sort class properties and methods (#6893)

* docs: sort class properties and methods

- Properties are sorted in the order of [Inputs, Outputs, neither]. Secondary sorting done alphabetically.
- Methods are sorted alphabetically.
- All deprecated members are sorted to the end.

* Use the same sort for methods and properties
This commit is contained in:
Will Howell
2017-09-08 17:28:26 -04:00
committed by tinayuangao
parent ab20ffd996
commit 9f2fd477f2
+38
View File
@@ -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;
@@ -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).