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: 'function', title: 'Function' },
{ value: 'interface', title: 'Interface' }, { value: 'interface', title: 'Interface' },
{ value: 'pipe', title: 'Pipe'}, { value: 'pipe', title: 'Pipe'},
{ value: 'ngmodule', title: 'NgModule'},
{ value: 'type-alias', title: 'Type alias' }, { value: 'type-alias', title: 'Type alias' },
{ value: 'package', title: 'Package'} { value: 'package', title: 'Package'}
]; ];

View File

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

View File

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

View File

@ -8,7 +8,7 @@ module.exports = function extractDecoratedClassesProcessor(EXPORT_DOC_TYPES) {
return { return {
$runAfter: ['processing-docs'], $runAfter: ['processing-docs'],
$runBefore: ['docs-processed'], $runBefore: ['docs-processed'],
decoratorTypes: ['Directive', 'Component', 'Pipe'], decoratorTypes: ['Directive', 'Component', 'Pipe', 'NgModule'],
$process: function(docs) { $process: function(docs) {
var decoratorTypes = this.decoratorTypes; 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"> <section class="{$ doc.docType $}-overview">
<code-example language="ts" hideCopy="true" linenums="false"> <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> </code-example>
{$ descendants.renderDescendants(doc, 'class', 'Subclasses') $} {$ 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 %}