.gitignore 0000664 0000000 0000000 00000000056 15161572741 0013060 0 ustar 00root root 0000000 0000000 /.idea
/node_modules
/build
*.iml
*.ipr
*.iws
.npmignore 0000664 0000000 0000000 00000000215 15161572741 0013064 0 ustar 00root root 0000000 0000000 /.idea
/artifacts
/build
/Gemfile
/_layouts
/_site
/_includes
/test
/node_modules
*.iml
*.ipr
*.iws
.travis.yml
.scrutinizer.yml
Gruntfile.js .scrutinizer.yml 0000664 0000000 0000000 00000000616 15161572741 0014254 0 ustar 00root root 0000000 0000000 checks:
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'
coverage:
file: 'build/coverage/clover.xml'
format: 'clover'
.travis.yml 0000664 0000000 0000000 00000000575 15161572741 0013207 0 ustar 00root root 0000000 0000000 sudo: 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.js 0000664 0000000 0000000 00000003004 15161572741 0013361 0 ustar 00root root 0000000 0000000 const 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: `
[](https://travis-ci.org/patrikx3/\${git.repo})
[](https://scrutinizer-ci.com/g/patrikx3/\${git.repo}/?branch=master)
[](https://scrutinizer-ci.com/g/patrikx3/\${git.repo}/?branch=master) [](https://trello.com/b/gqKHzZGy/p3x)
`,
files: [
'artifacts/**/*.md',
'*.md',
'!LICENSE.md'
]
},
footer: {
footer: true,
replace: `[by Patrik Laszlo](http://patrikx3.tk)`,
files: [
'artifacts/**/*.md',
'*.md',
'!LICENSE.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
} LICENSE.md 0000664 0000000 0000000 00000002056 15161572741 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 00000003007 15161572741 0012346 0 ustar 00root root 0000000 0000000 [//]: #@corifeus-header
[](https://travis-ci.org/patrikx3/ng2-compile-html)
[](https://scrutinizer-ci.com/g/patrikx3/ng2-compile-html/?branch=master)
[](https://scrutinizer-ci.com/g/patrikx3/ng2-compile-html/?branch=master) [](https://trello.com/b/gqKHzZGy/p3x)
[//]: #corifeus-header:end
# ng2-compile-html
Angular 2 Service/Attribute 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
###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)
[//]: #@corifeus-footer:end index.ts 0000664 0000000 0000000 00000000027 15161572741 0012545 0 ustar 00root root 0000000 0000000 export * from "./src";
package.json 0000664 0000000 0000000 00000004305 15161572741 0013357 0 ustar 00root root 0000000 0000000 {
"name": "p3x-ng2-compile-html",
"version": "1.0.86-110",
"corifeus": {
"prefix": "p3x-",
"time": "1/23/2017, 7:22:19 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",
"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.4",
"@angular/compiler": "^2.4.4",
"@angular/platform-browser": "^2.4.4",
"@angular/platform-browser-dynamic": "^2.4.4",
"@types/jasmine": "^2.5.41",
"@types/node": "^7.0.1",
"angular2-template-loader": "^0.6.0",
"awesome-typescript-loader": "^3.0.0-beta.18",
"core-js": "^2.4.1",
"corifeus-builder": "1.0.168-53",
"extract-text-webpack-plugin": "^1.0.1",
"grunt-connect": "^0.2.0",
"grunt-contrib-connect": "^1.0.2",
"grunt-karma": "^2.0.0",
"grunt-protractor-runner": "^4.0.0",
"grunt-webpack": "^1.0.18",
"html-loader": "^0.4.4",
"html-webpack-plugin": "^2.26.0",
"istanbul-instrumenter-loader": "^1.2.0",
"jasmine-core": "^2.5.2",
"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.4",
"rxjs": "^5.0.3",
"zone.js": "0.7.6",
"typescript": "^2.1.5"
}
} src/ 0000775 0000000 0000000 00000000000 15161572741 0011656 5 ustar 00root root 0000000 0000000 src/CompileHtmlAttribute.ts 0000664 0000000 0000000 00000001655 15161572741 0016336 0 ustar 00root root 0000000 0000000 import {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.ts 0000664 0000000 0000000 00000001630 15161572741 0015764 0 ustar 00root root 0000000 0000000 import {
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.ts 0000664 0000000 0000000 00000000170 15161572741 0013333 0 ustar 00root root 0000000 0000000 export { CompileHtmlService } from "./CompileHtmlService";
export { CompileHtmlAttribute} from "./CompileHtmlAttribute"; test/ 0000775 0000000 0000000 00000000000 15161572741 0012046 5 ustar 00root root 0000000 0000000 test/angular2-karma/ 0000775 0000000 0000000 00000000000 15161572741 0014652 5 ustar 00root root 0000000 0000000 test/angular2-karma/CompileHtmlService.ts 0000664 0000000 0000000 00000001514 15161572741 0020761 0 ustar 00root root 0000000 0000000 import { 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/ 0000775 0000000 0000000 00000000000 15161572741 0015756 5 ustar 00root root 0000000 0000000 test/angular2-protractor/test.js 0000664 0000000 0000000 00000001400 15161572741 0017266 0 ustar 00root root 0000000 0000000 browser.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/ 0000775 0000000 0000000 00000000000 15161572741 0015173 5 ustar 00root root 0000000 0000000 test/angular2-webpack/app/ 0000775 0000000 0000000 00000000000 15161572741 0015753 5 ustar 00root root 0000000 0000000 test/angular2-webpack/app/Module.ts 0000664 0000000 0000000 00000000664 15161572741 0017556 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-webpack/app/Page.ts 0000664 0000000 0000000 00000002632 15161572741 0017202 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-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.html 0000664 0000000 0000000 00000000347 15161572741 0017174 0 ustar 00root root 0000000 0000000
p3x-ng2-compile-html