Skip to content

Commit 0801d45

Browse files
committed
feat: add option to inline templates and styles
Inline templates via "--inline-template" or "-it" Inline steyles via "--inline-style" or "-is" Fixes angular#296 Fixes angular#349
1 parent 3581bf1 commit 0801d45

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

addon/ng2/blueprints/component/files/__path__/__name__.component.ts

+10-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,16 @@ import {RouteConfig, ROUTER_DIRECTIVES, ROUTER_PROVIDERS} from 'angular2/router'
33

44
@Component({
55
moduleId: __moduleName,
6-
selector: '<%= dasherizedModuleName %>',
7-
templateUrl: '<%= dasherizedModuleName %>.component.html',
8-
styleUrls: ['<%= dasherizedModuleName %>.component.<%= styleExt %>']<% if (route) { %>,
6+
selector: '<%= dasherizedModuleName %>',<% if(inlineTemplate) { %>
7+
template: `
8+
<p>
9+
<%= dasherizedModuleName %> Works!
10+
</p><% if (route) { %>
11+
<router-outlet></router-outlet><% } %>
12+
`,<% } else { %>
13+
templateUrl: '<%= dasherizedModuleName %>.component.html',<% } if(inlineStyle) { %>
14+
styles: []<% } else { %>
15+
styleUrls: ['<%= dasherizedModuleName %>.component.<%= styleExt %>']<% } if (route) { %>,
916
directives: [ROUTER_DIRECTIVES]<% } %>
1017
})<% if (route) { %>
1118
@RouteConfig([

addon/ng2/blueprints/component/index.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ module.exports = {
2020

2121
availableOptions: [
2222
{ name: 'flat', type: Boolean, default: false },
23-
{ name: 'route', type: Boolean, default: false }
23+
{ name: 'route', type: Boolean, default: false },
24+
{ name: 'inline-template', type: Boolean, default: false, aliases: ['it'] },
25+
{ name: 'inline-style', type: Boolean, default: false, aliases: ['is'] },
2426
],
2527

2628
normalizeEntityName: function (entityName) {
@@ -42,6 +44,8 @@ module.exports = {
4244
return {
4345
dynamicPath: this.dynamicPath.dir.replace(this.dynamicPath.appRoot, ''),
4446
flat: options.flat,
47+
inlineTemplate: options.inlineTemplate,
48+
inlineStyle: options.inlineStyle,
4549
route: options.route,
4650
styleExt: this.styleExt,
4751
isLazyRoute: !!options.isLazyRoute,
@@ -58,6 +62,12 @@ module.exports = {
5862
if (this.options && !this.options.route) {
5963
fileList = fileList.filter(p => p.indexOf(path.join('shared', 'index.ts')) <= 0);
6064
}
65+
if (this.options && this.options.inlineTemplate) {
66+
fileList = fileList.filter(p => p.indexOf('.html') < 0);
67+
}
68+
if (this.options && this.options.inlineStyle) {
69+
fileList = fileList.filter(p => p.indexOf('.__styleext__') < 0);
70+
}
6171

6272
return fileList;
6373
},

0 commit comments

Comments
 (0)