Skip to content

Commit 65fe9d2

Browse files
passybtford
authored andcommitted
feat(app): use checkboxes for module selection
Instead of asking for each module separately, you now get a nice checkbox dialog where you can tick each of the modules on and off.
1 parent 8727288 commit 65fe9d2

File tree

5 files changed

+67
-23
lines changed

5 files changed

+67
-23
lines changed

app/index.js

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -101,26 +101,29 @@ Generator.prototype.askForModules = function askForModules() {
101101
var cb = this.async();
102102

103103
var prompts = [{
104-
type: 'confirm',
105-
name: 'resourceModule',
106-
message: 'Would you like to include angular-resource.js?',
107-
default: true
108-
}, {
109-
type: 'confirm',
110-
name: 'cookiesModule',
111-
message: 'Would you like to include angular-cookies.js?',
112-
default: true
113-
}, {
114-
type: 'confirm',
115-
name: 'sanitizeModule',
116-
message: 'Would you like to include angular-sanitize.js?',
117-
default: true
104+
type: 'checkbox',
105+
name: 'modules',
106+
message: 'Which modules would you like to include?',
107+
choices: [{
108+
value: 'resourceModule',
109+
name: 'angular-resource.js',
110+
checked: true
111+
}, {
112+
value: 'cookiesModule',
113+
name: 'angular-cookies.js',
114+
checked: true
115+
}, {
116+
value: 'sanitizeModule',
117+
name: 'angular-sanitize.js',
118+
checked: true
119+
}]
118120
}];
119121

120122
this.prompt(prompts, function (props) {
121-
this.resourceModule = props.resourceModule;
122-
this.cookiesModule = props.cookiesModule;
123-
this.sanitizeModule = props.sanitizeModule;
123+
var hasMod = function (mod) { return props.modules.indexOf(mod) !== -1; };
124+
this.resourceModule = hasMod('resourceModule');
125+
this.cookiesModule = hasMod('cookiesModule');
126+
this.sanitizeModule = hasMod('sanitizeModule');
124127

125128
cb();
126129
}.bind(this));

app/scripts/controllers/weluse.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
'use strict';
2+
3+
angular.module('generatorAngularApp')
4+
.controller('WeluseCtrl', function ($scope) {
5+
$scope.awesomeThings = [
6+
'HTML5 Boilerplate',
7+
'AngularJS',
8+
'Karma'
9+
];
10+
});

test/spec/controllers/weluse.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
'use strict';
2+
3+
describe('Controller: WeluseCtrl', function () {
4+
5+
// load the controller's module
6+
beforeEach(module('generatorAngularApp'));
7+
8+
var WeluseCtrl,
9+
scope;
10+
11+
// Initialize the controller and a mock scope
12+
beforeEach(inject(function ($controller, $rootScope) {
13+
scope = $rootScope.$new();
14+
WeluseCtrl = $controller('WeluseCtrl', {
15+
$scope: scope
16+
});
17+
}));
18+
19+
it('should attach a list of awesomeThings to the scope', function () {
20+
expect(scope.awesomeThings.length).toBe(3);
21+
});
22+
});

test/test-appname-substitution.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,11 @@ describe('Angular generator template mechanism', function () {
4141
'app/index.html',
4242
'test/spec/controllers/main.js'
4343
];
44-
helpers.mockPrompt(angular, {'bootstrap': 'Y', 'compassBoostrap': 'Y'});
44+
helpers.mockPrompt(angular, {
45+
bootstrap: true,
46+
compassBoostrap: true,
47+
modules: []
48+
});
4549

4650
angular.run({}, function () {
4751
// Check if all files are created for the test

test/test-file-creation.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ describe('Angular generator', function () {
3434
it('should generate dotfiles', function (done) {
3535
helpers.mockPrompt(angular, {
3636
bootstrap: true,
37-
compassBoostrap: true
37+
compassBoostrap: true,
38+
modules: []
3839
});
3940

4041
angular.run({}, function () {
@@ -61,7 +62,8 @@ describe('Angular generator', function () {
6162
];
6263
helpers.mockPrompt(angular, {
6364
bootstrap: true,
64-
compassBoostrap: true
65+
compassBoostrap: true,
66+
modules: []
6567
});
6668

6769
angular.run({}, function() {
@@ -88,7 +90,8 @@ describe('Angular generator', function () {
8890
];
8991
helpers.mockPrompt(angular, {
9092
bootstrap: true,
91-
compassBoostrap: true
93+
compassBoostrap: true,
94+
modules: []
9295
});
9396

9497
angular.env.options.coffee = true;
@@ -106,7 +109,8 @@ describe('Angular generator', function () {
106109

107110
helpers.mockPrompt(angular, {
108111
bootstrap: true,
109-
compassBoostrap: true
112+
compassBoostrap: true,
113+
modules: []
110114
});
111115
angular.run([], function () {
112116
angularCtrl.run([], function () {
@@ -128,7 +132,8 @@ describe('Angular generator', function () {
128132

129133
helpers.mockPrompt(angular, {
130134
bootstrap: true,
131-
compassBoostrap: true
135+
compassBoostrap: true,
136+
modules: []
132137
});
133138
angular.run([], function (){
134139
angularView.run([], function () {

0 commit comments

Comments
 (0)