Skip to content

build(docs): show exported constants in docs #13168

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/cdk/overlay/overlay-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export class OverlayModule {}
/**
* @deprecated Use `OverlayModule` instead.
* @breaking-change 7.0.0
* @docs-private
*/
export const OVERLAY_PROVIDERS: Provider[] = [
Overlay,
Expand Down
5 changes: 4 additions & 1 deletion src/lib/datepicker/datepicker-animations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ import {
AnimationTriggerMetadata,
} from '@angular/animations';

/** Animations used by the Material datepicker. */
/**
* Animations used by the Material datepicker.
* @docs-private
*/
export const matDatepickerAnimations: {
readonly transformPanel: AnimationTriggerMetadata;
readonly fadeInCalendar: AnimationTriggerMetadata;
Expand Down
5 changes: 4 additions & 1 deletion src/lib/dialog/dialog-animations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ const animationBody = [
animate('75ms cubic-bezier(0.4, 0.0, 0.2, 1)', style({opacity: 0}))),
];

/** Animations used by MatDialog. */
/**
* Animations used by MatDialog.
* @docs-private
*/
export const matDialogAnimations: {
readonly dialogContainer: AnimationTriggerMetadata;
readonly slideDialog: AnimationTriggerMetadata;
Expand Down
4 changes: 3 additions & 1 deletion src/lib/expansion/expansion-animations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@ export const EXPANSION_PANEL_ANIMATION_TIMING = '225ms cubic-bezier(0.4,0.0,0.2,
* `collapsed` this acts a noop since no style values change.
*
* In the case where angular's animation state is out of sync with the expansion panel's state, the
* expansion panel being `expanded` and angular animations being`void`, the animation from the
* expansion panel being `expanded` and angular animations being `void`, the animation from the
* `expanded`'s effective styles (though in a `void` animation state) to the collapsed state will
* occur as expected.
*
* Angular Bug: https://github.com/angular/angular/issues/18847
*
* @docs-private
*/
export const matExpansionAnimations: {
readonly indicatorRotate: AnimationTriggerMetadata;
Expand Down
5 changes: 4 additions & 1 deletion src/lib/form-field/form-field-animations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ import {
AnimationTriggerMetadata,
} from '@angular/animations';

/** Animations used by the MatFormField. */
/**
* Animations used by the MatFormField.
* @docs-private
*/
export const matFormFieldAnimations: {
readonly transitionMessages: AnimationTriggerMetadata
} = {
Expand Down
3 changes: 3 additions & 0 deletions src/lib/menu/menu-animations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import{
* Animations used by the mat-menu component.
* Animation duration and timing values are based on:
* https://material.io/guidelines/components/menus.html#menus-usage
* @docs-private
*/
export const matMenuAnimations: {
readonly transformMenu: AnimationTriggerMetadata;
Expand Down Expand Up @@ -65,11 +66,13 @@ export const matMenuAnimations: {
/**
* @deprecated
* @breaking-change 7.0.0
* @docs-private
*/
export const fadeInItems = matMenuAnimations.fadeInItems;

/**
* @deprecated
* @breaking-change 7.0.0
* @docs-private
*/
export const transformMenu = matMenuAnimations.transformMenu;
3 changes: 3 additions & 0 deletions src/lib/select/select-animations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
* const containing the metadata for one animation.
*
* The values below match the implementation of the AngularJS Material mat-select animation.
* @docs-private
*/
export const matSelectAnimations: {
readonly transformPanel: AnimationTriggerMetadata;
Expand Down Expand Up @@ -74,11 +75,13 @@ export const matSelectAnimations: {
/**
* @deprecated
* @breaking-change 7.0.0
* @docs-private
*/
export const transformPanel = matSelectAnimations.transformPanel;

/**
* @deprecated
* @breaking-change 7.0.0
* @docs-private
*/
export const fadeInContent = matSelectAnimations.fadeInContent;
5 changes: 4 additions & 1 deletion src/lib/sidenav/drawer-animations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ import {
AnimationTriggerMetadata,
} from '@angular/animations';

/** Animations used by the Material drawers. */
/**
* Animations used by the Material drawers.
* @docs-private
*/
export const matDrawerAnimations: {
readonly transformDrawer: AnimationTriggerMetadata;
} = {
Expand Down
5 changes: 4 additions & 1 deletion src/lib/snack-bar/snack-bar-animations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ import {
AnimationTriggerMetadata,
} from '@angular/animations';

/** Animations used by the Material snack bar. */
/**
* Animations used by the Material snack bar.
* @docs-private
*/
export const matSnackBarAnimations: {
readonly snackBarState: AnimationTriggerMetadata;
} = {
Expand Down
5 changes: 4 additions & 1 deletion src/lib/sort/sort-animations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ import {AnimationCurves, AnimationDurations} from '@angular/material/core';
const SORT_ANIMATION_TRANSITION = AnimationDurations.ENTERING + ' ' +
AnimationCurves.STANDARD_CURVE;

/** Animations used by MatSort. */
/**
* Animations used by MatSort.
* @docs-private
*/
export const matSortAnimations: {
readonly indicator: AnimationTriggerMetadata;
readonly leftPointer: AnimationTriggerMetadata;
Expand Down
5 changes: 4 additions & 1 deletion src/lib/stepper/stepper-animations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ import {
AnimationTriggerMetadata,
} from '@angular/animations';

/** Animations used by the Material steppers. */
/**
* Animations used by the Material steppers.
* @docs-private
*/
export const matStepperAnimations: {
readonly horizontalStepTransition: AnimationTriggerMetadata;
readonly verticalStepTransition: AnimationTriggerMetadata;
Expand Down
5 changes: 4 additions & 1 deletion src/lib/tabs/tabs-animations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ import {
AnimationTriggerMetadata,
} from '@angular/animations';

/** Animations used by the Material tabs. */
/**
* Animations used by the Material tabs.
* @docs-private
*/
export const matTabsAnimations: {
readonly translateTab: AnimationTriggerMetadata;
} = {
Expand Down
5 changes: 4 additions & 1 deletion src/lib/tooltip/tooltip-animations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ import {
trigger,
} from '@angular/animations';

/** Animations used by MatTooltip. */
/**
* Animations used by MatTooltip.
* @docs-private
*/
export const matTooltipAnimations: {
readonly tooltipState: AnimationTriggerMetadata;
} = {
Expand Down
4 changes: 4 additions & 0 deletions tools/dgeni/common/dgeni-definitions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {ApiDoc} from 'dgeni-packages/typescript/api-doc-types/ApiDoc';
import {ClassExportDoc} from 'dgeni-packages/typescript/api-doc-types/ClassExportDoc';
import {ClassLikeExportDoc} from 'dgeni-packages/typescript/api-doc-types/ClassLikeExportDoc';
import {ConstExportDoc} from 'dgeni-packages/typescript/api-doc-types/ConstExportDoc';
import {PropertyMemberDoc} from 'dgeni-packages/typescript/api-doc-types/PropertyMemberDoc';
import {ParsedDecorator} from 'dgeni-packages/typescript/services/TsParser/getDecorators';
import {FunctionExportDoc} from 'dgeni-packages/typescript/api-doc-types/FunctionExportDoc';
Expand Down Expand Up @@ -51,3 +52,6 @@ export interface CategorizedMethodMemberDoc
/** Extended Dgeni function export document that simplifies logic for the Dgeni template. */
export interface CategorizedFunctionExportDoc
extends NormalizedFunctionDoc, FunctionExportDoc, DeprecationDoc {}

/** Extended Dgeni const export document that simplifies logic for the Dgeni template. */
export interface CategorizedConstExportDoc extends ConstExportDoc, DeprecationDoc {}
3 changes: 3 additions & 0 deletions tools/dgeni/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {Package} from 'dgeni';
import {Host} from 'dgeni-packages/typescript/services/ts-host/host';
import {HighlightNunjucksExtension} from './nunjucks-tags/highlight';
import {patchLogService} from './patch-log-service';
import {DocsPrivateFilter} from './processors/docs-private-filter';
import {Categorizer} from './processors/categorizer';
Expand Down Expand Up @@ -163,4 +164,6 @@ apiDocsPackage.config((templateFinder: any, templateEngine: any) => {
variableStart: '{$',
variableEnd: '$}'
};

templateEngine.tags.push(new HighlightNunjucksExtension());
});
37 changes: 37 additions & 0 deletions tools/dgeni/nunjucks-tags/highlight.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const hljs = require('highlight.js');

/**
* Nunjucks extension that supports rendering highlighted content. Content that is placed in
* between a {% highlight %} and {% end_highlight %} block will be automatically highlighted.
*
* HighlightJS cannot detect the code language automatically. Therefore, developers need to
* specify the language manually as first tag-block argument.
*/
export class HighlightNunjucksExtension {

/** Tags that will be parsed by this Nunjucks extension. */
tags = ['highlight'];

/** Disable autoescaping for content that is rendered within this extension. */
autoescape = false;

parse(parser: any, nodes: any) {
const startToken = parser.nextToken();
const args = parser.parseSignature(null, true);

// Jump to the end of the "{% highlight }" block.
parser.advanceAfterBlockEnd(startToken.value);

// Parse text content until {% end_highlight }" has been reached.
const textContent = parser.parseUntilBlocks('end_highlight');

// Jump to the end of the "{% highlight }" block.
parser.advanceAfterBlockEnd();

return new nodes.CallExtension(this, 'render', args, [textContent]);
}

render(_context: any, language: string, contentFn: () => string) {
return hljs.highlight(language, contentFn()).value;
}
}
13 changes: 13 additions & 0 deletions tools/dgeni/processors/categorizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
import {
CategorizedClassDoc,
CategorizedClassLikeDoc,
CategorizedConstExportDoc,
CategorizedFunctionExportDoc,
CategorizedMethodMemberDoc,
CategorizedPropertyMemberDoc,
Expand Down Expand Up @@ -42,6 +43,10 @@ export class Categorizer implements Processor {
docs
.filter(doc => doc.docType === 'function')
.forEach(doc => this.decorateFunctionExportDoc(doc));

docs
.filter(doc => doc.docType === 'const')
.forEach(doc => this.decorateConstExportDoc(doc));
}

/**
Expand Down Expand Up @@ -117,6 +122,14 @@ export class Categorizer implements Processor {
decorateDeprecatedDoc(functionDoc);
}

/**
* Method that will be called for each const export document. We decorate the const
* documents with a property that states whether the constant is deprecated or not.
*/
private decorateConstExportDoc(doc: CategorizedConstExportDoc) {
decorateDeprecatedDoc(doc);
}

/**
* Method that will be called for each property doc. Properties that are Angular inputs or
* outputs will be marked. Aliases for the inputs or outputs will be stored as well.
Expand Down
6 changes: 6 additions & 0 deletions tools/dgeni/processors/entry-point-grouper.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {DocCollection, Document, Processor} from 'dgeni';
import {ConstExportDoc} from 'dgeni-packages/typescript/api-doc-types/ConstExportDoc';
import {FunctionExportDoc} from 'dgeni-packages/typescript/api-doc-types/FunctionExportDoc';
import {InterfaceExportDoc} from 'dgeni-packages/typescript/api-doc-types/InterfaceExportDoc';
import {TypeAliasExportDoc} from 'dgeni-packages/typescript/api-doc-types/TypeAliasExportDoc';
Expand Down Expand Up @@ -50,6 +51,9 @@ export class EntryPointDoc {
/** Functions that belong to the entry-point. */
functions: FunctionExportDoc[] = [];

/** Constants that belong to the entry-point. */
constants: ConstExportDoc[] = [];

/** NgModule that defines the current entry-point. */
ngModule: CategorizedClassDoc | null = null;

Expand Down Expand Up @@ -108,6 +112,8 @@ export class EntryPointGrouper implements Processor {
entryPoint.typeAliases.push(doc);
} else if (doc.docType === 'function') {
entryPoint.functions.push(doc);
} else if (doc.docType === 'const') {
entryPoint.constants.push(doc);
}
});

Expand Down
24 changes: 24 additions & 0 deletions tools/dgeni/templates/constant.template.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{% import "macros.html" as macros %}

<h4 id="{$ constant.name $}" class="docs-header-link docs-api-h4 docs-api-constant-name">
<span header-link="{$ constant.name $}"></span>
<code>{$ constant.name $}</code>
</h4>

{%- if constant.isDeprecated -%}
<div class="docs-api-constant-deprecated-marker" {$ macros.deprecationTitle(constant) $}>
Deprecated
</div>
{%- endif -%}

{%- if constant.description -%}
<p class="docs-api-constant-description">{$ constant.description | marked | safe $}</p>
{%- endif -%}

<pre class="docs-markdown-pre">
<code class="docs-markdown-code">
{%- highlight "typescript" -%}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why use highlightjs here when we don't do this for any of the other symbol types?

Copy link
Member Author

@devversion devversion Sep 17, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, I couldn't think of anything that is describing the constant better.

My goal would be to do this for the other types as well (in follow-ups)

This also just looks way better IMO & also describes exports pretty good (besides the description). This is how Angular.io also does it

const {$ constant.name | safe $}: {$ constant.type | safe $}
{%- end_highlight -%}
</code>
</pre>
14 changes: 14 additions & 0 deletions tools/dgeni/templates/entry-point.template.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
{% include 'type-alias.template.html' %}
{% endmacro %}

{% macro constant(constant) -%}
{% include 'constant.template.html' %}
{% endmacro %}

<div class="docs-api">
<h2>
API reference for Angular {$ doc.packageDisplayName $} {$ doc.displayName $}
Expand Down Expand Up @@ -102,4 +106,14 @@ <h3 id="type_aliases" class="docs-header-link docs-api-h3">
{$ typeAlias(item) $}
{% endfor %}
{%- endif -%}

{%- if doc.constants.length -%}
<h3 id="constants" class="docs-header-link docs-api-h3">
<span header-link="constants"></span>
Constants
</h3>
{% for item in doc.constants %}
{$ constant(item) $}
{% endfor %}
{%- endif -%}
</div>