Skip to content

Commit 9be9bd5

Browse files
committed
chore: update templates to align with the style guide
Implements the majority of style guide #316 Moves systemjs configuration our of index.html #429 Closes #427
1 parent 8e9d3ef commit 9be9bd5

37 files changed

+256
-247
lines changed

addon/ng2/blueprints/component/files/__path__/__name__.css renamed to addon/ng2/blueprints/component/files/__path__/__name__.component.__styleext__

File renamed without changes.

addon/ng2/blueprints/component/files/__path__/__name__.html renamed to addon/ng2/blueprints/component/files/__path__/__name__.component.html

File renamed without changes.

addon/ng2/blueprints/component/files/__path__/__name__.spec.ts renamed to addon/ng2/blueprints/component/files/__path__/__name__.component.spec.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
11
import {
2-
it,
3-
iit,
2+
beforeEachProviders,
43
describe,
54
ddescribe,
65
expect,
6+
iit,
7+
it,
78
inject,
89
injectAsync,
9-
TestComponentBuilder,
10-
beforeEachProviders
10+
ComponentFixture,
11+
TestComponentBuilder
1112
} from 'angular2/testing';
1213
import {provide} from 'angular2/core';
13-
import {<%= classifiedModuleName %>} from './<%= dasherizedModuleName %>';
14+
import {<%= classifiedModuleName %>Component} from './<%= dasherizedModuleName %>.component';
1415

