Skip to content

Commit c990265

Browse files
JeanMechepkozlowski-opensource
authored andcommitted
docs(docs-infra): Improve doc support for pipes. (angular#60926)
This commits adds the pipe usage and the impure pipe mention. PR Close angular#60926
1 parent 1983a5c commit c990265

File tree

13 files changed

+83
-8
lines changed

13 files changed

+83
-8
lines changed

adev/shared-docs/pipeline/api-gen/rendering/entities.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,8 @@ export interface DirectiveEntry extends ClassEntry {
133133
export interface PipeEntry extends ClassEntry {
134134
pipeName: string;
135135
isStandalone: boolean;
136-
// TODO: add `isPure`.
136+
isPure: boolean;
137+
usage: string;
137138
}
138139

139140
export interface FunctionSignatureMetadata extends DocEntry {

adev/shared-docs/pipeline/api-gen/rendering/entities/renderables.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
JsDocTagEntry,
1919
MemberEntry,
2020
ParameterEntry,
21+
PipeEntry,
2122
TypeAliasEntry,
2223
} from '../entities';
2324

@@ -60,6 +61,12 @@ export type ClassEntryRenderable = ClassEntry &
6061
members: MemberEntryRenderable[];
6162
};
6263

64+
export type PipeEntryRenderable = PipeEntry &
65+
DocEntryRenderable &
66+
HasRenderableToc & {
67+
members: MemberEntryRenderable[];
68+
};
69+
6370
export type DecoratorEntryRenderable = DecoratorEntry &
6471
DocEntryRenderable &
6572
HasRenderableToc & {

adev/shared-docs/pipeline/api-gen/rendering/templates/class-reference.tsx

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,43 @@
77
*/
88

99
import {Fragment, h} from 'preact';
10-
import {ClassEntryRenderable, DecoratorEntryRenderable} from '../entities/renderables';
10+
import {
11+
ClassEntryRenderable,
12+
DecoratorEntryRenderable,
13+
PipeEntryRenderable,
14+
} from '../entities/renderables';
1115
import {ClassMemberList} from './class-member-list';
1216
import {HeaderApi} from './header-api';
13-
import {API_REFERENCE_CONTAINER, REFERENCE_MEMBERS} from '../styling/css-classes';
17+
import {
18+
API_REFERENCE_CONTAINER,
19+
REFERENCE_MEMBERS,
20+
SECTION_CONTAINER,
21+
} from '../styling/css-classes';
1422
import {SectionDescription} from './section-description';
1523
import {SectionUsageNotes} from './section-usage-notes';
1624
import {SectionApi} from './section-api';
25+
import {SectionHeading} from './section-heading';
26+
import {PipeEntry} from '../entities';
27+
import {codeToHtml} from '../shiki/shiki';
28+
import {RawHtml} from './raw-html';
1729

1830
/** Component to render a class API reference document. */
19-
export function ClassReference(entry: ClassEntryRenderable | DecoratorEntryRenderable) {
31+
export function ClassReference(
32+
entry: ClassEntryRenderable | DecoratorEntryRenderable | PipeEntryRenderable,
33+
) {
2034
return (
2135
<div className={API_REFERENCE_CONTAINER}>
2236
<HeaderApi entry={entry} />
37+
{entry.entryType === 'pipe' ? (
38+
<>
39+
<div className={SECTION_CONTAINER + ' docs-reference-api-section'}>
40+
<SectionHeading name="Pipe usage" />
41+
<RawHtml value={codeToHtml((entry as PipeEntry).usage, 'angular-html')} />
42+
</div>
43+
</>
44+
) : (
45+
''
46+
)}
2347
<SectionApi entry={entry} />
2448
{entry.members.length > 0 ? (
2549
<div class={REFERENCE_MEMBERS}>

adev/shared-docs/pipeline/api-gen/rendering/templates/header-api.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
*/
88

99
import {h} from 'preact';
10-
import {EntryType, isDocEntryWithSourceInfo} from '../entities';
11-
import {DocEntryRenderable} from '../entities/renderables';
10+
import {EntryType, isDocEntryWithSourceInfo, PipeEntry} from '../entities';
11+
import {DocEntryRenderable, PipeEntryRenderable} from '../entities/renderables';
1212
import {
1313
HEADER_CLASS_NAME,
1414
HEADER_ENTRY_CATEGORY,
@@ -18,7 +18,7 @@ import {
1818
import {DocsPillRow} from './docs-pill-row';
1919

2020
/** Component to render a header of the API page. */
21-
export function HeaderApi(props: {entry: DocEntryRenderable; showFullDescription?: boolean}) {
21+
export function HeaderApi(props: {entry: DocEntryRenderable | PipeEntryRenderable; showFullDescription?: boolean}) {
2222
const entry = props.entry;
2323

2424
// TODO: This link point to the main branch.
@@ -50,6 +50,12 @@ export function HeaderApi(props: {entry: DocEntryRenderable; showFullDescription
5050
<a href="/reference/releases#experimental">Experimental</a>
5151
</div>
5252
)}
53+
54+
{entry.entryType === EntryType.Pipe && !(entry as PipeEntry).isPure && (
55+
<div className={`${HEADER_ENTRY_LABEL} type-impure-pipe full`}>
56+
Impure
57+
</div>
58+
)}
5359
</div>
5460
{sourceUrl && (
5561
<a

adev/shared-docs/styles/_api-item-label.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@
8383
--label-theme: var(--symbolic-teal);
8484
}
8585

86+
&.type-impure-pipe {
87+
--label-theme: var(--symbolic-pink);
88+
}
89+
8690
&.type-ng_module {
8791
--label-theme: var(--symbolic-brown);
8892
}

adev/shared-docs/styles/_reference.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,10 @@
259259
}
260260
}
261261

262+
.pipe-usage {
263+
padding: 1rem;
264+
}
265+
262266
// "API member card"-specific styles
263267
.docs-reference-member-card {
264268
.docs-reference-card-item {

packages/compiler-cli/src/ngtsc/annotations/src/pipe.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ export class PipeDecoratorHandler
229229
isStandalone: analysis.meta.isStandalone,
230230
decorator: analysis.decorator,
231231
isExplicitlyDeferred: false,
232+
isPure: analysis.meta.pure,
232233
});
233234

234235
this.injectableRegistry.registerInjectable(node, {

packages/compiler-cli/src/ngtsc/docs/src/class_extractor.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,8 @@ class PipeExtractor extends ClassExtractor {
506506
pipeName: this.metadata.name,
507507
entryType: EntryType.Pipe,
508508
isStandalone: this.metadata.isStandalone,
509+
usage: extractPipeSyntax(this.metadata, this.declaration as ts.ClassDeclaration),
510+
isPure: this.metadata.isPure,
509511
};
510512
}
511513
}
@@ -564,3 +566,23 @@ export function extractInterface(
564566
const extractor = new ClassExtractor(declaration, typeChecker);
565567
return extractor.extract();
566568
}
569+
570+
function extractPipeSyntax(metadata: PipeMeta, classDeclaration: ts.ClassDeclaration): string {
571+
const transformParams = classDeclaration.members.find((member) => {
572+
return (
573+
ts.isMethodDeclaration(member) &&
574+
member.name &&
575+
ts.isIdentifier(member.name) &&
576+
member.name.getText() === 'transform'
577+
);
578+
}) as ts.MethodDeclaration;
579+
580+
let paramNames = transformParams.parameters
581+
// value is the first argument, it's already referenced before the pipe
582+
.slice(1)
583+
.map((param) => {
584+
return param.name.getText();
585+
});
586+
587+
return `{{ value_expression | ${metadata.name}${paramNames.length ? ':' + paramNames.join(':') : ''} }}`;
588+
}

packages/compiler-cli/src/ngtsc/docs/src/entities.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,8 @@ export interface DirectiveEntry extends ClassEntry {
139139
export interface PipeEntry extends ClassEntry {
140140
pipeName: string;
141141
isStandalone: boolean;
142-
// TODO: add `isPure`.
142+
usage: string;
143+
isPure: boolean;
143144
}
144145

145146
export interface FunctionSignatureMetadata extends DocEntry {

packages/compiler-cli/src/ngtsc/metadata/src/api.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,7 @@ export interface PipeMeta {
353353
name: string;
354354
nameExpr: ts.Expression | null;
355355
isStandalone: boolean;
356+
isPure: boolean;
356357
decorator: ts.Decorator | null;
357358
isExplicitlyDeferred: boolean;
358359
}

0 commit comments

Comments
 (0)