-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(template): support open isolated example #OSP-162
- Loading branch information
1 parent
9b5ded4
commit a700170
Showing
13 changed files
with
148 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
--- | ||
title: Docgeni - 为 Angular 组件开发场景而生的文档工具 | ||
title: 首页 | ||
order: 10 | ||
hero: | ||
title: Docgeni | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<dg-example-renderer [name]="name"></dg-example-renderer> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Component, OnInit } from '@angular/core'; | ||
import { ActivatedRoute } from '@angular/router'; | ||
import { PageTitleService } from '../../services/page-title.service'; | ||
|
||
@Component({ | ||
selector: 'dg-example-isolated-viewer', | ||
templateUrl: './example.component.html' | ||
}) | ||
export class ExampleIsolatedViewerComponent implements OnInit { | ||
public name: string; | ||
|
||
constructor(private route: ActivatedRoute, private pageTitle: PageTitleService) {} | ||
|
||
ngOnInit(): void { | ||
this.name = this.route.snapshot.paramMap.get('name'); | ||
this.pageTitle.title = `Example - ${this.name}`; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
packages/template/src/shared/example-renderer/example-renderer.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<ng-template | ||
*ngIf="enableIvy && componentType && exampleModuleFactory" | ||
[ngComponentOutlet]="componentType" | ||
[ngComponentOutletNgModuleFactory]="exampleModuleFactory" | ||
></ng-template> | ||
<ng-template *ngIf="!enableIvy && componentType" [ngComponentOutlet]="componentType"></ng-template> |
44 changes: 44 additions & 0 deletions
44
packages/template/src/shared/example-renderer/example-renderer.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { Component, EventEmitter, Input, NgModuleFactory, OnInit, Output, Type, ɵNgModuleFactory } from '@angular/core'; | ||
import { LiveExample } from '../../interfaces/example'; | ||
import { ExampleLoader, ExampleLoadResult } from '../../services/example-loader'; | ||
|
||
@Component({ | ||
selector: 'dg-example-renderer, [dgExampleRenderer]', | ||
templateUrl: './example-renderer.component.html' | ||
}) | ||
export class ExampleRendererComponent implements OnInit { | ||
/** Component type for the current example. */ | ||
componentType: Type<any> | null = null; | ||
|
||
exampleModuleFactory: NgModuleFactory<any> | null = null; | ||
|
||
@Input() set name(name: string) { | ||
this.load(name); | ||
} | ||
|
||
@Input() set exampleModuleType(type: Type<any>) { | ||
this.exampleModuleFactory = new ɵNgModuleFactory(type); | ||
} | ||
|
||
@Input() set exampleComponentType(type: Type<any>) { | ||
this.componentType = type; | ||
} | ||
|
||
@Output() exampleLoadSuccess = new EventEmitter<LiveExample>(); | ||
|
||
get enableIvy() { | ||
return this.exampleLoader.enableIvy; | ||
} | ||
|
||
constructor(private exampleLoader: ExampleLoader) {} | ||
|
||
ngOnInit(): void {} | ||
|
||
load(name: string) { | ||
this.exampleLoader.load(name).then(result => { | ||
this.exampleModuleFactory = new ɵNgModuleFactory(result.moduleType); | ||
this.componentType = result.componentType; | ||
this.exampleLoadSuccess.emit(result.example); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters