Skip to content

Commit

Permalink
docs: show inherited properties (#9299)
Browse files Browse the repository at this point in the history
* Fixes that properties from mixins (e.g color, disabled) are not showing up in the docs.
* No longer runs Dgeni twice when executing the docs task.

Fixes #5284
  • Loading branch information
devversion authored and andrewseguin committed Jan 12, 2018
1 parent acd9066 commit e5a0f7d
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 2 deletions.
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

0 comments on commit e5a0f7d

Please sign in to comment.