.gitignore000066400000000000000000000000331516067322000130440ustar00rootroot00000000000000/.idea /node_modules /build.npmignore000066400000000000000000000001041516067322000130520ustar00rootroot00000000000000/.idea /artifacts /docs /build /Gemfile /_layouts /_site /_includes .travis.yml000066400000000000000000000001331516067322000131660ustar00rootroot00000000000000language: node_js node_js: - "7" - "node" before_script: - npm install grunt-cli -g Gruntfile.js000066400000000000000000000005171516067322000133600ustar00rootroot00000000000000const 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.md000066400000000000000000000020561516067322000124670ustar00rootroot00000000000000MIT 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.md000066400000000000000000000032751516067322000123460ustar00rootroot00000000000000# ng2-compile-html [![Build Status](https://travis-ci.org/patrikx3/ng2-compile-html.svg?branch=master)](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 --save-dev p3x-ng2-compile-html ``` ##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, }) } } ``` ## Run ```bash npm install grunt run ``` [http://localhost:8080](http://localhost:8080)index.ts000066400000000000000000000000271516067322000125360ustar00rootroot00000000000000export * from "./src"; package.json000066400000000000000000000031071516067322000133470ustar00rootroot00000000000000{ "name": "p3x-ng2-compile-html", "version": "1.0.13-14", "version-date": "1/16/2017, 6:11:47 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/000077500000000000000000000000001516067322000116475ustar00rootroot00000000000000src/CompileHtmlAttribute.ts000066400000000000000000000012351516067322000163210ustar00rootroot00000000000000import {Directive, ElementRef, Input, Injectable, ViewContainerRef, OnInit} from '@angular/core'; import { CompileHtmlService } from './CompileHtmlService'; @Directive({ selector: '[p3xCompileHtml]' }) @Injectable() export class CompileHtmlAttribute { @Input('p3xCompileHtml') p3xHtml: string; @Input() p3xCompileHtmlRef: any; ngOnInit() { this.service.compile({ template: this.p3xHtml, container: this.container, ref: this.p3xCompileHtmlRef }) } constructor( private el: ElementRef, private container: ViewContainerRef, private service: CompileHtmlService ) {} }src/CompileHtmlService.ts000066400000000000000000000015631516067322000157620ustar00rootroot00000000000000import { 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.ts000066400000000000000000000003031516067322000175470ustar00rootroot00000000000000import { ViewContainerRef, } from '@angular/core'; export interface CompileHtmlServiceOptions { template: string; container: ViewContainerRef; imports?: any[]; ref?: any } src/index.ts000066400000000000000000000001701516067322000133240ustar00rootroot00000000000000export { CompileHtmlService } from "./CompileHtmlService"; export { CompileHtmlAttribute} from "./CompileHtmlAttribute";test/000077500000000000000000000000001516067322000120375ustar00rootroot00000000000000test/angular2/000077500000000000000000000000001516067322000135525ustar00rootroot00000000000000test/angular2/app/000077500000000000000000000000001516067322000143325ustar00rootroot00000000000000test/angular2/app/Module.ts000066400000000000000000000006641516067322000161350ustar00rootroot00000000000000import { 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.ts000066400000000000000000000017071516067322000155630ustar00rootroot00000000000000import { 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, }) } }test/angular2/index.html000066400000000000000000000003471516067322000155530ustar00rootroot00000000000000 p3x-ng2-compile-html test/angular2/main.ts000066400000000000000000000004271516067322000150510ustar00rootroot00000000000000import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; import { enableProdMode } from '@angular/core'; import {Module} from './app/Module'; if (process.env.ENV === 'production') { enableProdMode(); } platformBrowserDynamic().bootstrapModule(Module); test/angular2/polyfills.ts000066400000000000000000000004041516067322000161350ustar00rootroot00000000000000import 'core-js/es6'; import 'core-js/es7/reflect'; import 'zone.js/dist/zone'; if (process.env.ENV === 'production') { // Production } else { // Development Error['stackTraceLimit'] = Infinity; require('zone.js/dist/long-stack-trace-zone'); }test/angular2/vendor.ts000066400000000000000000000002351516067322000154170ustar00rootroot00000000000000// Angular import '@angular/platform-browser'; import '@angular/platform-browser-dynamic'; import '@angular/core'; import '@angular/common'; import 'rxjs'; tsconfig.json000066400000000000000000000007131516067322000135700ustar00rootroot00000000000000{ "compilerOptions": { "target": "es5", "module": "commonjs", "moduleResolution": "node", "sourceMap": true, "emitDecoratorMetadata": true, "experimentalDecorators": true, "noImplicitAny": true, "suppressImplicitAnyIndexErrors": true, "compilerOptions": { "sourceMap": true }, "lib": [ "es5", "es6", "dom", "es2015.collection", "es2015.promise", "es2015.core" ] } }