.gitignore 0000664 0000000 0000000 00000000033 15160707535 0013053 0 ustar 00root root 0000000 0000000 /.idea
/node_modules
/build .npmignore 0000664 0000000 0000000 00000000104 15160707535 0013061 0 ustar 00root root 0000000 0000000 /.idea
/artifacts
/docs
/build
/Gemfile
/_layouts
/_site
/_includes
.travis.yml 0000664 0000000 0000000 00000000133 15160707535 0013175 0 ustar 00root root 0000000 0000000 language: node_js
node_js:
- "7"
- "node"
before_script:
- npm install grunt-cli -g
Gruntfile.js 0000664 0000000 0000000 00000000517 15160707535 0013367 0 ustar 00root root 0000000 0000000 const builder = require('corifeus-core-builder');
module.exports = (grunt) => {
const loader = new builder.Loader(grunt);
loader.angular2(builder.config.folder.test.angular2.root);
grunt.registerTask('run', builder.config.task.continuous.angular2);
grunt.registerTask('default', builder.config.task.build.angular2);
} LICENSE.md 0000664 0000000 0000000 00000002056 15160707535 0012476 0 ustar 00root root 0000000 0000000 MIT License
Copyright (c) 2017 Patrik Laszlo
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
README.md 0000664 0000000 0000000 00000003466 15160707535 0012357 0 ustar 00root root 0000000 0000000 # ng2-compile-html
[](https://travis-ci.org/patrikx3/ng2-compile-html)
Angular 2 Service to compile an HTML into a component
It is only using ```TypeScript``` right now. It can be built though.
##Install
```bash
npm install p3x-ng2-compile-html
```
##Test
```bash
git clone https://github.com/patrikx3/ng2-compile-html.git
cd ng2-compile-html
npm install
grunt run
```
[http://localhost:8080](http://localhost:8080)
##Usage
Check out the example, here [test/angular2/app/Page.ts](test/angular2/app/Page.ts).
###HTML
```html
loading ...
loading ...
```
###TypeScript
```typescript
import {
Component,
Injectable,
ViewChild,
ViewContainerRef,
OnInit
} from '@angular/core';
import {CompileHtmlService } from '../../../src';
@Component({
selector: 'p3x-ng2-compile-html-text',
template: `
loading ...
loading ...
`,
})
@Injectable()
export class Page implements OnInit {
@ViewChild('container', {read: ViewContainerRef}) container: ViewContainerRef;
data: string = `
Done
If click works it says OK!
`;
ref: Page;
constructor( private compileHtmlService: CompileHtmlService ) {
this.ref = this;
}
alert(string: string ) {
alert(string);
}
ngOnInit() {
this.compileHtmlService.compile({
template: this.data,
container: this.container,
ref: this,
})
}
}
```
by [Patrik Laszlo](http://patrikx3.tk) _config.yml 0000664 0000000 0000000 00000000035 15160707535 0013214 0 ustar 00root root 0000000 0000000 theme: jekyll-theme-architect index.ts 0000664 0000000 0000000 00000000027 15160707535 0012545 0 ustar 00root root 0000000 0000000 export * from "./src";
package.json 0000664 0000000 0000000 00000003107 15160707535 0013356 0 ustar 00root root 0000000 0000000 {
"name": "p3x-ng2-compile-html",
"version": "1.0.35-18",
"version-date": "1/16/2017, 8:53:13 PM",
"description": "Angular 2 Service to compile an HTML into a component Edit",
"main": "src/index.ts",
"scripts": {
"test": "grunt"
},
"repository": {
"type": "git",
"url": "git+https://github.com/patrikx3/ng2-compile-html.git"
},
"keywords": [
"p3x",
"angular2",
"ng2",
"compile",
"html"
],
"author": "Patrik Laszlo ",
"license": "MIT",
"bugs": {
"url": "https://github.com/patrikx3/ng2-compile-html/issues"
},
"homepage": "https://github.com/patrikx3/ng2-compile-html#readme",
"devDependencies": {
"@angular/common": "^2.4.3",
"@angular/compiler": "^2.4.3",
"@angular/platform-browser": "^2.4.3",
"@angular/platform-browser-dynamic": "^2.4.3",
"@types/node": "^7.0.0",
"angular2-template-loader": "^0.6.0",
"awesome-typescript-loader": "^3.0.0-beta.18",
"core-js": "^2.4.1",
"corifeus-core-builder": "0.0.92-17",
"extract-text-webpack-plugin": "^1.0.1",
"grunt-webpack": "^1.0.18",
"html-loader": "^0.4.4",
"html-webpack-plugin": "^2.26.0",
"node-sass-css-importer": "0.0.3",
"webpack": "^1.14.0",
"webpack-dev-server": "^1.16.2",
"webpack-merge": "^2.4.0"
},
"dependencies": {
"@angular/core": "^2.4.3",
"rxjs": "^5.0.3",
"zone.js": "0.7.2",
"typescript": "^2.1.5"
}
} src/ 0000775 0000000 0000000 00000000000 15160707535 0011656 5 ustar 00root root 0000000 0000000 src/CompileHtmlAttribute.ts 0000664 0000000 0000000 00000001434 15160707535 0016331 0 ustar 00root root 0000000 0000000 import {Directive, Input, Injectable, ViewContainerRef, OnInit, OnChanges, SimpleChanges} from '@angular/core';
import { CompileHtmlService } from './CompileHtmlService';
@Directive({ selector: '[p3xCompileHtml]' })
@Injectable()
export class CompileHtmlAttribute implements OnInit, OnChanges{
@Input('p3xCompileHtml') p3xHtml: string;
@Input() p3xCompileHtmlRef: any;
update() {
this.service.compile({
template: this.p3xHtml,
container: this.container,
ref: this.p3xCompileHtmlRef
})
}
ngOnInit() {
this.update();
}
ngOnChanges(changes: SimpleChanges) {
this.update();
}
constructor(
private container: ViewContainerRef,
private service: CompileHtmlService
) {}
} src/CompileHtmlService.ts 0000664 0000000 0000000 00000001563 15160707535 0015771 0 ustar 00root root 0000000 0000000 import {
Component,
Compiler, NgModule,
Injectable
} from '@angular/core';
import {CompileHtmlServiceOptions} from "./CompileHtmlServiceOptions";
@Injectable()
export class CompileHtmlService {
constructor(private compiler: Compiler) {}
public compile(opts: CompileHtmlServiceOptions) {
@Component({template: opts.template})
class TemplateComponent {
ref = opts.ref;
}
@NgModule({
imports: opts.imports,
declarations: [TemplateComponent]
})
class TemplateModule {}
const compiled = this.compiler.compileModuleAndAllComponentsSync(TemplateModule);
const factory = compiled.componentFactories.find((comp) =>
comp.componentType === TemplateComponent
);
opts.container.clear();
opts.container.createComponent(factory);
}
} src/CompileHtmlServiceOptions.d.ts 0000664 0000000 0000000 00000000303 15160707535 0017556 0 ustar 00root root 0000000 0000000 import {
ViewContainerRef,
} from '@angular/core';
export interface CompileHtmlServiceOptions {
template: string;
container: ViewContainerRef;
imports?: any[];
ref?: any
}
src/index.ts 0000664 0000000 0000000 00000000170 15160707535 0013333 0 ustar 00root root 0000000 0000000 export { CompileHtmlService } from "./CompileHtmlService";
export { CompileHtmlAttribute} from "./CompileHtmlAttribute"; test/ 0000775 0000000 0000000 00000000000 15160707535 0012046 5 ustar 00root root 0000000 0000000 test/angular2/ 0000775 0000000 0000000 00000000000 15160707535 0013561 5 ustar 00root root 0000000 0000000 test/angular2/app/ 0000775 0000000 0000000 00000000000 15160707535 0014341 5 ustar 00root root 0000000 0000000 test/angular2/app/Module.ts 0000664 0000000 0000000 00000000664 15160707535 0016144 0 ustar 00root root 0000000 0000000 import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import {Page } from './Page';
import {CompileHtmlService, CompileHtmlAttribute} from '../../../src';
@NgModule({
imports: [
BrowserModule,
],
declarations: [
Page,
CompileHtmlAttribute
],
providers: [
CompileHtmlService
],
bootstrap: [ Page ]
})
export class Module { };
test/angular2/app/Page.ts 0000664 0000000 0000000 00000002471 15160707535 0015571 0 ustar 00root root 0000000 0000000 import {
Component,
Injectable,
ViewChild,
ViewContainerRef,
OnInit
} from '@angular/core';
import {CompileHtmlService } from '../../../src';
@Component({
selector: 'p3x-ng2-compile-html-text',
template: `
`,
})
@Injectable()
export class Page implements OnInit {
@ViewChild('container', {read: ViewContainerRef}) container: ViewContainerRef;
data1: string;
data2: string;
ref: Page;
counter1 : number = 0;
counter2 : number = 0;
constructor( private compileHtmlService: CompileHtmlService ) {
this.ref = this;
}
private update1() {
this.counter1++;
this.data1 = `
Service
Click me via a service!
${this.counter1}
`;
this.compileHtmlService.compile({
template: this.data1,
container: this.container,
ref: this,
})
}
private update2() {
this.counter2++;
this.data2 = `
Attribute
Click me via a service!
${this.counter2}
`;
}
ngOnInit() {
this.update1();
this.update2();
}
} test/angular2/index.html 0000664 0000000 0000000 00000000347 15160707535 0015562 0 ustar 00root root 0000000 0000000
p3x-ng2-compile-html