From a1dbdbe2976204d83578999e4096775252fc9804 Mon Sep 17 00:00:00 2001 From: Will Howell Date: Wed, 6 Sep 2017 18:54:35 -0400 Subject: [PATCH 1/2] 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. --- tools/dgeni/processors/categorizer.js | 65 +++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/tools/dgeni/processors/categorizer.js b/tools/dgeni/processors/categorizer.js index e5139c3020e6..67fbf42265bf 100644 --- a/tools/dgeni/processors/categorizer.js +++ b/tools/dgeni/processors/categorizer.js @@ -43,6 +43,10 @@ module.exports = function categorizer() { decoratePublicDoc(classDoc); + // Sort members + classDoc.methods.sort(sortMethods); + classDoc.properties.sort(sortProperties); + // Categorize the current visited classDoc into its Angular type. if (isDirective(classDoc)) { classDoc.isDirective = true; @@ -95,6 +99,67 @@ function filterDuplicateMembers(item, _index, array) { return array.filter((memberDoc, i) => memberDoc.name === item.name)[0] === item; } +/** Sorts alphabetically by a member's name. */ +function sortByName(docA, docB) { + if (docA.name < docB.name) { + return -1; + } + + if (docA.name > docB.name) { + return 1; + } + + return 0; +} + +/** Sort deprecated members to the end. */ +function sortByDeprecated(docA, docB) { + // Sort deprecated docs to the end + if (!docA.isDeprecated && docB.isDeprecated) { + return -1; + } + + if (docA.isDeprecated && !docB.isDeprecated) { + return 1; + } + + return 0; +} + +/** Sorts methods by deprecated status and name. */ +function sortMethods(docA, docB) { + const deprecatedSort = sortByDeprecated(docA, docB); + if (!!deprecatedSort) { + return deprecatedSort + } + + // Break ties by sorting alphabetically by name + return sortByName(docA, docB); +} + +/** Sorts properties by deprecated status, decorator, and name. */ +function sortProperties(docA, docB) { + // Sort deprecated properties to the end + const deprecatedSort = sortByDeprecated(docA, docB); + if (!!deprecatedSort) { + return deprecatedSort + } + + // 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 + return sortByName(docA, docB); +} + /** * The `parameters` property are the parameters extracted from TypeScript and are strings * of the form "propertyName: propertyType" (literally what's written in the source). From bb1c4891edea224a54466ba2e99dd3e6a058b006 Mon Sep 17 00:00:00 2001 From: Will Howell Date: Thu, 7 Sep 2017 14:10:49 -0400 Subject: [PATCH 2/2] Use the same sort for methods and properties --- tools/dgeni/processors/categorizer.js | 53 +++++++-------------------- 1 file changed, 13 insertions(+), 40 deletions(-) diff --git a/tools/dgeni/processors/categorizer.js b/tools/dgeni/processors/categorizer.js index 67fbf42265bf..d10a92f9d00d 100644 --- a/tools/dgeni/processors/categorizer.js +++ b/tools/dgeni/processors/categorizer.js @@ -44,8 +44,8 @@ module.exports = function categorizer() { decoratePublicDoc(classDoc); // Sort members - classDoc.methods.sort(sortMethods); - classDoc.properties.sort(sortProperties); + classDoc.methods.sort(sortMembers); + classDoc.properties.sort(sortMembers); // Categorize the current visited classDoc into its Angular type. if (isDirective(classDoc)) { @@ -99,21 +99,8 @@ function filterDuplicateMembers(item, _index, array) { return array.filter((memberDoc, i) => memberDoc.name === item.name)[0] === item; } -/** Sorts alphabetically by a member's name. */ -function sortByName(docA, docB) { - if (docA.name < docB.name) { - return -1; - } - - if (docA.name > docB.name) { - return 1; - } - - return 0; -} - -/** Sort deprecated members to the end. */ -function sortByDeprecated(docA, docB) { +/** 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; @@ -123,28 +110,6 @@ function sortByDeprecated(docA, docB) { return 1; } - return 0; -} - -/** Sorts methods by deprecated status and name. */ -function sortMethods(docA, docB) { - const deprecatedSort = sortByDeprecated(docA, docB); - if (!!deprecatedSort) { - return deprecatedSort - } - - // Break ties by sorting alphabetically by name - return sortByName(docA, docB); -} - -/** Sorts properties by deprecated status, decorator, and name. */ -function sortProperties(docA, docB) { - // Sort deprecated properties to the end - const deprecatedSort = sortByDeprecated(docA, docB); - if (!!deprecatedSort) { - return deprecatedSort - } - // Sort in the order of: Inputs, Outputs, neither if ((isDirectiveInput(docA) && !isDirectiveInput(docB)) || (isDirectiveOutput(docA) && !isDirectiveInput(docB) && !isDirectiveOutput(docB))) { @@ -157,7 +122,15 @@ function sortProperties(docA, docB) { } // Break ties by sorting alphabetically on the name - return sortByName(docA, docB); + if (docA.name < docB.name) { + return -1; + } + + if (docA.name > docB.name) { + return 1; + } + + return 0; } /**