Skip to content

Commit

Permalink
feat(template): add parentheses () wrapper for name when kind is Output
Browse files Browse the repository at this point in the history
  • Loading branch information
why520crazy committed Sep 5, 2022
1 parent 365f323 commit d91143d
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/template/ng-package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"src/assets/styles"
]
},
"whitelistedNonPeerDependencies": [
"allowedNonPeerDependencies": [
"docsearch.js"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ <h1 class="name" id="{{ apiDeclaration.name }}">{{ apiDeclaration.name }}</h1>
<tbody>
<tr class="dg-api-properties-row" *ngFor="let property of apiDeclaration.properties">
<td class="dg-api-properties-name-cell">
<label><span *ngIf="property.kind | dgIsContentChildKind">#</span>{{ property.aliasName || property.name }}</label>
<label>{{ property | dgPropertyName }}</label>
</td>
<td class="dg-api-properties-type-cell">
<label class="">{{ property.type.name || property.type }}</label>
Expand Down
79 changes: 79 additions & 0 deletions packages/template/src/shared/pipes/property-name.pipe.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import { PropertyNamePipe } from './property-name.pipe';

describe('property-name', () => {
it('should get property name for Input', () => {
const result = new PropertyNamePipe().transform({
kind: 'Input',
name: 'thyType',
type: 'string'
});
expect(result).toEqual('thyType');
});

it('should get property name with alias name for Input', () => {
const result = new PropertyNamePipe().transform({
kind: 'Input',
name: 'thyType',
type: 'string',
aliasName: 'thyTypeAlias'
});
expect(result).toEqual('thyTypeAlias');
});

it('should get property name for Output', () => {
const result = new PropertyNamePipe().transform({
kind: 'Output',
name: 'thyChange',
type: 'EventEmitter<boolean>'
});
expect(result).toEqual('(thyChange)');
});

it('should get property name with alias name for Output', () => {
const result = new PropertyNamePipe().transform({
kind: 'Output',
name: 'thyChange',
aliasName: 'thyChangeAlias',
type: 'EventEmitter<boolean>'
});
expect(result).toEqual('(thyChangeAlias)');
});

it('should get property name for ContentChild', () => {
const result = new PropertyNamePipe().transform({
kind: 'ContentChild',
name: 'header',
type: 'TemplateRef<unknown>'
});
expect(result).toEqual('#header');
});

it('should get property name with alias name for ContentChild', () => {
const result = new PropertyNamePipe().transform({
kind: 'ContentChild',
name: 'header',
aliasName: 'headerAlias',
type: 'TemplateRef<unknown>'
});
expect(result).toEqual('#headerAlias');
});

it('should get property name for ContentChildren', () => {
const result = new PropertyNamePipe().transform({
kind: 'ContentChildren',
name: 'header',
type: 'TemplateRef<unknown>'
});
expect(result).toEqual('#header');
});

it('should get property name with alias name for ContentChildren', () => {
const result = new PropertyNamePipe().transform({
kind: 'ContentChildren',
name: 'header',
aliasName: 'headerAlias',
type: 'TemplateRef<unknown>'
});
expect(result).toEqual('#headerAlias');
});
});
22 changes: 22 additions & 0 deletions packages/template/src/shared/pipes/property-name.pipe.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { NavigationItem } from './../../interfaces/navigation-item';
import { Pipe, PipeTransform } from '@angular/core';
import { PropertyDeclaration } from '../../interfaces';
import { IsNgContentChildKindPipe } from './ng-kind.pipe';

@Pipe({ name: 'dgPropertyName' })
export class PropertyNamePipe implements PipeTransform {
constructor() {}

transform(property: PropertyDeclaration): string {
const ngContentChildKind = new IsNgContentChildKindPipe();
const isContentChild = ngContentChildKind.transform(property.kind);
const name = property.aliasName || property.name;
if (isContentChild) {
return `#${name}`;
} else if (property.kind === 'Output') {
return `(${name})`;
} else {
return `${name}`;
}
}
}
2 changes: 2 additions & 0 deletions packages/template/src/shared/shared.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { DocPagesLinksComponent } from './doc-pages-links/doc-pages-links.compon
import { SearchComponent } from './search/search.component';
import { HighlightPipe } from './pipes/highlight.pipe';
import { IsNgContentChildKindPipe } from './pipes/ng-kind.pipe';
import { PropertyNamePipe } from './pipes/property-name.pipe';

const COMPONENTS = [
NavbarComponent,
Expand All @@ -47,6 +48,7 @@ const COMPONENTS = [
CopyComponent,
IsComponentDocPipe,
IsNgContentChildKindPipe,
PropertyNamePipe,
TranslatePipe,
IsModeLitePipe,
IsModeFullPipe,
Expand Down
1 change: 1 addition & 0 deletions packages/template/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"target": "es2015",
"declaration": true,
"inlineSources": true,
"strict": true,
"types": [],
"lib": [
"dom",
Expand Down

0 comments on commit d91143d

Please sign in to comment.