Skip to content

Commit 8540d10

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 8540d10

File tree

4 files changed

+38
-5
lines changed

4 files changed

+38
-5
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
},

addon/ng2/blueprints/route/index.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ module.exports = {
1313
availableOptions: [
1414
{ name: 'skip-router-generation', type: Boolean, default: false, aliases: ['srg'] },
1515
{ name: 'default', type: Boolean, default: false },
16-
{ name: 'lazy', type: Boolean, default: true }
16+
{ name: 'lazy', type: Boolean, default: true },
17+
{ name: 'inline-template', type: Boolean, default: false, aliases: ['it'] },
18+
{ name: 'inline-style', type: Boolean, default: false, aliases: ['is'] }
1719
],
1820

1921
beforeInstall: function(options) {

tests/acceptance/generate-component.spec.js

+14
Original file line numberDiff line numberDiff line change
@@ -159,4 +159,18 @@ describe('Acceptance: ng generate component', function () {
159159
expect(existsSync(testPath)).to.equal(true);
160160
});
161161
});
162+
163+
it('ng generate component my-comp --inline-template', function () {
164+
return ng(['generate', 'component', 'my-comp', '--inline-template']).then(() => {
165+
var testPath = path.join(root, 'tmp', 'foo', 'src', 'client', 'app', 'my-comp', 'my-comp.component.html');
166+
expect(existsSync(testPath)).to.equal(false);
167+
});
168+
});
169+
170+
it('ng generate component my-comp --inline-style', function () {
171+
return ng(['generate', 'component', 'my-comp', '--inline-style']).then(() => {
172+
var testPath = path.join(root, 'tmp', 'foo', 'src', 'client', 'app', 'my-comp', 'my-comp.component.css');
173+
expect(existsSync(testPath)).to.equal(false);
174+
});
175+
});
162176
});

0 commit comments

Comments
 (0)