1516
describe('<%= classifiedModuleName %> Component', () => {
1617

1718
beforeEachProviders((): any[] => []);
1819

1920

2021
it('should ...', injectAsync([TestComponentBuilder], (tcb:TestComponentBuilder) => {
21-
return tcb.createAsync(<%= classifiedModuleName %>).then((fixture) => {
22+
return tcb.createAsync(<%= classifiedModuleName %>Component).then((fixture: ComponentFixture) => {
2223
fixture.detectChanges();
2324
});
2425
}));
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import {Component, OnInit} from 'angular2/core';
2+
3+
@Component({
4+
moduleId: __moduleName,
5+
selector: '<%= dasherizedModuleName %>',
6+
templateUrl: '<%= dasherizedModuleName %>.component.html',
7+
styleUrls: ['<%= dasherizedModuleName %>.component.<%= styleExt %>']
8+
})
9+
export class <%= classifiedModuleName %>Component implements OnInit {
10+
11+
constructor() {}
12+
13+
ngOnInit() {
14+
}
15+
16+
}

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

Lines changed: 0 additions & 16 deletions
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export {<%= classifiedModuleName %>Component} from './<%= dasherizedModuleName %>.component';

addon/ng2/blueprints/component/index.js

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
var path = require('path');
2+
var Blueprint = require('ember-cli/lib/models/blueprint');
23
var dynamicPathParser = require('../../utilities/dynamic-path-parser');
34

5+
var getFiles = Blueprint.prototype.files;
6+
47
module.exports = {
58
description: '',
69

710
availableOptions: [
8-
{ name: 'flat', type: Boolean, default: false, aliases: ['f'] }
11+
{ name: 'flat', type: Boolean, default: false }
912
],
1013

1114
normalizeEntityName: function (entityName) {
@@ -16,22 +19,60 @@ module.exports = {
1619
},
1720

1821
locals: function (options) {
22+
//TODO: pull value from config
23+
this.styleExt = 'css';
24+
1925
return {
2026
dynamicPath: this.dynamicPath.dir.replace(this.dynamicPath.appRoot, ''),
21-
flat: options.flat
27+
flat: options.flat,
28+
styleExt: this.styleExt,
29+
isLazyRoute: !!options.isLazyRoute,
30+
isAppComponent: !!options.isAppComponent
2231
};
2332
},
33+
34+
files: function() {
35+
var fileList = getFiles.call(this);
36+
37+
if (this.options.flat) {
38+
fileList = fileList.filter(p => p.indexOf('index.ts') <= 0);
39+
}
2440

41+
return fileList;
42+
},
43+
2544
fileMapTokens: function (options) {
2645
// Return custom template variables here.
2746
return {
2847
__path__: () => {
2948
var dir = this.dynamicPath.dir;
3049
if (!options.locals.flat) {
3150
dir += path.sep + options.dasherizedModuleName;
51+
52+
if (options.locals.isLazyRoute) {
53+
var dirParts = dir.split(path.sep);
54+
dirParts[dirParts.length - 1] = `+${dirParts[dirParts.length - 1]}`;
55+
dir = dirParts.join(path.sep);
56+
}
3257
}
58+
this.appDir = dir.replace(`src${path.sep}client${path.sep}`, '');
3359
return dir;
60+
},
61+
__styleext__: () => {
62+
return options.locals.styleExt;
3463
}
3564
};
65+
},
66+
67+
afterInstall: function(options) {
68+
if (!options.flat) {
69+
var filePath = path.join('src', 'client', 'system-config.ts');
70+
var barrelUrl = this.appDir.replace(path.sep, '/');
71+
return this.insertIntoFile(
72+
filePath,
73+
` '${barrelUrl}',`,
74+
{ before: ' /** @cli-barrel */' }
75+
);
76+
}
3677
}
3778
};

addon/ng2/blueprints/directive/files/__path__/__name__.spec.ts renamed to addon/ng2/blueprints/directive/files/__path__/__name__.directive.spec.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
import {
2-
it,
3-
iit,
2+
beforeEachProviders,
43
describe,
54
ddescribe,
65
expect,
6+
iit,
7+
it,
78
inject,
89
injectAsync,
9-
TestComponentBuilder,
10-
beforeEachProviders
10+
ComponentFixture,
11+
TestComponentBuilder
1112
} from 'angular2/testing';
1213
import {provide, Component} from 'angular2/core';
13-
import {<%= classifiedModuleName %>} from './<%= dasherizedModuleName %>';
14+
import {<%= classifiedModuleName %>} from './<%= dasherizedModuleName %>.directive';
1415

1516

1617
@Component({
@@ -25,7 +26,7 @@ describe('<%= classifiedModuleName %> Directive', () => {
2526

2627

2728
it('should ...', injectAsync([TestComponentBuilder], (tcb:TestComponentBuilder) => {
28-
return tcb.createAsync(TestComponent).then((fixture) => {
29+
return tcb.createAsync(TestComponent).then((fixture: ComponentFixture) => {
2930
fixture.detectChanges();
3031
});
3132
}));

addon/ng2/blueprints/directive/files/__path__/__name__.ts renamed to addon/ng2/blueprints/directive/files/__path__/__name__.directive.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
import {Directive} from 'angular2/core';
22

3-
43
@Directive({
5-
selector: '<%= dasherizedModuleName %>',
6-
providers: [],
7-
host: {},
8-
4+
selector: '<%= rawEntityName %>'
95
})
106
export class <%= classifiedModuleName %> {
117

addon/ng2/blueprints/directive/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,22 @@ module.exports = {
55
description: '',
66

77
availableOptions: [
8-
{ name: 'flat', type: Boolean, default: false, aliases: ['f'] }
8+
{ name: 'flat', type: Boolean, default: false }
99
],
1010

1111
normalizeEntityName: function (entityName) {
1212
var parsedPath = dynamicPathParser(this.project, entityName);
1313

1414
this.dynamicPath = parsedPath;
15+
this.rawEntityName = parsedPath.name;
1516
return parsedPath.name;
1617
},
1718

1819
locals: function (options) {
1920
return {
2021
dynamicPath: this.dynamicPath.dir,
21-
flat: options.flat
22+
flat: options.flat,
23+
rawEntityName: this.rawEntityName
2224
};
2325
},
2426

0 commit comments

Comments
 (0)