|
9 | 9 | module.exports = function categorizer() {
|
10 | 10 | return {
|
11 | 11 | $runBefore: ['docs-processed'],
|
12 |
| - $process: function(docs) { |
13 |
| - docs.forEach(doc => { |
14 |
| - // The typescriptPackage groups both methods and parameters into "members". |
15 |
| - // Use the presence of `parameters` as a proxy to determine if this is a method. |
16 |
| - if (doc.classDoc && doc.hasOwnProperty('parameters')) { |
17 |
| - doc.isMethod = true; |
18 |
| - |
19 |
| - // Mark methods with a `void` return type so we can omit show the return type in the docs. |
20 |
| - doc.showReturns = doc.returnType && doc.returnType != 'void'; |
21 |
| - |
22 |
| - normalizeMethodParameters(doc); |
23 |
| - |
24 |
| - // Maintain a list of methods on the associated class so we can |
25 |
| - // iterate through them while rendering. |
26 |
| - doc.classDoc.methods ? |
27 |
| - doc.classDoc.methods.push(doc) : |
28 |
| - doc.classDoc.methods = [doc]; |
29 |
| - } else if (isDirective(doc)) { |
30 |
| - doc.isDirective = true; |
31 |
| - doc.directiveExportAs = getDirectiveExportAs(doc); |
32 |
| - } else if (isService(doc)) { |
33 |
| - doc.isService = true; |
34 |
| - } else if (isNgModule(doc)) { |
35 |
| - doc.isNgModule = true; |
36 |
| - } else if (doc.docType == 'member') { |
37 |
| - doc.isDirectiveInput = isDirectiveInput(doc); |
38 |
| - doc.directiveInputAlias = getDirectiveInputAlias(doc); |
39 |
| - |
40 |
| - doc.isDirectiveOutput = isDirectiveOutput(doc); |
41 |
| - doc.directiveOutputAlias = getDirectiveOutputAlias(doc); |
42 |
| - |
43 |
| - doc.classDoc.properties ? |
44 |
| - doc.classDoc.properties.push(doc) : |
45 |
| - doc.classDoc.properties = [doc]; |
46 |
| - } |
47 |
| - }); |
| 12 | + $process: function (docs) { |
| 13 | + docs.filter(doc => doc.docType === 'class').forEach(doc => decorateClassDoc(doc)); |
48 | 14 | }
|
49 | 15 | };
|
| 16 | + |
| 17 | + /** |
| 18 | + * Decorates all class docs inside of the dgeni pipeline. |
| 19 | + * - Methods and properties of a class-doc will be extracted into separate variables. |
| 20 | + * - Identifies directives, services or NgModules and marks them them in class-doc. |
| 21 | + **/ |
| 22 | + function decorateClassDoc(classDoc) { |
| 23 | + // Resolve all methods and properties from the classDoc. Includes inherited docs. |
| 24 | + classDoc.methods = resolveMethods(classDoc); |
| 25 | + classDoc.properties = resolveProperties(classDoc); |
| 26 | + |
| 27 | + // Call decorate hooks that can modify the method and property docs. |
| 28 | + classDoc.methods.forEach(doc => decorateMethodDoc(doc)); |
| 29 | + classDoc.properties.forEach(doc => decoratePropertyDoc(doc)); |
| 30 | + |
| 31 | + // Categorize the current visited classDoc into its Angular type. |
| 32 | + if (isDirective(classDoc)) { |
| 33 | + classDoc.isDirective = true; |
| 34 | + classDoc.directiveExportAs = getDirectiveExportAs(classDoc); |
| 35 | + } else if (isService(classDoc)) { |
| 36 | + classDoc.isService = true; |
| 37 | + } else if (isNgModule(classDoc)) { |
| 38 | + classDoc.isNgModule = true; |
| 39 | + } |
| 40 | + } |
| 41 | + |
| 42 | + /** |
| 43 | + * Method that will be called for each method doc. The parameters for the method-docs |
| 44 | + * will be normalized, so that they can be easily used inside of dgeni templates. |
| 45 | + **/ |
| 46 | + function decorateMethodDoc(methodDoc) { |
| 47 | + normalizeMethodParameters(methodDoc); |
| 48 | + |
| 49 | + // Mark methods with a `void` return type so we can omit show the return type in the docs. |
| 50 | + methodDoc.showReturns = methodDoc.returnType && methodDoc.returnType != 'void'; |
| 51 | + } |
| 52 | + |
| 53 | + /** |
| 54 | + * Method that will be called for each property doc. Properties that are Angular inputs or |
| 55 | + * outputs will be marked. Aliases for the inputs or outputs will be stored as well. |
| 56 | + **/ |
| 57 | + function decoratePropertyDoc(propertyDoc) { |
| 58 | + propertyDoc.isDirectiveInput = isDirectiveInput(propertyDoc); |
| 59 | + propertyDoc.directiveInputAlias = getDirectiveInputAlias(propertyDoc); |
| 60 | + |
| 61 | + propertyDoc.isDirectiveOutput = isDirectiveOutput(propertyDoc); |
| 62 | + propertyDoc.directiveOutputAlias = getDirectiveOutputAlias(propertyDoc); |
| 63 | + } |
50 | 64 | };
|
51 | 65 |
|
| 66 | +/** Function that walks through all inherited docs and collects public methods. */ |
| 67 | +function resolveMethods(classDoc) { |
| 68 | + let methods = classDoc.members.filter(member => member.hasOwnProperty('parameters')); |
| 69 | + |
| 70 | + if (classDoc.inheritedDoc) { |
| 71 | + methods = methods.concat(resolveMethods(classDoc.inheritedDoc)); |
| 72 | + } |
| 73 | + |
| 74 | + return methods; |
| 75 | +} |
| 76 | + |
| 77 | +/** Function that walks through all inherited docs and collects public properties. */ |
| 78 | +function resolveProperties(classDoc) { |
| 79 | + let properties = classDoc.members.filter(member => !member.hasOwnProperty('parameters')); |
| 80 | + |
| 81 | + if (classDoc.inheritedDoc) { |
| 82 | + properties = properties.concat(resolveProperties(classDoc.inheritedDoc)); |
| 83 | + } |
| 84 | + |
| 85 | + return properties; |
| 86 | +} |
| 87 | + |
52 | 88 |
|
53 | 89 | /**
|
54 | 90 | * The `parameters` property are the parameters extracted from TypeScript and are strings
|
|
0 commit comments