Skip to content

Commit 09f0f7b

Browse files
committed
feat(gen): allow app names to have custom suffix
Allow app names to have a custom suffix with app-suffix option. By default, it uses 'App' Breaks existing app names that began with a capital letter
1 parent 889befb commit 09f0f7b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+194
-165
lines changed

app/index.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22
var path = require('path');
33
var util = require('util');
4+
var angularUtils = require('../util.js');
45
var spawn = require('child_process').spawn;
56
var yeoman = require('yeoman-generator');
67

@@ -9,6 +10,14 @@ var Generator = module.exports = function Generator(args, options) {
910
yeoman.generators.Base.apply(this, arguments);
1011
this.argument('appname', { type: String, required: false });
1112
this.appname = this.appname || path.basename(process.cwd());
13+
this.appname = this._.camelize(this._.slugify(this._.humanize(this.appname)));
14+
15+
this.option('app-suffix', {
16+
desc: 'Allow a custom suffix to be added to the module name',
17+
type: String,
18+
required: 'false'
19+
});
20+
this.scriptAppName = this.appname + angularUtils.appName(this);
1221

1322
args = ['main'];
1423

route/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Generator.prototype.rewriteAppJs = function () {
2323
needle: '.otherwise',
2424
splicable: [
2525
" templateUrl: 'views/" + this.name + ".html'" + (coffee ? "" : "," ),
26-
" controller: '" + this._.classify(this.name) + "Ctrl'"
26+
" controller: '" + this.classedName + "Ctrl'"
2727
]
2828
};
2929

script-base.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ var Generator = module.exports = function Generator() {
1212
} catch (e) {
1313
this.appname = path.basename(process.cwd());
1414
}
15+
this.appname = this._.slugify(this._.humanize(this.appname));
16+
this.scriptAppName = this._.camelize(this.appname) + angularUtils.appName(this);
17+
18+
this.cameledName = this._.camelize(this.name);
19+
this.classedName = this._.classify(this.name);
1520

1621
if (typeof this.env.options.appPath === 'undefined') {
1722
try {

templates/coffeescript-min/app.coffee

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict'
22

3-
angular.module('<%= _.camelize(appname) %>App', [<%= angularModules %>])
3+
angular.module('<%= scriptAppName %>', [<%= angularModules %>])
44
.config ['$routeProvider', ($routeProvider) ->
55
$routeProvider
66
.when '/',

templates/coffeescript-min/controller.coffee

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict'
22

3-
angular.module('<%= _.camelize(appname) %>App')
4-
.controller '<%= _.classify(name) %>Ctrl', ['$scope', ($scope) ->
3+
angular.module('<%= scriptAppName %>')
4+
.controller '<%= classedName %>Ctrl', ['$scope', ($scope) ->
55
$scope.awesomeThings = [
66
'HTML5 Boilerplate'
77
'AngularJS'
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict'
22

3-
angular.module("<%= _.camelize(appname) %>App").config ["$provide", ($provide) ->
4-
$provide.decorator "<%= _.camelize(name) %>", ($delegate) ->
3+
angular.module("<%= scriptAppName").config ["$provide", ($provide) ->
4+
$provide.decorator "<%= cameledName %>", ($delegate) ->
55
# decorate the $delegate
66
$delegate
77
]
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
'use strict'
22

3-
angular.module('<%= _.camelize(appname) %>App')
4-
.directive '<%= _.camelize(name) %>', [->
3+
angular.module('<%= scriptAppName %>')
4+
.directive '<%= cameledName %>', [->
55
template: '<div></div>'
66
restrict: 'E'
77
link: (scope, element, attrs) ->
8-
element.text 'this is the <%= _.camelize(name) %> directive'
8+
element.text 'this is the <%= cameledName %> directive'
99
]
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict'
22

3-
angular.module('<%= _.camelize(appname) %>App')
4-
.filter '<%= _.camelize(name) %>', [() ->
3+
angular.module('<%= scriptAppName %>')
4+
.filter '<%= cameledName %>', [() ->
55
(input) ->
6-
'<%= _.camelize(name) %> filter: ' + input
6+
'<%= cameledName %> filter: ' + input
77
]
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
'use strict'
22

3-
angular.module('<%= _.camelize(appname) %>App')
4-
.constant '<%= _.camelize(name) %>', 42
3+
angular.module('<%= scriptAppName %>')
4+
.constant '<%= cameledName %>', 42

templates/coffeescript-min/service/factory.coffee

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict'
22

3-
angular.module('<%= _.camelize(appname) %>App')
4-
.factory '<%= _.camelize(name) %>', [() ->
3+
angular.module('<%= scriptAppName %>')
4+
.factory '<%= cameledName %>', [() ->
55
# Service logic
66
# ...
77

0 commit comments

Comments
 (0)