build(docs-infra): separate NgModules from Classes in API docs (#25734)

PR Close #25734
This commit is contained in:
Pete Bacon Darwin 2018-08-29 17:23:08 +01:00 committed by Kara Erickson
parent 34b848ad51
commit bc5cb8153e
8 changed files with 132 additions and 29 deletions

View File

@ -49,6 +49,7 @@ export class ApiListComponent implements OnInit {
{ value: 'function', title: 'Function' },
{ value: 'interface', title: 'Interface' },
{ value: 'pipe', title: 'Pipe'},
{ value: 'ngmodule', title: 'NgModule'},
{ value: 'type-alias', title: 'Type alias' },
{ value: 'package', title: 'Package'}
];

View File

@ -61,6 +61,14 @@ $api-symbols: (
content: ' ',
background: $white
),
class: (
content: 'C',
background: $blue-500
),
const: (
content: 'K',
background: $mediumgray
),
decorator: (
content: '@',
background: $blue-800
@ -69,46 +77,42 @@ $api-symbols: (
content: 'D',
background: $pink-600
),
pipe: (
content: 'P',
background: $blue-grey-600
),
class: (
content: 'C',
background: $blue-500
),
interface: (
content: 'I',
background: $teal-500
enum: (
content: 'E',
background: $amber-700
),
function: (
content: 'F',
background: $green-500
),
enum: (
content: 'E',
background: $amber-700
),
const: (
content: 'K',
background: $mediumgray
interface: (
content: 'I',
background: $teal-500
),
let: (
content: 'K',
background: $mediumgray
),
var: (
content: 'K',
background: $mediumgray
ngmodule: (
content: 'M',
background: $darkred
),
package: (
content: 'Pk',
background: $purple-600
),
pipe: (
content: 'P',
background: $blue-grey-600
),
type-alias: (
content: 'T',
background: $light-green-600
),
package: (
content: 'Pk',
background: $purple-600
)
var: (
content: 'K',
background: $mediumgray
),
);
// OTHER

View File

@ -34,6 +34,8 @@ module.exports = new Package('angular-api', [basePackage, typeScriptPackage])
.processor(require('./processors/computeStability'))
.processor(require('./processors/removeInjectableConstructors'))
.processor(require('./processors/processPackages'))
.processor(require('./processors/processNgModuleDocs'))
/**
* These are the API doc types that will be rendered to actual files.
@ -41,7 +43,7 @@ module.exports = new Package('angular-api', [basePackage, typeScriptPackage])
* more Angular specific API types, such as decorators and directives.
*/
.factory(function API_DOC_TYPES_TO_RENDER(EXPORT_DOC_TYPES) {
return EXPORT_DOC_TYPES.concat(['decorator', 'directive', 'pipe', 'package']);
return EXPORT_DOC_TYPES.concat(['decorator', 'directive', 'ngmodule', 'pipe', 'package']);
})
/**
@ -198,7 +200,7 @@ module.exports = new Package('angular-api', [basePackage, typeScriptPackage])
outputPathTemplate: '${moduleFolder}.json'
});
computePathsProcessor.pathTemplates.push({
docTypes: EXPORT_DOC_TYPES.concat(['decorator', 'directive', 'pipe']),
docTypes: EXPORT_DOC_TYPES.concat(['decorator', 'directive', 'ngmodule', 'pipe']),
pathTemplate: '${moduleDoc.moduleFolder}/${name}',
outputPathTemplate: '${moduleDoc.moduleFolder}/${name}.json',
});

View File

@ -8,7 +8,7 @@ module.exports = function extractDecoratedClassesProcessor(EXPORT_DOC_TYPES) {
return {
$runAfter: ['processing-docs'],
$runBefore: ['docs-processed'],
decoratorTypes: ['Directive', 'Component', 'Pipe'],
decoratorTypes: ['Directive', 'Component', 'Pipe', 'NgModule'],
$process: function(docs) {
var decoratorTypes = this.decoratorTypes;

View File

@ -0,0 +1,18 @@
module.exports = function processNgModuleDocs() {
return {
$runAfter: ['extractDecoratedClassesProcessor'],
$runBefore: ['docs-processed'],
$process(docs) {
docs.forEach(doc => {
if (doc.docType === 'ngmodule') {
Object.keys(doc.ngmoduleOptions).forEach(key => {
const value = doc.ngmoduleOptions[key];
if (value && !Array.isArray(value)) {
doc.ngmoduleOptions[key] = [value];
}
});
}
});
}
};
};

View File

@ -0,0 +1,24 @@
const testPackage = require('../../helpers/test-package');
const Dgeni = require('dgeni');
describe('processNgModuleDocs processor', () => {
let processor;
beforeEach(() => {
const dgeni = new Dgeni([testPackage('angular-api-package')]);
const injector = dgeni.configureInjector();
processor = injector.get('processNgModuleDocs');
});
it('should be available on the injector', () => {
expect(processor.$process).toBeDefined();
});
it('should run before the correct processor', () => {
expect(processor.$runBefore).toEqual(['docs-processed']);
});
it('should run after the correct processor', () => {
expect(processor.$runAfter).toEqual(['extractDecoratedClassesProcessor']);
});
});

View File

@ -2,7 +2,7 @@
<section class="{$ doc.docType $}-overview">
<code-example language="ts" hideCopy="true" linenums="false">
{% if doc.isAbstract %}abstract {% endif%}{$ doc.docType $} {$ doc.name $}{$ doc.typeParams | escape $}{$ memberHelper.renderHeritage(doc) $} {{$ memberHelper.renderMembers(doc) $}
{% if doc.isAbstract %}abstract {% endif%}class {$ doc.name $}{$ doc.typeParams | escape $}{$ memberHelper.renderHeritage(doc) $} {{$ memberHelper.renderMembers(doc) $}
}
</code-example>
{$ descendants.renderDescendants(doc, 'class', 'Subclasses') $}

View File

@ -0,0 +1,54 @@
{% import "lib/memberHelpers.html" as memberHelpers -%}
{% import "lib/descendants.html" as descendants -%}
{% import "lib/paramList.html" as params -%}
{% extends 'export-base.template.html' -%}
{% macro renderTable(items, containerClass, headingText, tableHeading) %}
<section class="{$ containerClass $}">
<h2>{$ headingText $}</h2>
<table class="is-full-width list-table property-table">
<thead>
<tr>
<th>{$ tableHeading $}</th>
</tr>
</thead>
<tbody>
{% for item in items %}
<tr>
<td>
<code-example language="ts" hideCopy="true" linenums="false" class="no-box">
{$ item | escape $}
</code-example>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</section>
{% endmacro %}
{% block overview %}
{% include "includes/class-overview.html" %}
{% endblock %}
{% block details %}
{% block additional %}{% endblock %}
{% include "includes/description.html" %}
{$ memberHelpers.renderProperties(doc.staticProperties, 'static-properties', 'static-property', 'Static properties') $}
{$ memberHelpers.renderMethodDetails(versionInfo, doc.staticMethods, 'static-methods', 'static-method', 'Static methods') $}
{% if doc.constructorDoc %}
<h2>Constructor</h2>
{$ memberHelpers.renderMethodDetail(versionInfo, doc.constructorDoc, 'constructor') $}{% endif %}
{$ memberHelpers.renderProperties(doc.properties, 'instance-properties', 'instance-property', 'Properties') $}
{$ memberHelpers.renderMethodDetails(versionInfo, doc.methods, 'instance-methods', 'instance-method', 'Methods') $}
{% if doc.ngmoduleOptions.providers %}
{$ renderTable(doc.ngmoduleOptions.providers, 'providers', 'Providers', 'Provider') $}
{% endif %}
{% if doc.ngmoduleOptions.exports %}
{$ renderTable(doc.ngmoduleOptions.exports, 'exports', 'Exports', 'Export') $}
{% endif %}
{% endblock %}