refactor(docs-infra): simplify code snippet indentation in the "Cheat sheet" guide (#41051)
Previously, the indentation of code snippets in the "Cheat sheet" guide was done using `<br>` elements (for line breaks) and ` ` HTML entities (for space). This was laborious and put the onus on the author to remember to use these symbols (instead of regular whitespace characters). (Discussed in https://github.com/angular/angular/pull/41051#discussion_r585651621.) This commit changes the way `<code>` elements are styles inside the "Cheat sheet" guide to allow using regular whitespace characters in code snippets. It also changes all `<br>`/` ` occurrences to `\n`/` ` respectively to make code snippets more readable in the source code. PR Close #41051
This commit is contained in:
parent
d7398d3025
commit
7a27cd262f
|
@ -24,7 +24,12 @@
|
||||||
</th>
|
</th>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td><code>@<b>NgModule</b>({<br> declarations: ..., imports: ..., exports: ...,<br> providers: ..., bootstrap: ...<br>})<br>class MyModule {}</code></td>
|
<td><code>@<b>NgModule</b>({
|
||||||
|
declarations: ..., imports: ..., exports: ...,
|
||||||
|
providers: ..., bootstrap: ...
|
||||||
|
})
|
||||||
|
class MyModule {}
|
||||||
|
</code></td>
|
||||||
<td><p>Defines a module that contains components, directives, pipes, and providers.</p>
|
<td><p>Defines a module that contains components, directives, pipes, and providers.</p>
|
||||||
</td>
|
</td>
|
||||||
</tr><tr>
|
</tr><tr>
|
||||||
|
@ -93,7 +98,9 @@ is available to <code>declarations</code> of this module.</p>
|
||||||
<td><p>Sets up two-way data binding. Equivalent to: <code><my-cmp [title]="name" (titleChange)="name=$event"></code></p>
|
<td><p>Sets up two-way data binding. Equivalent to: <code><my-cmp [title]="name" (titleChange)="name=$event"></code></p>
|
||||||
</td>
|
</td>
|
||||||
</tr><tr>
|
</tr><tr>
|
||||||
<td><code><video <b>#movieplayer</b> ...></video><br><button <b>(click)</b>="movieplayer.play()">Play</button></code></td>
|
<td><code><video <b>#movieplayer</b> ...></video>
|
||||||
|
<button <b>(click)</b>="movieplayer.play()">Play</button>
|
||||||
|
</code></td>
|
||||||
<td><p>Creates a local variable <code>movieplayer</code> that provides access to the <code>video</code> element instance in data-binding and event-binding expressions in the current template.</p>
|
<td><p>Creates a local variable <code>movieplayer</code> that provides access to the <code>video</code> element instance in data-binding and event-binding expressions in the current template.</p>
|
||||||
</td>
|
</td>
|
||||||
</tr><tr>
|
</tr><tr>
|
||||||
|
@ -114,7 +121,10 @@ is available to <code>declarations</code> of this module.</p>
|
||||||
<td><p>An SVG snippet template needs an <code>svg:</code> prefix on its root element to disambiguate the SVG element from an HTML component.</p>
|
<td><p>An SVG snippet template needs an <code>svg:</code> prefix on its root element to disambiguate the SVG element from an HTML component.</p>
|
||||||
</td>
|
</td>
|
||||||
</tr><tr>
|
</tr><tr>
|
||||||
<td><code><<b>svg</b>><br> <rect x="0" y="0" width="100" height="100"/><br></<b>svg</b>></code></td>
|
<td><code><<b>svg</b>>
|
||||||
|
<rect x="0" y="0" width="100" height="100"/>
|
||||||
|
</<b>svg</b>>
|
||||||
|
</code></td>
|
||||||
<td><p>An <code><svg></code> root element is detected as an SVG element automatically, without the prefix.</p>
|
<td><p>An <code><svg></code> root element is detected as an SVG element automatically, without the prefix.</p>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
@ -136,7 +146,12 @@ is available to <code>declarations</code> of this module.</p>
|
||||||
<td><p>Turns the li element and its contents into a template, and uses that to instantiate a view for each item in list.</p>
|
<td><p>Turns the li element and its contents into a template, and uses that to instantiate a view for each item in list.</p>
|
||||||
</td>
|
</td>
|
||||||
</tr><tr>
|
</tr><tr>
|
||||||
<td><code><div <b>[ngSwitch]</b>="conditionExpression"><br> <ng-template <b>[<b>ngSwitchCase</b>]</b>="case1Exp">...</ng-template><br> <ng-template <b>ngSwitchCase</b>="case2LiteralString">...</ng-template><br> <ng-template <b>ngSwitchDefault</b>>...</ng-template><br></div></code></td>
|
<td><code><div <b>[ngSwitch]</b>="conditionExpression">
|
||||||
|
<ng-template <b>[<b>ngSwitchCase</b>]</b>="case1Exp">...</ng-template>
|
||||||
|
<ng-template <b>ngSwitchCase</b>="case2LiteralString">...</ng-template>
|
||||||
|
<ng-template <b>ngSwitchDefault</b>>...</ng-template>
|
||||||
|
</div>
|
||||||
|
</code></td>
|
||||||
<td><p>Conditionally swaps the contents of the div by selecting one of the embedded templates based on the current value of <code>conditionExpression</code>.</p>
|
<td><p>Conditionally swaps the contents of the div by selecting one of the embedded templates based on the current value of <code>conditionExpression</code>.</p>
|
||||||
</td>
|
</td>
|
||||||
</tr><tr>
|
</tr><tr>
|
||||||
|
@ -145,7 +160,9 @@ is available to <code>declarations</code> of this module.</p>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td><code><div <b>[ngStyle]</b>="{'property': 'value'}"></code><br><code><div <b>[ngStyle]</b>="dynamicStyles()"></code></td>
|
<td><code><div <b>[ngStyle]</b>="{'property': 'value'}">
|
||||||
|
<div <b>[ngStyle]</b>="dynamicStyles()">
|
||||||
|
</code></td>
|
||||||
<td><p>Allows you to assign styles to an HTML element using CSS. You can use CSS directly, as in the first example, or you can call a method from the component.</p>
|
<td><p>Allows you to assign styles to an HTML element using CSS. You can use CSS directly, as in the first example, or you can call a method from the component.</p>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
@ -173,19 +190,27 @@ is available to <code>declarations</code> of this module.</p>
|
||||||
</th>
|
</th>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td><code><b>@Component({...})</b><br>class MyComponent() {}</code></td>
|
<td><code><b>@Component({...})</b>
|
||||||
|
class MyComponent() {}
|
||||||
|
</code></td>
|
||||||
<td><p>Declares that a class is a component and provides metadata about the component.</p>
|
<td><p>Declares that a class is a component and provides metadata about the component.</p>
|
||||||
</td>
|
</td>
|
||||||
</tr><tr>
|
</tr><tr>
|
||||||
<td><code><b>@Directive({...})</b><br>class MyDirective() {}</code></td>
|
<td><code><b>@Directive({...})</b>
|
||||||
|
class MyDirective() {}
|
||||||
|
</code></td>
|
||||||
<td><p>Declares that a class is a directive and provides metadata about the directive.</p>
|
<td><p>Declares that a class is a directive and provides metadata about the directive.</p>
|
||||||
</td>
|
</td>
|
||||||
</tr><tr>
|
</tr><tr>
|
||||||
<td><code><b>@Pipe({...})</b><br>class MyPipe() {}</code></td>
|
<td><code><b>@Pipe({...})</b>
|
||||||
|
class MyPipe() {}
|
||||||
|
</code></td>
|
||||||
<td><p>Declares that a class is a pipe and provides metadata about the pipe.</p>
|
<td><p>Declares that a class is a pipe and provides metadata about the pipe.</p>
|
||||||
</td>
|
</td>
|
||||||
</tr><tr>
|
</tr><tr>
|
||||||
<td><code><b>@Injectable()</b><br>class MyService() {}</code></td>
|
<td><code><b>@Injectable()</b>
|
||||||
|
class MyService() {}
|
||||||
|
</code></td>
|
||||||
<td><p>Declares that a class can be provided and injected by other classes. Without this decorator, the compiler won't generate enough metadata to allow the class to be created properly when it's injected somewhere.</p>
|
<td><p>Declares that a class can be provided and injected by other classes. Without this decorator, the compiler won't generate enough metadata to allow the class to be created properly when it's injected somewhere.</p>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
@ -228,11 +253,15 @@ so the <code>@Directive</code> configuration applies to components as well</p>
|
||||||
<td><p>List of dependency injection providers scoped to this component's view.</p>
|
<td><p>List of dependency injection providers scoped to this component's view.</p>
|
||||||
</td>
|
</td>
|
||||||
</tr><tr>
|
</tr><tr>
|
||||||
<td><code><b>template:</b> 'Hello {{name}}'<br><b>templateUrl:</b> 'my-component.html'</code></td>
|
<td><code><b>template:</b> 'Hello {{name}}'
|
||||||
|
<b>templateUrl:</b> 'my-component.html'
|
||||||
|
</code></td>
|
||||||
<td><p>Inline template or external template URL of the component's view.</p>
|
<td><p>Inline template or external template URL of the component's view.</p>
|
||||||
</td>
|
</td>
|
||||||
</tr><tr>
|
</tr><tr>
|
||||||
<td><code><b>styles:</b> ['.primary {color: red}']<br><b>styleUrls:</b> ['my-component.css']</code></td>
|
<td><code><b>styles:</b> ['.primary {color: red}']
|
||||||
|
<b>styleUrls:</b> ['my-component.css']
|
||||||
|
</code></td>
|
||||||
<td><p>List of inline CSS styles or external stylesheet URLs for styling the component’s view.</p>
|
<td><p>List of inline CSS styles or external stylesheet URLs for styling the component’s view.</p>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
@ -355,15 +384,32 @@ so the <code>@Directive</code> configuration applies to components as well</p>
|
||||||
</th>
|
</th>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td><code>const routes: <b>Routes</b> = [<br> { path: '', component: HomeComponent },<br> { path: 'path/:routeParam', component: MyComponent },<br> { path: 'staticPath', component: ... },<br> { path: '**', component: ... },<br> { path: 'oldPath', redirectTo: '/staticPath' },<br> { path: ..., component: ..., data: { message: 'Custom' } }<br>]);<br><br>const routing = RouterModule.forRoot(routes);</code></td>
|
<td><code>const routes: <b>Routes</b> = [
|
||||||
|
{ path: '', component: HomeComponent },
|
||||||
|
{ path: 'path/:routeParam', component: MyComponent },
|
||||||
|
{ path: 'staticPath', component: ... },
|
||||||
|
{ path: '**', component: ... },
|
||||||
|
{ path: 'oldPath', redirectTo: '/staticPath' },
|
||||||
|
{ path: ..., component: ..., data: { message: 'Custom' } }
|
||||||
|
]);
|
||||||
|
|
||||||
|
const routing = RouterModule.forRoot(routes);
|
||||||
|
</code></td>
|
||||||
<td><p>Configures routes for the application. Supports static, parameterized, redirect, and wildcard routes. Also supports custom route data and resolve.</p>
|
<td><p>Configures routes for the application. Supports static, parameterized, redirect, and wildcard routes. Also supports custom route data and resolve.</p>
|
||||||
</td>
|
</td>
|
||||||
</tr><tr>
|
</tr><tr>
|
||||||
<td><code><br><<b>router-outlet</b>></<b>router-outlet</b>><br><<b>router-outlet</b> name="aux"></<b>router-outlet</b>><br></code></td>
|
<td><code><<b>router-outlet</b>></<b>router-outlet</b>>
|
||||||
|
<<b>router-outlet</b> name="aux"></<b>router-outlet</b>>
|
||||||
|
</code></td>
|
||||||
<td><p>Marks the location to load the component of the active route.</p>
|
<td><p>Marks the location to load the component of the active route.</p>
|
||||||
</td>
|
</td>
|
||||||
</tr><tr>
|
</tr><tr>
|
||||||
<td><code><br><a <b>routerLink</b>="/path"><br><a <b>[routerLink]</b>="[ '/path', routeParam ]"><br><a <b>[routerLink]</b>="[ '/path', { matrixParam: 'value' } ]"><br><a <b>[routerLink]</b>="[ '/path' ]" [queryParams]="{ page: 1 }"><br><a <b>[routerLink]</b>="[ '/path' ]" fragment="anchor"><br></code></td>
|
<td><code><a <b>routerLink</b>="/path">
|
||||||
|
<a <b>[routerLink]</b>="[ '/path', routeParam ]">
|
||||||
|
<a <b>[routerLink]</b>="[ '/path', { matrixParam: 'value' } ]">
|
||||||
|
<a <b>[routerLink]</b>="[ '/path' ]" [queryParams]="{ page: 1 }">
|
||||||
|
<a <b>[routerLink]</b>="[ '/path' ]" fragment="anchor">
|
||||||
|
</code></td>
|
||||||
<td><p>Creates a link to a different view based on a route instruction consisting of a route path, required and optional parameters, query parameters, and a fragment. To navigate to a root route, use the <code>/</code> prefix; for a child route, use the <code>./</code>prefix; for a sibling or parent, use the <code>../</code> prefix.</p>
|
<td><p>Creates a link to a different view based on a route instruction consisting of a route path, required and optional parameters, query parameters, and a fragment. To navigate to a root route, use the <code>/</code> prefix; for a child route, use the <code>./</code>prefix; for a sibling or parent, use the <code>../</code> prefix.</p>
|
||||||
</td>
|
</td>
|
||||||
</tr><tr>
|
</tr><tr>
|
||||||
|
@ -371,23 +417,64 @@ so the <code>@Directive</code> configuration applies to components as well</p>
|
||||||
<td><p>The provided classes are added to the element when the <code>routerLink</code> becomes the current active route.</p>
|
<td><p>The provided classes are added to the element when the <code>routerLink</code> becomes the current active route.</p>
|
||||||
</td>
|
</td>
|
||||||
</tr><tr>
|
</tr><tr>
|
||||||
<td><code>class <b>CanActivate</b>Guard implements <b>CanActivate</b> {<br> canActivate(<br>  route: ActivatedRouteSnapshot,<br>  state: RouterStateSnapshot<br> ): Observable<boolean|UrlTree>|Promise<boolean|UrlTree>|boolean|UrlTree { ... }<br>}<br><br>{ path: ..., canActivate: [<b>CanActivate</b>Guard] }</code></td>
|
<td><code>class <b>CanActivate</b>Guard implements <b>CanActivate</b> {
|
||||||
|
canActivate(
|
||||||
|
route: ActivatedRouteSnapshot,
|
||||||
|
state: RouterStateSnapshot
|
||||||
|
): Observable<boolean|UrlTree>|Promise<boolean|UrlTree>|boolean|UrlTree { ... }
|
||||||
|
}
|
||||||
|
|
||||||
|
{ path: ..., canActivate: [<b>CanActivate</b>Guard] }
|
||||||
|
</code></td>
|
||||||
<td><p>An interface for defining a class that the router should call first to determine if it should activate this component. Should return a boolean|UrlTree or an Observable/Promise that resolves to a boolean|UrlTree.</p>
|
<td><p>An interface for defining a class that the router should call first to determine if it should activate this component. Should return a boolean|UrlTree or an Observable/Promise that resolves to a boolean|UrlTree.</p>
|
||||||
</td>
|
</td>
|
||||||
</tr><tr>
|
</tr><tr>
|
||||||
<td><code>class <b>CanDeactivate</b>Guard implements <b>CanDeactivate</b><T> {<br> canDeactivate(<br>  component: T,<br>  route: ActivatedRouteSnapshot,<br>  state: RouterStateSnapshot<br> ): Observable<boolean|UrlTree>|Promise<boolean|UrlTree>|boolean|UrlTree { ... }<br>}<br><br>{ path: ..., canDeactivate: [<b>CanDeactivate</b>Guard] }</code></td>
|
<td><code>class <b>CanDeactivate</b>Guard implements <b>CanDeactivate</b><T> {
|
||||||
|
canDeactivate(
|
||||||
|
component: T,
|
||||||
|
route: ActivatedRouteSnapshot,
|
||||||
|
state: RouterStateSnapshot
|
||||||
|
): Observable<boolean|UrlTree>|Promise<boolean|UrlTree>|boolean|UrlTree { ... }
|
||||||
|
}
|
||||||
|
|
||||||
|
{ path: ..., canDeactivate: [<b>CanDeactivate</b>Guard] }
|
||||||
|
</code></td>
|
||||||
<td><p>An interface for defining a class that the router should call first to determine if it should deactivate this component after a navigation. Should return a boolean|UrlTree or an Observable/Promise that resolves to a boolean|UrlTree.</p>
|
<td><p>An interface for defining a class that the router should call first to determine if it should deactivate this component after a navigation. Should return a boolean|UrlTree or an Observable/Promise that resolves to a boolean|UrlTree.</p>
|
||||||
</td>
|
</td>
|
||||||
</tr><tr>
|
</tr><tr>
|
||||||
<td><code>class <b>CanActivateChild</b>Guard implements <b>CanActivateChild</b> {<br> canActivateChild(<br>  route: ActivatedRouteSnapshot,<br>  state: RouterStateSnapshot<br> ): Observable<boolean|UrlTree>|Promise<boolean|UrlTree>|boolean|UrlTree { ... }<br>}<br><br>{ path: ..., canActivateChild: [CanActivateGuard],<br> children: ... }</code></td>
|
<td><code>class <b>CanActivateChild</b>Guard implements <b>CanActivateChild</b> {
|
||||||
|
canActivateChild(
|
||||||
|
route: ActivatedRouteSnapshot,
|
||||||
|
state: RouterStateSnapshot
|
||||||
|
): Observable<boolean|UrlTree>|Promise<boolean|UrlTree>|boolean|UrlTree { ... }
|
||||||
|
}
|
||||||
|
|
||||||
|
{ path: ..., canActivateChild: [CanActivateGuard],
|
||||||
|
children: ... }
|
||||||
|
</code></td>
|
||||||
<td><p>An interface for defining a class that the router should call first to determine if it should activate the child route. Should return a boolean|UrlTree or an Observable/Promise that resolves to a boolean|UrlTree.</p>
|
<td><p>An interface for defining a class that the router should call first to determine if it should activate the child route. Should return a boolean|UrlTree or an Observable/Promise that resolves to a boolean|UrlTree.</p>
|
||||||
</td>
|
</td>
|
||||||
</tr><tr>
|
</tr><tr>
|
||||||
<td><code>class <b>Resolve</b>Guard implements <b>Resolve</b><T> {<br> resolve(<br>  route: ActivatedRouteSnapshot,<br>  state: RouterStateSnapshot<br> ): Observable<any>|Promise<any>|any { ... }<br>}<br><br>{ path: ..., resolve: [<b>Resolve</b>Guard] }</code></td>
|
<td><code>class <b>Resolve</b>Guard implements <b>Resolve</b><T> {
|
||||||
|
resolve(
|
||||||
|
route: ActivatedRouteSnapshot,
|
||||||
|
state: RouterStateSnapshot
|
||||||
|
): Observable<any>|Promise<any>|any { ... }
|
||||||
|
}
|
||||||
|
|
||||||
|
{ path: ..., resolve: [<b>Resolve</b>Guard] }
|
||||||
|
</code></td>
|
||||||
<td><p>An interface for defining a class that the router should call first to resolve route data before rendering the route. Should return a value or an Observable/Promise that resolves to a value.</p>
|
<td><p>An interface for defining a class that the router should call first to resolve route data before rendering the route. Should return a value or an Observable/Promise that resolves to a value.</p>
|
||||||
</td>
|
</td>
|
||||||
</tr><tr>
|
</tr><tr>
|
||||||
<td><code>class <b>CanLoad</b>Guard implements <b>CanLoad</b> {<br> canLoad(<br>  route: Route<br> ): Observable<boolean|UrlTree>|Promise<boolean|UrlTree>|boolean|UrlTree { ... }<br>}<br><br>{ path: ..., canLoad: [<b>CanLoad</b>Guard], loadChildren: ... }</code></td>
|
<td><code>class <b>CanLoad</b>Guard implements <b>CanLoad</b> {
|
||||||
|
canLoad(
|
||||||
|
route: Route
|
||||||
|
): Observable<boolean|UrlTree>|Promise<boolean|UrlTree>|boolean|UrlTree { ... }
|
||||||
|
}
|
||||||
|
|
||||||
|
{ path: ..., canLoad: [<b>CanLoad</b>Guard], loadChildren: ... }
|
||||||
|
</code></td>
|
||||||
<td><p>An interface for defining a class that the router should call first to check if the lazy loaded module should be loaded. Should return a boolean|UrlTree or an Observable/Promise that resolves to a boolean|UrlTree.</p>
|
<td><p>An interface for defining a class that the router should call first to check if the lazy loaded module should be loaded. Should return a boolean|UrlTree or an Observable/Promise that resolves to a boolean|UrlTree.</p>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
|
@ -182,6 +182,7 @@ aio-code {
|
||||||
code {
|
code {
|
||||||
background-color: inherit;
|
background-color: inherit;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
|
white-space: pre-wrap;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue