Skip to content

Commit 4879dc4

Browse files
devversionjelbourn
authored andcommitted
docs: show exported functions (#12736)
Changes the Dgeni setup to properly display exported functions (e.g. from cdk/coercion, cdk/a11y, cdk/platform)
1 parent 35fb68b commit 4879dc4

File tree

11 files changed

+87
-32
lines changed

11 files changed

+87
-32
lines changed

src/cdk/collections/selection.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ export interface SelectionChange<T> {
202202
/**
203203
* Returns an error that reports that multiple values are passed into a selection model
204204
* with a single value.
205+
* @docs-private
205206
*/
206207
export function getMultipleValuesInSingleSelectionError() {
207208
return Error('Cannot pass multiple values into SelectionModel with single-value mode.');

src/cdk/table/can-stick.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export interface CanStick {
3535
* Mixin to provide a directive with a function that checks if the sticky input has been
3636
* changed since the last time the function was called. Essentially adds a dirty-check to the
3737
* sticky value.
38+
* @docs-private
3839
*/
3940
export function mixinHasStickyInput<T extends Constructor<{}>>(base: T):
4041
Constructor<CanStick> & T {

src/lib/autocomplete/autocomplete-trigger.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ export const MAT_AUTOCOMPLETE_VALUE_ACCESSOR: any = {
8787

8888
/**
8989
* Creates an error to be thrown when attempting to use an autocomplete trigger without a panel.
90+
* @docs-private
9091
*/
9192
export function getMatAutocompleteMissingPanelError(): Error {
9293
return Error('Attempting to open an undefined instance of `mat-autocomplete`. ' +

src/lib/sidenav/drawer.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ import {matDrawerAnimations} from './drawer-animations';
4242
import {ANIMATION_MODULE_TYPE} from '@angular/platform-browser/animations';
4343

4444

45-
/** Throws an exception when two MatDrawer are matching the same position. */
45+
/**
46+
* Throws an exception when two MatDrawer are matching the same position.
47+
* @docs-private
48+
*/
4649
export function throwMatDuplicatedDrawerError(position: string) {
4750
throw Error(`A drawer was already declared for 'position="${position}"'`);
4851
}

src/lib/tooltip/tooltip.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,10 @@ export const SCROLL_THROTTLE_MS = 20;
5252
/** CSS class that will be attached to the overlay panel. */
5353
export const TOOLTIP_PANEL_CLASS = 'mat-tooltip-panel';
5454

55-
/** Creates an error to be thrown if the user supplied an invalid tooltip position. */
55+
/**
56+
* Creates an error to be thrown if the user supplied an invalid tooltip position.
57+
* @docs-private
58+
*/
5659
export function getMatTooltipInvalidPositionError(position: string) {
5760
return Error(`Tooltip position "${position}" is invalid.`);
5861
}
@@ -87,6 +90,7 @@ export const MAT_TOOLTIP_DEFAULT_OPTIONS =
8790
factory: MAT_TOOLTIP_DEFAULT_OPTIONS_FACTORY
8891
});
8992

93+
/** @docs-private */
9094
export function MAT_TOOLTIP_DEFAULT_OPTIONS_FACTORY(): MatTooltipDefaultOptions {
9195
return {
9296
showDelay: 0,

tools/dgeni/common/dgeni-definitions.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ import {ClassExportDoc} from 'dgeni-packages/typescript/api-doc-types/ClassExpor
33
import {ClassLikeExportDoc} from 'dgeni-packages/typescript/api-doc-types/ClassLikeExportDoc';
44
import {PropertyMemberDoc} from 'dgeni-packages/typescript/api-doc-types/PropertyMemberDoc';
55
import {ParsedDecorator} from 'dgeni-packages/typescript/services/TsParser/getDecorators';
6-
import {NormalizedMethodMemberDoc} from './normalize-method-parameters';
6+
import {FunctionExportDoc} from 'dgeni-packages/typescript/api-doc-types/FunctionExportDoc';
7+
import {MethodMemberDoc} from 'dgeni-packages/typescript/api-doc-types/MethodMemberDoc';
8+
import {NormalizedFunctionDoc} from './normalize-function-parameters';
79

810
/** Interface that describes categorized docs that can be deprecated. */
911
export interface DeprecationDoc extends ApiDoc {
@@ -43,6 +45,9 @@ export interface CategorizedPropertyMemberDoc extends PropertyMemberDoc, Depreca
4345
}
4446

4547
/** Extended Dgeni method-member document that simplifies logic for the Dgeni template. */
46-
export interface CategorizedMethodMemberDoc extends NormalizedMethodMemberDoc, DeprecationDoc {
47-
showReturns: boolean;
48-
}
48+
export interface CategorizedMethodMemberDoc
49+
extends NormalizedFunctionDoc, MethodMemberDoc, DeprecationDoc {}
50+
51+
/** Extended Dgeni function export document that simplifies logic for the Dgeni template. */
52+
export interface CategorizedFunctionExportDoc
53+
extends NormalizedFunctionDoc, FunctionExportDoc, DeprecationDoc {}

tools/dgeni/common/normalize-method-parameters.ts renamed to tools/dgeni/common/normalize-function-parameters.ts

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
import {MethodMemberDoc} from 'dgeni-packages/typescript/api-doc-types/MethodMemberDoc';
2-
3-
export class NormalizedMethodMemberDoc extends MethodMemberDoc {
4-
params?: MethodParameterInfo[];
1+
import {
2+
ParameterContainer,
3+
ParamTag,
4+
} from 'dgeni-packages/typescript/api-doc-types/ParameterContainer';
5+
import {ApiDoc} from 'dgeni-packages/typescript/api-doc-types/ApiDoc';
6+
7+
export interface NormalizedFunctionDoc extends ParameterContainer, ApiDoc {
8+
params?: FunctionParameterInfo[];
59
}
610

7-
export interface MethodParameterInfo {
8-
name: string;
11+
export interface FunctionParameterInfo extends ParamTag {
912
type: string;
1013
isOptional: boolean;
1114
}
@@ -20,9 +23,9 @@ export interface MethodParameterInfo {
2023
* We will use the `params` property to store the final normalized form since it is already
2124
* an object.
2225
*/
23-
export function normalizeMethodParameters(method: NormalizedMethodMemberDoc) {
24-
if (method.parameters) {
25-
method.parameters.forEach(parameter => {
26+
export function normalizeFunctionParameters(doc: NormalizedFunctionDoc) {
27+
if (doc.parameters) {
28+
doc.parameters.forEach(parameter => {
2629
let [parameterName, parameterType] = parameter.split(':');
2730

2831
// If the parameter is optional, the name here will contain a '?'. We store whether the
@@ -33,23 +36,22 @@ export function normalizeMethodParameters(method: NormalizedMethodMemberDoc) {
3336
parameterName = parameterName.replace('?', '');
3437
}
3538

36-
if (!method.params) {
37-
method.params = [];
38-
}
39+
doc.params = doc.params || [];
3940

4041
if (!parameterType) {
4142
console.warn(`Missing parameter type information (${parameterName}) in ` +
42-
`${method.fileInfo.relativePath}:${method.startingLine}`);
43+
`${doc.fileInfo.relativePath}:${doc.startingLine}`);
4344
return;
4445
}
4546

46-
const existingParameterInfo = method.params.find(p => p.name == parameterName);
47+
const existingParameterInfo = doc.params.find(p => p.name == parameterName);
4748

4849
if (!existingParameterInfo) {
49-
method.params.push({
50+
doc.params.push({
5051
name: parameterName,
5152
type: parameterType.trim(),
52-
isOptional: isOptional
53+
isOptional: isOptional,
54+
description: ''
5355
});
5456
} else {
5557
existingParameterInfo.type = parameterType.trim();

tools/dgeni/processors/categorizer.ts

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
11
import {DocCollection, Processor} from 'dgeni';
22
import {MethodMemberDoc} from 'dgeni-packages/typescript/api-doc-types/MethodMemberDoc';
3-
import {getDirectiveMetadata} from '../common/directive-metadata';
43
import {
5-
decorateDeprecatedDoc, getDirectiveSelectors, isDirective, isMethod, isNgModule, isProperty,
6-
isService
4+
decorateDeprecatedDoc,
5+
getDirectiveSelectors,
6+
isDirective,
7+
isMethod,
8+
isNgModule,
9+
isProperty,
10+
isService,
711
} from '../common/decorators';
812
import {
9-
CategorizedClassDoc, CategorizedClassLikeDoc, CategorizedMethodMemberDoc,
10-
CategorizedPropertyMemberDoc
13+
CategorizedClassDoc,
14+
CategorizedClassLikeDoc,
15+
CategorizedFunctionExportDoc,
16+
CategorizedMethodMemberDoc,
17+
CategorizedPropertyMemberDoc,
1118
} from '../common/dgeni-definitions';
12-
import {normalizeMethodParameters} from '../common/normalize-method-parameters';
19+
import {getDirectiveMetadata} from '../common/directive-metadata';
20+
import {normalizeFunctionParameters} from '../common/normalize-function-parameters';
1321
import {getInputBindingData, getOutputBindingData} from '../common/property-bindings';
1422
import {sortCategorizedMembers} from '../common/sort-members';
1523

@@ -30,6 +38,10 @@ export class Categorizer implements Processor {
3038
docs
3139
.filter(doc => doc.docType === 'class' || doc.docType === 'interface')
3240
.forEach(doc => this.decorateClassLikeDoc(doc));
41+
42+
docs
43+
.filter(doc => doc.docType === 'function')
44+
.forEach(doc => this.decorateFunctionExportDoc(doc));
3345
}
3446

3547
/**
@@ -92,11 +104,17 @@ export class Categorizer implements Processor {
92104
* will be normalized, so that they can be easily used inside of dgeni templates.
93105
*/
94106
private decorateMethodDoc(methodDoc: CategorizedMethodMemberDoc) {
95-
normalizeMethodParameters(methodDoc);
107+
normalizeFunctionParameters(methodDoc);
96108
decorateDeprecatedDoc(methodDoc);
109+
}
97110

98-
// Mark methods with a `void` return type so we can omit show the return type in the docs.
99-
methodDoc.showReturns = methodDoc.type ? methodDoc.type !== 'void' : false;
111+
/**
112+
* Method that will be called for each function export doc. The parameters for the functions
113+
* will be normalized, so that they can be easily used inside of Dgeni templates.
114+
*/
115+
private decorateFunctionExportDoc(functionDoc: CategorizedFunctionExportDoc) {
116+
normalizeFunctionParameters(functionDoc);
117+
decorateDeprecatedDoc(functionDoc);
100118
}
101119

102120
/**

tools/dgeni/processors/component-grouper.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {DocCollection, Document, Processor} from 'dgeni';
22
import {InterfaceExportDoc} from 'dgeni-packages/typescript/api-doc-types/InterfaceExportDoc';
33
import {TypeAliasExportDoc} from 'dgeni-packages/typescript/api-doc-types/TypeAliasExportDoc';
4+
import {FunctionExportDoc} from 'dgeni-packages/typescript/api-doc-types/FunctionExportDoc';
45
import {CategorizedClassDoc} from '../common/dgeni-definitions';
56
import * as path from 'path';
67

@@ -46,6 +47,9 @@ export class ComponentGroup {
4647
/** Additional type aliases that belong to the component group. */
4748
additionalTypeAliases: TypeAliasExportDoc[] = [];
4849

50+
/** Additional functions that belong to the component group. */
51+
additionalFunctions: FunctionExportDoc[] = [];
52+
4953
/** NgModule that defines the current component group. */
5054
ngModule: CategorizedClassDoc | null = null;
5155

@@ -103,6 +107,8 @@ export class ComponentGrouper implements Processor {
103107
group.additionalInterfaces.push(doc);
104108
} else if (doc.docType === 'type-alias') {
105109
group.additionalTypeAliases.push(doc);
110+
} else if (doc.docType === 'function') {
111+
group.additionalFunctions.push(doc);
106112
}
107113
});
108114

tools/dgeni/templates/componentGroup.template.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,20 @@ <h3 id="additional_interfaces" class="docs-header-link docs-api-h3">
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
86+
</h3>
87+
{% for item in doc.additionalFunctions %}
88+
{#
89+
Since the function docs have a similar structure as method docs, we use
90+
the method template.
91+
#}
92+
{$ method(item) $}
93+
{% endfor %}
94+
{%- endif -%}
95+
8296
{%- if doc.additionalTypeAliases.length -%}
8397
<h3 id="additional_type_aliases" class="docs-header-link docs-api-h3">
8498
<span header-link="additional_type_aliases"></span>

tools/dgeni/templates/method.template.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
{% endfor %}
4848
{%- endif -%}
4949

50-
{%- if method.showReturns -%}
50+
{%- if method.type and method.type !== "void" -%}
5151
<thead>
5252
<tr class="docs-api-method-returns-header-row">
5353
<th colspan="2" class="docs-api-method-returns-header-cell">Returns</th>

0 commit comments

Comments
 (0)