Skip to content

Commit

Permalink
feat(host): allow to override generated template
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Malkevich committed Jan 9, 2019
1 parent 52aa96d commit 1898eee
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
24 changes: 15 additions & 9 deletions projects/ngx-testing/src/lib/host-generator.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,13 @@ export class HostGeneratorService {
genForComponent<T>(compType: Type<T>): Type<AsHostComponent<T>> {
const factory = this.cfr.resolveComponentFactory(compType);
const selector = `host-${factory.selector}`;
const template = genHostCompTpl(
factory.selector,
factory,
this.extraConfig.projectContent,
);
const template =
this.extraConfig.template ||
genHostCompTpl(
factory.selector,
factory,
this.extraConfig.projectContent,
);

return this.genComponent({ selector, template }, compType, factory);
}
Expand All @@ -92,14 +94,18 @@ export class HostGeneratorService {
const io = getDirectiveIO(dirType);

const selector = `host-directive`;
const templateTag = this.extraConfig.hostComponent

const templateTag = this.extraConfig.template
? ''
: this.extraConfig.hostComponent
? this.cfr.resolveComponentFactory(this.extraConfig.hostComponent)
.selector
: this.extraConfig.hostTag;

const template = templateTag
? this.genDirectiveTemplate(templateTag, io)
: '';
const template =
this.extraConfig.template || templateTag
? this.genDirectiveTemplate(templateTag, io)
: '';

return this.genComponent({ selector, template }, dirType, io);
}
Expand Down
1 change: 1 addition & 0 deletions projects/ngx-testing/src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
import { OutputMock } from './output-mock';

export interface TestingModuleExtras {
template?: string;
projectContent?: string;
}

Expand Down

0 comments on commit 1898eee

Please sign in to comment.