Skip to content

Commit

Permalink
fix(deps): Display component providers
Browse files Browse the repository at this point in the history
fix #514
  • Loading branch information
vogloblinsky committed Mar 19, 2018
1 parent b010638 commit 7804509
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 19 deletions.
9 changes: 8 additions & 1 deletion src/app/compiler/deps/component-dep.factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class ComponentDepFactory {
// animations?: string[]; // TODO
changeDetection: this.helper.getComponentChangeDetection(props, srcFile),
encapsulation: this.helper.getComponentEncapsulation(props, srcFile),
// entryComponents?: string; // TODO waiting doc infos
entryComponents: this.helper.getComponentEntryComponents(props, srcFile),
exportAs: this.helper.getComponentExportAs(props, srcFile),
host: this.helper.getComponentHost(props),
inputs: this.helper.getComponentInputsMetadata(props, srcFile),
Expand Down Expand Up @@ -49,6 +49,9 @@ export class ComponentDepFactory {
sourceCode: srcFile.getText(),
exampleUrls: this.helper.getComponentExampleUrls(srcFile.getText())
};
if (typeof this.helper.getComponentPreserveWhitespaces(props, srcFile) !== 'undefined') {
componentDep.preserveWhitespaces = this.helper.getComponentPreserveWhitespaces(props, srcFile);
}
if (this.configuration.mainData.disableLifeCycleHooks) {
componentDep.methodsClass = cleanLifecycleHooksFromMethods(componentDep.methodsClass);
}
Expand Down Expand Up @@ -93,6 +96,8 @@ export interface IComponentDep extends IDep {
propertiesClass: Array<any>;
methodsClass: Array<any>;

entryComponents: Array<any>;

hostBindings: Array<any>;
hostListeners: Array<any>;

Expand All @@ -105,4 +110,6 @@ export interface IComponentDep extends IDep {
extends?: any;
implements?: any;
accessors?: Object;

preserveWhitespaces?: any;
}
10 changes: 10 additions & 0 deletions src/app/compiler/deps/helpers/component-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ export class ComponentHelper {
.map((name) => this.symbolHelper.parseDeepIndentifier(name));
}

public getComponentEntryComponents(props: ReadonlyArray<ts.ObjectLiteralElementLike>, srcFile: ts.SourceFile): Array<IParseDeepIdentifierResult> {
return this.symbolHelper
.getSymbolDeps(props, 'entryComponents', srcFile)
.map((name) => this.symbolHelper.parseDeepIndentifier(name));
}

public getComponentViewProviders(props: ReadonlyArray<ts.ObjectLiteralElementLike>, srcFile: ts.SourceFile): Array<IParseDeepIdentifierResult> {
return this.symbolHelper
.getSymbolDeps(props, 'viewProviders', srcFile)
Expand All @@ -93,6 +99,10 @@ export class ComponentHelper {
return exampleUrls;
}

public getComponentPreserveWhitespaces(props: ReadonlyArray<ts.ObjectLiteralElementLike>, srcFile: ts.SourceFile): string {
return this.symbolHelper.getSymbolDeps(props, 'preserveWhitespaces', srcFile).pop();
}

public getComponentSelector(props: ReadonlyArray<ts.ObjectLiteralElementLike>, srcFile: ts.SourceFile): string {
return this.symbolHelper.getSymbolDeps(props, 'selector', srcFile).pop();
}
Expand Down
11 changes: 11 additions & 0 deletions src/app/engines/html-engine-helpers/has-own.helper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { IHtmlEngineHelper, IHandlebarsOptions } from './html-engine-helper.interface';

export class HasOwnHelper implements IHtmlEngineHelper {
public helperFunc(context: any, entity, key: any, options: IHandlebarsOptions): string {
if (Object.hasOwnProperty.call(entity, key)) {
return options.fn(context);
} else {
return options.inverse(context);
}
}
}
2 changes: 2 additions & 0 deletions src/app/engines/html.engine.helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import { ParseDescriptionHelper } from './html-engine-helpers/parse-description.
import { OneParameterHasHelper } from './html-engine-helpers/one-parameter-has.helper';
import { ConfigurationInterface } from '../interfaces/configuration.interface';
import { ElementAloneHelper } from './html-engine-helpers/element-alone.helper';
import { HasOwnHelper } from './html-engine-helpers/has-own.helper';

export class HtmlEngineHelpers {
public registerHelpers(
Expand Down Expand Up @@ -68,6 +69,7 @@ export class HtmlEngineHelpers {
this.registerHelper(bars, 'parseDescription', new ParseDescriptionHelper(dependenciesEngine));
this.registerHelper(bars, 'one-parameter-has', new OneParameterHasHelper());
this.registerHelper(bars, 'element-alone', new ElementAloneHelper(dependenciesEngine));
this.registerHelper(bars, 'hasOwn', new HasOwnHelper());
}

private registerHelper(bars, key: string, helper: IHtmlEngineHelper) {
Expand Down
29 changes: 12 additions & 17 deletions src/templates/partials/component-detail.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,11 @@
{{#if component.entryComponents}}
<tr>
<td class="col-md-3">entryComponents</td>
<td class="col-md-9"><code>{{component.entryComponents}}</code></td>
<td class="col-md-9">
{{#each component.entryComponents}}
{{> link-type type=name }}
{{/each}}
</td>
</tr>
{{/if}}

Expand All @@ -95,16 +99,9 @@
</tr>
{{/if}}

{{#if component.inputs}}
<tr>
<td class="col-md-3">inputs</td>
<td class="col-md-9"><code>{{breakComma component.inputs}}</code></td>
</tr>
{{/if}}

{{#if component.interpolation}}
<tr>
<td class="col-md-3">host</td>
<td class="col-md-3">interpolation</td>
<td class="col-md-9"><code>{{component.interpolation}}</code></td>
</tr>
{{/if}}
Expand All @@ -116,22 +113,20 @@
</tr>
{{/if}}

{{#if component.outputs}}
{{#hasOwn component 'preserveWhitespaces'}}
<tr>
<td class="col-md-3">outputs</td>
<td class="col-md-9"><code>{{breakComma component.outputs}}</code></td>
<td class="col-md-3">preserveWhitespaces</td>
<td class="col-md-9"><code>{{component.preserveWhitespaces}}</code></td>
</tr>
{{/if}}
{{/hasOwn}}

{{#if component.providers}}
<tr>
<td class="col-md-3">providers</td>
<td class="col-md-9">
<code>
{{#each component.providers}}
{{name}}
{{> link-type type=name }}
{{/each}}
</code>
</td>
</tr>
{{/if}}
Expand Down Expand Up @@ -184,7 +179,7 @@
<td class="col-md-9">
<code>
{{#each component.viewProviders}}
{{name}}
{{> link-type type=name }}
{{/each}}
</code>
</td>
Expand Down
15 changes: 15 additions & 0 deletions test/src/cli/cli-generation-big-app.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -586,4 +586,19 @@ describe('CLI simple generation - big app', () => {
expect(file).to.contain('<a href="./injectables/EmitterService.html" >EmitterService</a>');
expect(file).to.contain('<a href="./pipes/FirstUpperPipe2.html" >FirstUpperPipe2</a>');
});

it('should support component metadata preserveWhiteSpaces', () => {
let file = read(distFolder + '/components/AboutComponent.html');
expect(file).to.contain('<td class="col-md-3">preserveWhitespaces</td>');
});

it('should support component metadata entryComponents', () => {
let file = read(distFolder + '/components/AboutComponent.html');
expect(file).to.contain('<code><a href="../classes/Todo.html" target="_self" >TodoComponent</a></code>');
});

it('should support component metadata providers', () => {
let file = read(distFolder + '/components/AboutComponent.html');
expect(file).to.contain('<code><a href="../injectables/EmitterService.html" target="_self" >EmitterService</a></code>');
});
});
5 changes: 4 additions & 1 deletion test/src/todomvc-ng2/src/app/about/about.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ import { Subscription } from 'rxjs/Subscription';
*/
@Component({
selector: 'about',
templateUrl: './about.component.html'
templateUrl: './about.component.html',
providers: [EmitterService],
entryComponents: [TodoComponent, ListComponent],
preserveWhitespaces: false
})
export class AboutComponent {

Expand Down

0 comments on commit 7804509

Please sign in to comment.