.gitignore000066400000000000000000000000251516075046000130470ustar00rootroot00000000000000/node_modules /build .npmignore000066400000000000000000000002151516075046000130570ustar00rootroot00000000000000/.idea /artifacts /build /Gemfile /_layouts /_site /_includes /test /node_modules *.iml *.ipr *.iws .travis.yml .scrutinizer.yml Gruntfile.js.scrutinizer.yml000066400000000000000000000006421516075046000142460ustar00rootroot00000000000000checks: javascript: true filter: excluded_paths: - node_modules/* build: environment: node: 7 dependencies: before: - npm install grunt-cli -g - npm install - node_modules/protractor/bin/webdriver-manager update tests: override: - command: 'grunt karma:cory-angular2' coverage: file: 'build/coverage/clover.xml' format: 'clover' .travis.yml000066400000000000000000000005751516075046000132020ustar00rootroot00000000000000sudo: required dist: trusty addons: apt: sources: - google-chrome packages: - google-chrome-stable language: node_js node_js: - "7" - "node" before_script: - "export DISPLAY=:99.0" - "sh -e /etc/init.d/xvfb start" - sleep 3 # give xvfb some time to start - npm install grunt-cli -g - npm install - ./node_modules/.bin/webdriver-manager update Gruntfile.js000066400000000000000000000032021516075046000133540ustar00rootroot00000000000000const builder = require('corifeus-builder'); module.exports = (grunt) => { //node_modules\.bin\webdriver-manager update const loader = new builder.Loader(grunt); loader.angular2(builder.config.folder.test.angular2Webpack.root); grunt.config.set('cory-replace', { header: { header: true, replace: ` [![Build Status](https://travis-ci.org/patrikx3/\${git.repo}.svg?branch=master)](https://travis-ci.org/patrikx3/\${git.repo}) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/patrikx3/\${git.repo}/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/patrikx3/\${git.repo}/?branch=master) [![Code Coverage](https://scrutinizer-ci.com/g/patrikx3/\${git.repo}/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/patrikx3/\${git.repo}/?branch=master) [![Trello](https://img.shields.io/badge/Trello-p3x-026aa7.svg)](https://trello.com/b/gqKHzZGy/p3x) [![NPM](https://nodei.co/npm/\${pkg.name}.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/\${pkg.name}/) `, files: [ 'artifacts/**/*.md', '*.md' ] }, footer: { footer: true, replace: ` [by Patrik Laszlo](http://patrikx3.tk) \${pkg.name} v\${pkg.version} on \${pkg.corifeus.time } `, files: [ 'artifacts/**/*.md', '*.md' ] } }) grunt.registerTask('run', builder.config.task.run.angular2); grunt.registerTask('default', builder.config.task.build.angular2); //cori-test:angular2-protractor // cori-test:angular2-karma }LICENSE000066400000000000000000000021351516075046000120700ustar00rootroot00000000000000MIT License Copyright (c) 2017 Patrik Laszlo Corifeus http://patrikx3.tk 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.md000066400000000000000000000034211516075046000123410ustar00rootroot00000000000000[//]: #@corifeus-header [![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) [![Code Coverage](https://scrutinizer-ci.com/g/patrikx3/ng2-compile-html/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/patrikx3/ng2-compile-html/?branch=master) [![Trello](https://img.shields.io/badge/Trello-p3x-026aa7.svg)](https://trello.com/b/gqKHzZGy/p3x) [![NPM](https://nodei.co/npm/p3x-ng2-compile-html.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/p3x-ng2-compile-html/) [//]: #corifeus-header:end ##Compile an HTML Angular 2 Service/Attribute to into a component/HTML It is only using ```TypeScript``` right now. It can be built though. ##Install ```bash npm install p3x-ng2-compile-html ``` ## Dev environment end test ```bash git clone https://github.com/patrikx3/ng2-compile-html.git cd ng2-compile-html npm install node_modules/.bin/webdriver-manager update grunt default|run ``` [http://localhost:8080](http://localhost:8080) ##Usage ###HTML ```html
``` ###TypeScript Check out the example, here [test/angular2/app/Page.ts](test/angular2-webpack/app/Page.ts). ###Info Angular 2 tries to camelCase all attributes, for me it is still HTML, so my selectors always ```kebab-case```. [//]: #@corifeus-footer [by Patrik Laszlo](http://patrikx3.tk) p3x-ng2-compile-html v1.1.113-149 on 2/26/2017, 1:41:33 AM [//]: #@corifeus-footer:end _config.yml000066400000000000000000000000341516075046000132060ustar00rootroot00000000000000theme: jekyll-theme-midnightindex.ts000066400000000000000000000000271516075046000125400ustar00rootroot00000000000000export * from "./src"; ng2-compile-html.iml000066400000000000000000000017061516075046000146470ustar00rootroot00000000000000 ng2-compile-html.ipr000066400000000000000000000025761516075046000146660ustar00rootroot00000000000000 1.8 package.json000066400000000000000000000044201516075046000133500ustar00rootroot00000000000000{ "name": "p3x-ng2-compile-html", "version": "1.1.113-149", "corifeus": { "prefix": "p3x-", "time": "2/26/2017, 1:41:33 AM" }, "description": "Compile an HTML Angular 2 Service/Attribute to into a component/HTML", "main": "src/index.ts", "scripts": { "test": "grunt" }, "repository": { "type": "git", "url": "git+https://github.com/patrikx3/ng2-compile-html.git" }, "keywords": [ "p3x", "angular", "ng", "compile", "html", "angular2", "angular 2", "ng2" ], "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.8", "@angular/compiler": "^2.4.8", "@angular/platform-browser": "^2.4.8", "@angular/platform-browser-dynamic": "^2.4.8", "@types/jasmine": "^2.5.43", "@types/node": "^7.0.5", "angular2-template-loader": "^0.6.2", "awesome-typescript-loader": "^3.0.7", "core-js": "^2.4.1", "corifeus-builder": "1.0.218-160", "extract-text-webpack-plugin": "^2.0.0", "grunt-connect": "^0.2.0", "grunt-contrib-connect": "^1.0.2", "grunt-karma": "^2.0.0", "grunt-protractor-runner": "^4.0.0", "grunt-webpack": "^2.0.1", "html-loader": "^0.4.5", "html-webpack-plugin": "^2.28.0", "istanbul-instrumenter-loader": "^2.0.0", "jasmine-core": "^2.5.2", "karma": "^1.5.0", "karma-coverage-istanbul-reporter": "^0.2.3", "karma-jasmine": "^1.1.0", "karma-phantomjs-launcher": "^1.0.2", "karma-sourcemap-loader": "^0.3.7", "karma-webpack": "^2.0.2", "node-sass-css-importer": "0.0.3", "optimize-css-assets-webpack-plugin": "^1.3.0", "phantomjs-prebuilt": "^2.1.14", "webpack": "^2.2.1", "webpack-dev-server": "^2.4.1", "webpack-merge": "^3.0.0" }, "dependencies": { "@angular/core": "^2.4.8", "rxjs": "^5.2.0", "zone.js": "0.7.7", "typescript": "^2.2.1" } }src/000077500000000000000000000000001516075046000116515ustar00rootroot00000000000000src/CompileHtmlAttribute.ts000066400000000000000000000016551516075046000163310ustar00rootroot00000000000000import {Directive, Input, Injectable, ViewContainerRef, OnInit, OnChanges, SimpleChanges} from '@angular/core'; import { CompileHtmlService } from './CompileHtmlService'; @Directive({ selector: '[p3x-compile-html]' }) @Injectable() export class CompileHtmlAttribute implements OnInit, OnChanges{ @Input('p3x-compile-html') p3xHtml: string; @Input('p3x-compile-html-ref') p3xCompileHtmlRef: any; @Input('p3x-compile-html-imports') 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.ts000066400000000000000000000016301516075046000157570ustar00rootroot00000000000000import { 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.ts000066400000000000000000000001701516075046000133260ustar00rootroot00000000000000export { CompileHtmlService } from "./CompileHtmlService"; export { CompileHtmlAttribute} from "./CompileHtmlAttribute";test/000077500000000000000000000000001516075046000120415ustar00rootroot00000000000000test/angular2-karma/000077500000000000000000000000001516075046000146455ustar00rootroot00000000000000test/angular2-karma/CompileHtmlService.ts000066400000000000000000000015141516075046000207540ustar00rootroot00000000000000import { 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); */ }); });test/angular2-protractor/000077500000000000000000000000001516075046000157515ustar00rootroot00000000000000test/angular2-protractor/test.js000066400000000000000000000014001516075046000172610ustar00rootroot00000000000000browser.ignoreSynchronization = true; describe('CompileHtml', () => { browser.get(`index.html`); const clicker = (button, counter) => { const total = 5; for(let i =0; i < total - 1; i++) { button.click(); browser.waitForAngular(); } const count = counter.getText(); expect(count).toEqual(total.toString()); } it('Service', () => { const button = element(by.id('button-container')) const counter = element(by.id('counter-container')); clicker(button, counter); }); it('Attribute', () => { const button = element(by.id('button-attribute')) const counter = element(by.id('counter-attribute')); clicker(button, counter); }); });test/angular2-webpack/000077500000000000000000000000001516075046000151665ustar00rootroot00000000000000test/angular2-webpack/app/000077500000000000000000000000001516075046000157465ustar00rootroot00000000000000test/angular2-webpack/app/Module.ts000066400000000000000000000006641516075046000175510ustar00rootroot00000000000000import { 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-webpack/app/Page.ts000066400000000000000000000026321516075046000171750ustar00rootroot00000000000000import { 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-webpack/index.html000066400000000000000000000003431516075046000171630ustar00rootroot00000000000000 ng2-compile-html test/angular2-webpack/main.ts000066400000000000000000000004271516075046000164650ustar00rootroot00000000000000import { 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-webpack/polyfills.ts000066400000000000000000000004041516075046000175510ustar00rootroot00000000000000import '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-webpack/vendor.ts000066400000000000000000000002351516075046000170330ustar00rootroot00000000000000// Angular import '@angular/platform-browser'; import '@angular/platform-browser-dynamic'; import '@angular/core'; import '@angular/common'; import 'rxjs'; tsconfig.json000066400000000000000000000007131516075046000135720ustar00rootroot00000000000000{ "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/000077500000000000000000000000001516075046000125575ustar00rootroot00000000000000typings/CompileHtmlServiceOptions.d.ts000066400000000000000000000003031516075046000204570ustar00rootroot00000000000000import { ViewContainerRef, } from '@angular/core'; export interface CompileHtmlServiceOptions { template: string; container: ViewContainerRef; imports?: any[]; ref?: any }