docs: show exported functions (#12736)

Changes the Dgeni setup to properly display exported functions (e.g. from cdk/coercion, cdk/a11y, cdk/platform)
This commit is contained in:
Paul Gschwendtner
2018-08-20 22:40:28 +02:00
committed by Jeremy Elbourn
parent 35fb68bfe6
commit 4879dc4720
11 changed files with 86 additions and 31 deletions
+9 -4
View File
@@ -3,7 +3,9 @@ import {ClassExportDoc} from 'dgeni-packages/typescript/api-doc-types/ClassExpor
import {ClassLikeExportDoc} from 'dgeni-packages/typescript/api-doc-types/ClassLikeExportDoc';
import {PropertyMemberDoc} from 'dgeni-packages/typescript/api-doc-types/PropertyMemberDoc';
import {ParsedDecorator} from 'dgeni-packages/typescript/services/TsParser/getDecorators';
import {NormalizedMethodMemberDoc} from './normalize-method-parameters';
import {FunctionExportDoc} from 'dgeni-packages/typescript/api-doc-types/FunctionExportDoc';
import {MethodMemberDoc} from 'dgeni-packages/typescript/api-doc-types/MethodMemberDoc';
import {NormalizedFunctionDoc} from './normalize-function-parameters';
/** Interface that describes categorized docs that can be deprecated. */
export interface DeprecationDoc extends ApiDoc {
@@ -43,6 +45,9 @@ export interface CategorizedPropertyMemberDoc extends PropertyMemberDoc, Depreca
}
/** Extended Dgeni method-member document that simplifies logic for the Dgeni template. */
export interface CategorizedMethodMemberDoc extends NormalizedMethodMemberDoc, DeprecationDoc {
showReturns: boolean;
}
export interface CategorizedMethodMemberDoc
extends NormalizedFunctionDoc, MethodMemberDoc, DeprecationDoc {}
/** Extended Dgeni function export document that simplifies logic for the Dgeni template. */
export interface CategorizedFunctionExportDoc
extends NormalizedFunctionDoc, FunctionExportDoc, DeprecationDoc {}
@@ -1,11 +1,14 @@
import {MethodMemberDoc} from 'dgeni-packages/typescript/api-doc-types/MethodMemberDoc';
import {
ParameterContainer,
ParamTag,
} from 'dgeni-packages/typescript/api-doc-types/ParameterContainer';
import {ApiDoc} from 'dgeni-packages/typescript/api-doc-types/ApiDoc';
export class NormalizedMethodMemberDoc extends MethodMemberDoc {
params?: MethodParameterInfo[];
export interface NormalizedFunctionDoc extends ParameterContainer, ApiDoc {
params?: FunctionParameterInfo[];
}
export interface MethodParameterInfo {
name: string;
export interface FunctionParameterInfo extends ParamTag {
type: string;
isOptional: boolean;
}
@@ -20,9 +23,9 @@ export interface MethodParameterInfo {
* We will use the `params` property to store the final normalized form since it is already
* an object.
*/
export function normalizeMethodParameters(method: NormalizedMethodMemberDoc) {
if (method.parameters) {
method.parameters.forEach(parameter => {
export function normalizeFunctionParameters(doc: NormalizedFunctionDoc) {
if (doc.parameters) {
doc.parameters.forEach(parameter => {
let [parameterName, parameterType] = parameter.split(':');
// If the parameter is optional, the name here will contain a '?'. We store whether the
@@ -33,23 +36,22 @@ export function normalizeMethodParameters(method: NormalizedMethodMemberDoc) {
parameterName = parameterName.replace('?', '');
}
if (!method.params) {
method.params = [];
}
doc.params = doc.params || [];
if (!parameterType) {
console.warn(`Missing parameter type information (${parameterName}) in ` +
`${method.fileInfo.relativePath}:${method.startingLine}`);
`${doc.fileInfo.relativePath}:${doc.startingLine}`);
return;
}
const existingParameterInfo = method.params.find(p => p.name == parameterName);
const existingParameterInfo = doc.params.find(p => p.name == parameterName);
if (!existingParameterInfo) {
method.params.push({
doc.params.push({
name: parameterName,
type: parameterType.trim(),
isOptional: isOptional
isOptional: isOptional,
description: ''
});
} else {
existingParameterInfo.type = parameterType.trim();
+27 -9
View File
@@ -1,15 +1,23 @@
import {DocCollection, Processor} from 'dgeni';
import {MethodMemberDoc} from 'dgeni-packages/typescript/api-doc-types/MethodMemberDoc';
import {getDirectiveMetadata} from '../common/directive-metadata';
import {
decorateDeprecatedDoc, getDirectiveSelectors, isDirective, isMethod, isNgModule, isProperty,
isService
decorateDeprecatedDoc,
getDirectiveSelectors,
isDirective,
isMethod,
isNgModule,
isProperty,
isService,
} from '../common/decorators';
import {
CategorizedClassDoc, CategorizedClassLikeDoc, CategorizedMethodMemberDoc,
CategorizedPropertyMemberDoc
CategorizedClassDoc,
CategorizedClassLikeDoc,
CategorizedFunctionExportDoc,
CategorizedMethodMemberDoc,
CategorizedPropertyMemberDoc,
} from '../common/dgeni-definitions';
import {normalizeMethodParameters} from '../common/normalize-method-parameters';
import {getDirectiveMetadata} from '../common/directive-metadata';
import {normalizeFunctionParameters} from '../common/normalize-function-parameters';
import {getInputBindingData, getOutputBindingData} from '../common/property-bindings';
import {sortCategorizedMembers} from '../common/sort-members';
@@ -30,6 +38,10 @@ export class Categorizer implements Processor {
docs
.filter(doc => doc.docType === 'class' || doc.docType === 'interface')
.forEach(doc => this.decorateClassLikeDoc(doc));
docs
.filter(doc => doc.docType === 'function')
.forEach(doc => this.decorateFunctionExportDoc(doc));
}
/**
@@ -92,11 +104,17 @@ export class Categorizer implements Processor {
* will be normalized, so that they can be easily used inside of dgeni templates.
*/
private decorateMethodDoc(methodDoc: CategorizedMethodMemberDoc) {
normalizeMethodParameters(methodDoc);
normalizeFunctionParameters(methodDoc);
decorateDeprecatedDoc(methodDoc);
}
// Mark methods with a `void` return type so we can omit show the return type in the docs.
methodDoc.showReturns = methodDoc.type ? methodDoc.type !== 'void' : false;
/**
* Method that will be called for each function export doc. The parameters for the functions
* will be normalized, so that they can be easily used inside of Dgeni templates.
*/
private decorateFunctionExportDoc(functionDoc: CategorizedFunctionExportDoc) {
normalizeFunctionParameters(functionDoc);
decorateDeprecatedDoc(functionDoc);
}
/**
@@ -1,6 +1,7 @@
import {DocCollection, Document, Processor} from 'dgeni';
import {InterfaceExportDoc} from 'dgeni-packages/typescript/api-doc-types/InterfaceExportDoc';
import {TypeAliasExportDoc} from 'dgeni-packages/typescript/api-doc-types/TypeAliasExportDoc';
import {FunctionExportDoc} from 'dgeni-packages/typescript/api-doc-types/FunctionExportDoc';
import {CategorizedClassDoc} from '../common/dgeni-definitions';
import * as path from 'path';
@@ -46,6 +47,9 @@ export class ComponentGroup {
/** Additional type aliases that belong to the component group. */
additionalTypeAliases: TypeAliasExportDoc[] = [];
/** Additional functions that belong to the component group. */
additionalFunctions: FunctionExportDoc[] = [];
/** NgModule that defines the current component group. */
ngModule: CategorizedClassDoc | null = null;
@@ -103,6 +107,8 @@ export class ComponentGrouper implements Processor {
group.additionalInterfaces.push(doc);
} else if (doc.docType === 'type-alias') {
group.additionalTypeAliases.push(doc);
} else if (doc.docType === 'function') {
group.additionalFunctions.push(doc);
}
});
@@ -79,6 +79,20 @@
{% endfor %}
{%- endif -%}
{%- if doc.additionalFunctions.length -%}
<h3 id="additional_functions" class="docs-header-link docs-api-h3">
<span header-link="additional_functions"></span>
Additional functions
</h3>
{% for item in doc.additionalFunctions %}
{#
Since the function docs have a similar structure as method docs, we use
the method template.
#}
{$ method(item) $}
{% endfor %}
{%- endif -%}
{%- if doc.additionalTypeAliases.length -%}
<h3 id="additional_type_aliases" class="docs-header-link docs-api-h3">
<span header-link="additional_type_aliases"></span>
+1 -1
View File
@@ -47,7 +47,7 @@
{% endfor %}
{%- endif -%}
{%- if method.showReturns -%}
{%- if method.type and method.type !== "void" -%}
<thead>
<tr class="docs-api-method-returns-header-row">
<th colspan="2" class="docs-api-method-returns-header-cell">Returns</th>