Skip to content

docs: show inherited properties #9299

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/lib/core/common-behaviors/color.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {ElementRef} from '@angular/core';

/** @docs-private */
export interface CanColor {
/** Theme color palette for the component. */
color: ThemePalette;
}

Expand Down
1 change: 1 addition & 0 deletions src/lib/core/common-behaviors/disable-ripple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {Constructor} from './constructor';

/** @docs-private */
export interface CanDisableRipple {
/** Whether ripples are disabled. */
disableRipple: boolean;
}

Expand Down
1 change: 1 addition & 0 deletions src/lib/core/common-behaviors/disabled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {Constructor} from './constructor';

/** @docs-private */
export interface CanDisable {
/** Whether the component is disabled. */
disabled: boolean;
}

Expand Down
1 change: 1 addition & 0 deletions src/lib/core/common-behaviors/tabindex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {CanDisable} from './disabled';

/** @docs-private */
export interface HasTabIndex {
/** Tabindex of the component. */
tabIndex: number;
}

Expand Down
12 changes: 11 additions & 1 deletion tools/dgeni/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {Package} from 'dgeni';
import {DocsPrivateFilter} from './processors/docs-private-filter';
import {Categorizer} from './processors/categorizer';
import {FilterExportAliases} from './processors/filter-export-aliases';
import {MergeInheritedProperties} from './processors/merge-inherited-properties';
import {ComponentGrouper} from './processors/component-grouper';
import {ReadTypeScriptModules} from 'dgeni-packages/typescript/processors/readTypeScriptModules';
import {TsParser} from 'dgeni-packages/typescript/services/TsParser';
Expand Down Expand Up @@ -51,6 +52,9 @@ export const apiDocsPackage = new Package('material2-api-docs', dgeniPackageDeps
// Processor that filters out aliased exports that should not be shown in the docs.
apiDocsPackage.processor(new FilterExportAliases());

// Processor that merges inherited properties of a class with the class doc.
apiDocsPackage.processor(new MergeInheritedProperties());

// Processor that filters out symbols that should not be shown in the docs.
apiDocsPackage.processor(new DocsPrivateFilter());

Expand Down Expand Up @@ -99,8 +103,14 @@ apiDocsPackage.config((readTypeScriptModules: ReadTypeScriptModules, tsParser: T
typescriptPathMap[`@angular/cdk/${packageName}`] = [`./cdk/${packageName}/index.ts`];
});

tsParser.options.baseUrl = sourceDir;
materialPackages.forEach(packageName => {
typescriptPathMap[`@angular/material/${packageName}`] = [`./lib/${packageName}/index.ts`];
});

// Add proper path mappings to the TSParser service of Dgeni. This ensures that properties
// from mixins (e.g. color, disabled) are showing up properly in the docs.
tsParser.options.paths = typescriptPathMap;
tsParser.options.baseUrl = sourceDir;

// Entry points for docs generation. All publically exported symbols found through these
// files will have docs generated.
Expand Down
2 changes: 2 additions & 0 deletions tools/dgeni/processors/categorizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ export class Categorizer implements Processor {
private decoratePropertyDoc(propertyDoc: CategorizedPropertyMemberDoc) {
decorateDeprecatedDoc(propertyDoc);

// TODO(devversion): detect inputs based on the `inputs` property in the component metadata.

propertyDoc.isDirectiveInput = isDirectiveInput(propertyDoc);
propertyDoc.directiveInputAlias = getDirectiveInputAlias(propertyDoc);

Expand Down
34 changes: 34 additions & 0 deletions tools/dgeni/processors/merge-inherited-properties.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import {DocCollection, Processor} from 'dgeni';
import {ClassExportDoc} from 'dgeni-packages/typescript/api-doc-types/ClassExportDoc';
import {MemberDoc} from 'dgeni-packages/typescript/api-doc-types/MemberDoc';

/**
* Processor that merges inherited properties of a class with the class doc. This is necessary
* to properly show public properties from TypeScript mixin interfaces in the API.
*/
export class MergeInheritedProperties implements Processor {
name = 'merge-inherited-properties';
$runBefore = ['categorizer'];

$process(docs: DocCollection) {
return docs
.filter(doc => doc.docType === 'class')
.forEach(doc => this.addInhertiedProperties(doc));
}

private addInhertiedProperties(doc: ClassExportDoc) {
doc.implementsClauses.filter(clause => clause.doc).forEach(clause => {
clause.doc!.members.forEach(member => this.addMemberDocIfNotPresent(doc, member));
});

doc.extendsClauses.filter(clause => clause.doc).forEach(clause => {
clause.doc!.members.forEach(member => this.addMemberDocIfNotPresent(doc, member));
});
}

private addMemberDocIfNotPresent(destination: ClassExportDoc, memberDoc: MemberDoc) {
if (!destination.members.find(member => member.name === memberDoc.name)) {
destination.members.push(memberDoc);
}
}
}
2 changes: 1 addition & 1 deletion tools/gulp/tasks/docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ task('api-docs', () => {
* Minifies all HTML files that have been generated. The HTML files for the
* highlighted examples can be skipped, because it won't have any effect.
*/
task('minify-html-files', ['api-docs'], () => {
task('minify-html-files', () => {
return src('dist/docs/+(api|markdown)/**/*.html')
.pipe(htmlmin(htmlMinifierOptions))
.pipe(dest('dist/docs'));
Expand Down