Skip to content

Commit 6b2f008

Browse files
devversionjelbourn
authored andcommitted
docs: component-grouper does not always include components (#13079)
* Currently we group the Dgeni docs by entry-points (we just call it *grouping by components*). Technically there are "component groups" that do not even include any component/directive (e.g. `cdk/coercion`, `cdk/platform`). This renames the component grouper to `entry point grouper`. * No longer displays interfaces, classes, type-aliases etc. as `additional` "parts of an entry-point". (As mentioned above; sometimes classes are the primary export of an entry-point).
1 parent 664ef4c commit 6b2f008

File tree

3 files changed

+71
-71
lines changed

3 files changed

+71
-71
lines changed

tools/dgeni/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {DocsPrivateFilter} from './processors/docs-private-filter';
55
import {Categorizer} from './processors/categorizer';
66
import {FilterDuplicateExports} from './processors/filter-duplicate-exports';
77
import {MergeInheritedProperties} from './processors/merge-inherited-properties';
8-
import {ComponentGrouper} from './processors/component-grouper';
8+
import {EntryPointGrouper} from './processors/entry-point-grouper';
99
import {ReadTypeScriptModules} from 'dgeni-packages/typescript/processors/readTypeScriptModules';
1010
import {TsParser} from 'dgeni-packages/typescript/services/TsParser';
1111
import {sync as globSync} from 'glob';
@@ -62,8 +62,8 @@ apiDocsPackage.processor(new DocsPrivateFilter());
6262
// Processor that appends categorization flags to the docs, e.g. `isDirective`, `isNgModule`, etc.
6363
apiDocsPackage.processor(new Categorizer());
6464

65-
// Processor to group components into top-level groups such as "Tabs", "Sidenav", etc.
66-
apiDocsPackage.processor(new ComponentGrouper());
65+
// Processor to group docs into top-level entry-points such as "tabs", "sidenav", etc.
66+
apiDocsPackage.processor(new EntryPointGrouper());
6767

6868
// Configure the log level of the API docs dgeni package.
6969
apiDocsPackage.config((log: any) => log.level = 'info');
@@ -82,7 +82,7 @@ apiDocsPackage.config((log: any) => patchLogService(log));
8282
// Configure the output path for written files (i.e., file names).
8383
apiDocsPackage.config((computePathsProcessor: any) => {
8484
computePathsProcessor.pathTemplates = [{
85-
docTypes: ['componentGroup'],
85+
docTypes: ['entry-point'],
8686
pathTemplate: '${name}',
8787
outputPathTemplate: '${name}.html',
8888
}];

tools/dgeni/processors/component-grouper.ts renamed to tools/dgeni/processors/entry-point-grouper.ts

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
import {DocCollection, Document, Processor} from 'dgeni';
2+
import {FunctionExportDoc} from 'dgeni-packages/typescript/api-doc-types/FunctionExportDoc';
23
import {InterfaceExportDoc} from 'dgeni-packages/typescript/api-doc-types/InterfaceExportDoc';
34
import {TypeAliasExportDoc} from 'dgeni-packages/typescript/api-doc-types/TypeAliasExportDoc';
4-
import {FunctionExportDoc} from 'dgeni-packages/typescript/api-doc-types/FunctionExportDoc';
5-
import {CategorizedClassDoc} from '../common/dgeni-definitions';
65
import * as path from 'path';
6+
import {CategorizedClassDoc} from '../common/dgeni-definitions';
77

8-
/** Component group data structure. */
9-
export class ComponentGroup {
8+
/** Document type for an entry-point. */
9+
export class EntryPointDoc {
1010

1111
/** Unique document type for Dgeni. */
12-
docType = 'componentGroup';
12+
docType = 'entry-point';
1313

1414
/** Name of the component group. */
1515
name: string;
1616

17-
/** Display name of the component group */
17+
/** Display name of the entry-point. */
1818
displayName: string;
1919

20-
/** Module import path for the component group. */
20+
/** Module import path for the entry-point. */
2121
moduleImportPath: string;
2222

2323
/** Name of the package, either material or cdk */
@@ -26,10 +26,10 @@ export class ComponentGroup {
2626
/** Display name of the package. */
2727
packageDisplayName: string;
2828

29-
/** Unique id for the component group. */
29+
/** Unique id for the entry-point. */
3030
id: string;
3131

32-
/** Known aliases for the component group. */
32+
/** Known aliases for the entry-point. This is only needed for the `computeIdsProcessor`. */
3333
aliases: string[] = [];
3434

3535
/** List of categorized class docs that are defining a directive. */
@@ -38,38 +38,37 @@ export class ComponentGroup {
3838
/** List of categorized class docs that are defining a service. */
3939
services: CategorizedClassDoc[] = [];
4040

41-
/** Additional classes that belong to the component group. */
42-
additionalClasses: CategorizedClassDoc[] = [];
41+
/** Classes that belong to the entry-point. */
42+
classes: CategorizedClassDoc[] = [];
4343

44-
/** Additional interfaces that belong to the component group. */
45-
additionalInterfaces: InterfaceExportDoc[] = [];
44+
/** Interfaces that belong to the entry-point. */
45+
interfaces: InterfaceExportDoc[] = [];
4646

47-
/** Additional type aliases that belong to the component group. */
48-
additionalTypeAliases: TypeAliasExportDoc[] = [];
47+
/** Type aliases that belong to the entry-point. */
48+
typeAliases: TypeAliasExportDoc[] = [];
4949

50-
/** Additional functions that belong to the component group. */
51-
additionalFunctions: FunctionExportDoc[] = [];
50+
/** Functions that belong to the entry-point. */
51+
functions: FunctionExportDoc[] = [];
5252

53-
/** NgModule that defines the current component group. */
53+
/** NgModule that defines the current entry-point. */
5454
ngModule: CategorizedClassDoc | null = null;
5555

5656
constructor(name: string) {
5757
this.name = name;
58-
this.id = `component-group-${name}`;
58+
this.id = `entry-point-${name}`;
5959
}
6060
}
6161

6262
/**
63-
* Processor to group docs into top-level "Components" WRT material design, e.g., "Button", "Tabs",
64-
* where each group may conists of several directives and services.
63+
* Processor to group docs into entry-points that consist of directives, component, classes,
64+
* interfaces, functions or type aliases.
6565
*/
66-
export class ComponentGrouper implements Processor {
67-
name = 'component-grouper';
66+
export class EntryPointGrouper implements Processor {
67+
name = 'entry-point-grouper';
6868
$runBefore = ['docs-processed'];
6969

7070
$process(docs: DocCollection) {
71-
// Map of group name to group instance.
72-
const groups = new Map<string, ComponentGroup>();
71+
const entryPoints = new Map<string, EntryPointDoc>();
7372

7473
docs.forEach(doc => {
7574
const documentInfo = getDocumentPackageInfo(doc);
@@ -78,41 +77,41 @@ export class ComponentGrouper implements Processor {
7877
const packageDisplayName = documentInfo.packageName === 'cdk' ? 'CDK' : 'Material';
7978

8079
const moduleImportPath = `@angular/${packageName}/${documentInfo.entryPointName}`;
81-
const groupName = packageName + '-' + documentInfo.name;
80+
const entryPointName = packageName + '-' + documentInfo.name;
8281

83-
// Get the group for this doc, or, if one does not exist, create it.
84-
let group;
85-
if (groups.has(groupName)) {
86-
group = groups.get(groupName)!;
82+
// Get the entry-point for this doc, or, if one does not exist, create it.
83+
let entryPoint;
84+
if (entryPoints.has(entryPointName)) {
85+
entryPoint = entryPoints.get(entryPointName)!;
8786
} else {
88-
group = new ComponentGroup(groupName);
89-
groups.set(groupName, group);
87+
entryPoint = new EntryPointDoc(entryPointName);
88+
entryPoints.set(entryPointName, entryPoint);
9089
}
9190

92-
group.displayName = documentInfo.name;
93-
group.moduleImportPath = moduleImportPath;
94-
group.packageName = packageName;
95-
group.packageDisplayName = packageDisplayName;
91+
entryPoint.displayName = documentInfo.name;
92+
entryPoint.moduleImportPath = moduleImportPath;
93+
entryPoint.packageName = packageName;
94+
entryPoint.packageDisplayName = packageDisplayName;
9695

97-
// Put this doc into the appropriate list in this group.
96+
// Put this doc into the appropriate list in the entry-point doc.
9897
if (doc.isDirective) {
99-
group.directives.push(doc);
98+
entryPoint.directives.push(doc);
10099
} else if (doc.isService) {
101-
group.services.push(doc);
100+
entryPoint.services.push(doc);
102101
} else if (doc.isNgModule) {
103-
group.ngModule = doc;
102+
entryPoint.ngModule = doc;
104103
} else if (doc.docType === 'class') {
105-
group.additionalClasses.push(doc);
104+
entryPoint.classes.push(doc);
106105
} else if (doc.docType === 'interface') {
107-
group.additionalInterfaces.push(doc);
106+
entryPoint.interfaces.push(doc);
108107
} else if (doc.docType === 'type-alias') {
109-
group.additionalTypeAliases.push(doc);
108+
entryPoint.typeAliases.push(doc);
110109
} else if (doc.docType === 'function') {
111-
group.additionalFunctions.push(doc);
110+
entryPoint.functions.push(doc);
112111
}
113112
});
114113

115-
return Array.from(groups.values());
114+
return Array.from(entryPoints.values());
116115
}
117116
}
118117

@@ -127,8 +126,9 @@ function getDocumentPackageInfo(doc: Document) {
127126
const pathSegments = path.relative(basePath, filePath).split(path.sep);
128127
let groupName = pathSegments[1];
129128

130-
// For the ripples there should be a component group in the docs. Even it's not a
131-
// secondary-entry point it can be still documented with its own `material-ripple.html` file.
129+
// The ripples are technically part of the `@angular/material/core` entry-point, but we
130+
// want to show the ripple API separately in the docs. In order to archive this, we treat
131+
// the ripple folder as its own entry-point.
132132
if (pathSegments[1] === 'core' && pathSegments[2] === 'ripple') {
133133
groupName = 'ripple';
134134
}

tools/dgeni/templates/componentGroup.template.html renamed to tools/dgeni/templates/entry-point.template.html

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -59,32 +59,32 @@ <h3 id="directives" class="docs-header-link docs-api-h3">
5959
{% endfor %}
6060
{%- endif -%}
6161

62-
{%- if doc.additionalClasses.length -%}
63-
<h3 id="additional_classes" class="docs-header-link docs-api-h3">
64-
<span header-link="additional_classes"></span>
65-
Additional classes
62+
{%- if doc.classes.length -%}
63+
<h3 id="classes" class="docs-header-link docs-api-h3">
64+
<span header-link="classes"></span>
65+
Classes
6666
</h3>
67-
{% for other in doc.additionalClasses %}
67+
{% for other in doc.classes %}
6868
{$ class(other) $}
6969
{% endfor %}
7070
{%- endif -%}
7171

72-
{%- if doc.additionalInterfaces.length -%}
73-
<h3 id="additional_interfaces" class="docs-header-link docs-api-h3">
74-
<span header-link="additional_interfaces"></span>
75-
Additional interfaces
72+
{%- if doc.interfaces.length -%}
73+
<h3 id="interfaces" class="docs-header-link docs-api-h3">
74+
<span header-link="interfaces"></span>
75+
Interfaces
7676
</h3>
77-
{% for item in doc.additionalInterfaces %}
77+
{% for item in doc.interfaces %}
7878
{$ interface(item) $}
7979
{% endfor %}
8080
{%- endif -%}
8181

82-
{%- if doc.additionalFunctions.length -%}
83-
<h3 id="additional_functions" class="docs-header-link docs-api-h3">
84-
<span header-link="additional_functions"></span>
85-
Additional functions
82+
{%- if doc.functions.length -%}
83+
<h3 id="functions" class="docs-header-link docs-api-h3">
84+
<span header-link="functions"></span>
85+
Functions
8686
</h3>
87-
{% for item in doc.additionalFunctions %}
87+
{% for item in doc.functions %}
8888
{#
8989
Since the function docs have a similar structure as method docs, we use
9090
the method template.
@@ -93,12 +93,12 @@ <h3 id="additional_functions" class="docs-header-link docs-api-h3">
9393
{% endfor %}
9494
{%- endif -%}
9595

96-
{%- if doc.additionalTypeAliases.length -%}
97-
<h3 id="additional_type_aliases" class="docs-header-link docs-api-h3">
98-
<span header-link="additional_type_aliases"></span>
99-
Additional type aliases
96+
{%- if doc.typeAliases.length -%}
97+
<h3 id="type_aliases" class="docs-header-link docs-api-h3">
98+
<span header-link="type_aliases"></span>
99+
Type aliases
100100
</h3>
101-
{% for item in doc.additionalTypeAliases %}
101+
{% for item in doc.typeAliases %}
102102
{$ typeAlias(item) $}
103103
{% endfor %}
104104
{%- endif -%}

0 commit comments

Comments
 (0)