.gitignore000066400000000000000000000000331516101661300130420ustar00rootroot00000000000000/.idea /node_modules /build.npmignore000066400000000000000000000001041516101661300130500ustar00rootroot00000000000000/.idea /artifacts /docs /build /Gemfile /_layouts /_site /_includes .scrutinizer.yml000066400000000000000000000005201516101661300142350ustar00rootroot00000000000000checks: javascript: true filter: excluded_paths: - node_modules/* build: environment: node: 7 dependencies: before: - npm install grunt-cli -g - npm install tests: override: - command: 'grunt' coverage: file: 'build/coverage/clover.xml' format: 'clover'.travis.yml000066400000000000000000000001331516101661300131640ustar00rootroot00000000000000language: node_js node_js: - "7" - "node" before_script: - npm install grunt-cli -g Gruntfile.js000066400000000000000000000006401516101661300133530ustar00rootroot00000000000000const 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.concat(['karma:angular2'])); grunt.registerTask('test', 'karma:angular2Run'); }LICENSE.md000066400000000000000000000020561516101661300124650ustar00rootroot00000000000000MIT 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.md000066400000000000000000000020501516101661300123320ustar00rootroot00000000000000# ng2-compile-html [![Build Status](https://travis-ci.org/patrikx3/ng2-compile-html.svg?branch=master)](https://travis-ci.org/patrikx3/ng2-compile-html) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/patrikx3/ng2-compile-html/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/patrikx3/ng2-compile-html/?branch=master) Angular 2 Service/Attribute to compile an HTML into a component It is only using ```TypeScript``` right now. It can be built though. Right now, only ```zone.js@0.7.2``` show errors right. Probably 0.7.6 will be good. ##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 ###HTML ```html
``` ###TypeScript Check out the example, here [test/angular2/app/Page.ts](test/angular2/app/Page.ts). by [Patrik Laszlo](http://patrikx3.tk) index.ts000066400000000000000000000000271516101661300125340ustar00rootroot00000000000000export * from "./src"; package.json000066400000000000000000000037101516101661300133450ustar00rootroot00000000000000{ "name": "p3x-ng2-compile-html", "version": "1.0.58-31", "version-date": "1/18/2017, 3:21:45 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/jasmine": "^2.5.40", "@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": "1.0.100-31", "extract-text-webpack-plugin": "^1.0.1", "grunt-karma": "^2.0.0", "grunt-webpack": "^1.0.18", "html-loader": "^0.4.4", "html-webpack-plugin": "^2.26.0", "istanbul-instrumenter-loader": "^1.2.0", "karma": "^1.4.0", "karma-coverage": "^1.1.1", "karma-jasmine": "^1.1.0", "karma-phantomjs-launcher": "^1.0.2", "karma-sourcemap-loader": "^0.3.7", "karma-webpack": "^2.0.1", "node-sass-css-importer": "0.0.3", "phantomjs-prebuilt": "^2.1.14", "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/000077500000000000000000000000001516101661300116455ustar00rootroot00000000000000src/CompileHtmlAttribute.ts000066400000000000000000000015711516101661300163220ustar00rootroot00000000000000import {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; @Input() p3xCompileHtmlImports: any[]; update() { this.service.compile({ template: this.p3xHtml, container: this.container, ref: this.p3xCompileHtmlRef, imports: this.p3xCompileHtmlImports }) } ngOnInit() { this.update(); } ngOnChanges(changes: SimpleChanges) { this.update(); } constructor( private container: ViewContainerRef, private service: CompileHtmlService ) {} }src/CompileHtmlService.ts000066400000000000000000000016301516101661300157530ustar00rootroot00000000000000import { Component, Compiler, NgModule, Injectable } from '@angular/core'; import {CompileHtmlServiceOptions} from "../typings/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/index.ts000066400000000000000000000001701516101661300133220ustar00rootroot00000000000000export { CompileHtmlService } from "./CompileHtmlService"; export { CompileHtmlAttribute} from "./CompileHtmlAttribute";test/000077500000000000000000000000001516101661300120355ustar00rootroot00000000000000test/angular2/000077500000000000000000000000001516101661300135505ustar00rootroot00000000000000test/angular2/app/000077500000000000000000000000001516101661300143305ustar00rootroot00000000000000test/angular2/app/Module.ts000066400000000000000000000006641516101661300161330ustar00rootroot00000000000000import { 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.ts000066400000000000000000000024741516101661300155630ustar00rootroot00000000000000import { Component, Injectable, ViewChild, ViewContainerRef, OnInit } from '@angular/core'; import {CompileHtmlService } from '../../../src'; @Component({ selector: 'p3x-ng2-compile-html-test', 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 an attribute!
${this.counter2}
`; } ngOnInit() { this.update1(); this.update2(); } }test/angular2/index.html000066400000000000000000000003471516101661300155510ustar00rootroot00000000000000 p3x-ng2-compile-html test/angular2/main.ts000066400000000000000000000004271516101661300150470ustar00rootroot00000000000000import { 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.ts000066400000000000000000000004041516101661300161330ustar00rootroot00000000000000import '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.ts000066400000000000000000000002351516101661300154150ustar00rootroot00000000000000// Angular import '@angular/platform-browser'; import '@angular/platform-browser-dynamic'; import '@angular/core'; import '@angular/common'; import 'rxjs'; test/angular2Karma/000077500000000000000000000000001516101661300145245ustar00rootroot00000000000000test/angular2Karma/CompileHtmlService.ts000066400000000000000000000015131516101661300206320ustar00rootroot00000000000000import { TestBed } from '@angular/core/testing'; import { inject } from '@angular/core/testing'; import {CompileHtmlAttribute, CompileHtmlService } from '../../src' describe('CompileHtml', () => { let service: CompileHtmlService; beforeEach(() => { TestBed.configureTestingModule({ declarations: [ CompileHtmlAttribute ], providers: [ CompileHtmlService ], }); }); beforeEach(inject([CompileHtmlService], (_service: CompileHtmlService) => { service = _service; })); it ('CompileHtmlService', (/*done*/) => { expect(service instanceof CompileHtmlService).toBeTruthy(); /* setTimeout(()=> { console.log('done later'); done(); }, 2000); */ }); });tsconfig.json000066400000000000000000000007131516101661300135660ustar00rootroot00000000000000{ "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" ] } }typings/000077500000000000000000000000001516101661300125535ustar00rootroot00000000000000typings/CompileHtmlServiceOptions.d.ts000066400000000000000000000003031516101661300204530ustar00rootroot00000000000000import { ViewContainerRef, } from '@angular/core'; export interface CompileHtmlServiceOptions { template: string; container: ViewContainerRef; imports?: any[]; ref?: any }