diff --git a/app/index.js b/app/index.js index d1526bade..43f509655 100644 --- a/app/index.js +++ b/app/index.js @@ -1,6 +1,7 @@ 'use strict'; var path = require('path'); var util = require('util'); +var angularUtils = require('../util.js'); var spawn = require('child_process').spawn; var yeoman = require('yeoman-generator'); @@ -9,6 +10,14 @@ var Generator = module.exports = function Generator(args, options) { yeoman.generators.Base.apply(this, arguments); this.argument('appname', { type: String, required: false }); this.appname = this.appname || path.basename(process.cwd()); + this.appname = this._.camelize(this._.slugify(this._.humanize(this.appname))); + + this.option('app-suffix', { + desc: 'Allow a custom suffix to be added to the module name', + type: String, + required: 'false' + }); + this.scriptAppName = this.appname + angularUtils.appName(this); args = ['main']; diff --git a/route/index.js b/route/index.js index 8aeb93851..2c653c601 100644 --- a/route/index.js +++ b/route/index.js @@ -23,7 +23,7 @@ Generator.prototype.rewriteAppJs = function () { needle: '.otherwise', splicable: [ " templateUrl: 'views/" + this.name + ".html'" + (coffee ? "" : "," ), - " controller: '" + this._.classify(this.name) + "Ctrl'" + " controller: '" + this.classedName + "Ctrl'" ] }; diff --git a/script-base.js b/script-base.js index f9054ca58..989cb1789 100644 --- a/script-base.js +++ b/script-base.js @@ -12,6 +12,11 @@ var Generator = module.exports = function Generator() { } catch (e) { this.appname = path.basename(process.cwd()); } + this.appname = this._.slugify(this._.humanize(this.appname)); + this.scriptAppName = this._.camelize(this.appname) + angularUtils.appName(this); + + this.cameledName = this._.camelize(this.name); + this.classedName = this._.classify(this.name); if (typeof this.env.options.appPath === 'undefined') { try { diff --git a/templates/coffeescript-min/app.coffee b/templates/coffeescript-min/app.coffee index 229628e13..3f7bb2792 100644 --- a/templates/coffeescript-min/app.coffee +++ b/templates/coffeescript-min/app.coffee @@ -1,6 +1,6 @@ 'use strict' -angular.module('<%= _.camelize(appname) %>App', [<%= angularModules %>]) +angular.module('<%= scriptAppName %>', [<%= angularModules %>]) .config ['$routeProvider', ($routeProvider) -> $routeProvider .when '/', diff --git a/templates/coffeescript-min/controller.coffee b/templates/coffeescript-min/controller.coffee index 0a4e6f4d2..fd22c83a9 100644 --- a/templates/coffeescript-min/controller.coffee +++ b/templates/coffeescript-min/controller.coffee @@ -1,7 +1,7 @@ 'use strict' -angular.module('<%= _.camelize(appname) %>App') - .controller '<%= _.classify(name) %>Ctrl', ['$scope', ($scope) -> +angular.module('<%= scriptAppName %>') + .controller '<%= classedName %>Ctrl', ['$scope', ($scope) -> $scope.awesomeThings = [ 'HTML5 Boilerplate' 'AngularJS' diff --git a/templates/coffeescript-min/decorator.coffee b/templates/coffeescript-min/decorator.coffee index ac6c08299..c380eb394 100644 --- a/templates/coffeescript-min/decorator.coffee +++ b/templates/coffeescript-min/decorator.coffee @@ -1,7 +1,7 @@ 'use strict' -angular.module("<%= _.camelize(appname) %>App").config ["$provide", ($provide) -> - $provide.decorator "<%= _.camelize(name) %>", ($delegate) -> +angular.module("<%= scriptAppName").config ["$provide", ($provide) -> + $provide.decorator "<%= cameledName %>", ($delegate) -> # decorate the $delegate $delegate ] diff --git a/templates/coffeescript-min/directive.coffee b/templates/coffeescript-min/directive.coffee index 677424479..7bf305a99 100644 --- a/templates/coffeescript-min/directive.coffee +++ b/templates/coffeescript-min/directive.coffee @@ -1,9 +1,9 @@ 'use strict' -angular.module('<%= _.camelize(appname) %>App') - .directive '<%= _.camelize(name) %>', [-> +angular.module('<%= scriptAppName %>') + .directive '<%= cameledName %>', [-> template: '
' restrict: 'E' link: (scope, element, attrs) -> - element.text 'this is the <%= _.camelize(name) %> directive' + element.text 'this is the <%= cameledName %> directive' ] diff --git a/templates/coffeescript-min/filter.coffee b/templates/coffeescript-min/filter.coffee index 469c3c94a..dc4f92b5d 100644 --- a/templates/coffeescript-min/filter.coffee +++ b/templates/coffeescript-min/filter.coffee @@ -1,7 +1,7 @@ 'use strict' -angular.module('<%= _.camelize(appname) %>App') - .filter '<%= _.camelize(name) %>', [() -> +angular.module('<%= scriptAppName %>') + .filter '<%= cameledName %>', [() -> (input) -> - '<%= _.camelize(name) %> filter: ' + input + '<%= cameledName %> filter: ' + input ] diff --git a/templates/coffeescript-min/service/constant.coffee b/templates/coffeescript-min/service/constant.coffee index e998f483b..49c0af7e2 100644 --- a/templates/coffeescript-min/service/constant.coffee +++ b/templates/coffeescript-min/service/constant.coffee @@ -1,4 +1,4 @@ 'use strict' -angular.module('<%= _.camelize(appname) %>App') - .constant '<%= _.camelize(name) %>', 42 +angular.module('<%= scriptAppName %>') + .constant '<%= cameledName %>', 42 diff --git a/templates/coffeescript-min/service/factory.coffee b/templates/coffeescript-min/service/factory.coffee index ba2a97c37..d9b515e3c 100644 --- a/templates/coffeescript-min/service/factory.coffee +++ b/templates/coffeescript-min/service/factory.coffee @@ -1,7 +1,7 @@ 'use strict' -angular.module('<%= _.camelize(appname) %>App') - .factory '<%= _.camelize(name) %>', [() -> +angular.module('<%= scriptAppName %>') + .factory '<%= cameledName %>', [() -> # Service logic # ... diff --git a/templates/coffeescript-min/service/provider.coffee b/templates/coffeescript-min/service/provider.coffee index 02e5048f9..9a8611bb2 100644 --- a/templates/coffeescript-min/service/provider.coffee +++ b/templates/coffeescript-min/service/provider.coffee @@ -1,7 +1,7 @@ 'use strict' -angular.module('<%= _.camelize(appname) %>App') - .provider '<%= _.camelize(name) %>', [-> +angular.module('<%= scriptAppName %>') + .provider '<%= cameledName %>', [-> # Private variables salutation = 'Hello' diff --git a/templates/coffeescript-min/service/service.coffee b/templates/coffeescript-min/service/service.coffee index 9268e48c7..ab30570f1 100644 --- a/templates/coffeescript-min/service/service.coffee +++ b/templates/coffeescript-min/service/service.coffee @@ -1,5 +1,5 @@ 'use strict' -angular.module('<%= _.camelize(appname) %>App') - .service '<%= _.classify(name) %>', () -> +angular.module('<%= scriptAppName %>') + .service '<%= classedName %>', () -> # AngularJS will instantiate a singleton by calling "new" on this function diff --git a/templates/coffeescript-min/service/value.coffee b/templates/coffeescript-min/service/value.coffee index 3bd4f898b..5e6b5427c 100644 --- a/templates/coffeescript-min/service/value.coffee +++ b/templates/coffeescript-min/service/value.coffee @@ -1,4 +1,4 @@ 'use strict' -angular.module('<%= _.camelize(appname) %>App') - .value '<%= _.camelize(name) %>', 42 +angular.module('<%= scriptAppName %>') + .value '<%= cameledName %>', 42 diff --git a/templates/coffeescript-min/spec/controller.coffee b/templates/coffeescript-min/spec/controller.coffee index 787c6924e..04a67b98c 100644 --- a/templates/coffeescript-min/spec/controller.coffee +++ b/templates/coffeescript-min/spec/controller.coffee @@ -1,17 +1,17 @@ 'use strict' -describe 'Controller: <%= _.classify(name) %>Ctrl', () -> +describe 'Controller: <%= classedName %>Ctrl', () -> # load the controller's module - beforeEach module '<%= _.camelize(appname) %>App' + beforeEach module '<%= scriptAppName %>' - <%= _.classify(name) %>Ctrl = {} + <%= classedName %>Ctrl = {} scope = {} # Initialize the controller and a mock scope beforeEach inject ($controller, $rootScope) -> scope = $rootScope.$new() - <%= _.classify(name) %>Ctrl = $controller '<%= _.classify(name) %>Ctrl', { + <%= classedName %>Ctrl = $controller '<%= classedName %>Ctrl', { $scope: scope } diff --git a/templates/coffeescript-min/spec/directive.coffee b/templates/coffeescript-min/spec/directive.coffee index 3c3cdd214..7cd04df27 100644 --- a/templates/coffeescript-min/spec/directive.coffee +++ b/templates/coffeescript-min/spec/directive.coffee @@ -1,9 +1,9 @@ 'use strict' -describe 'Directive: <%= _.camelize(name) %>', () -> +describe 'Directive: <%= cameledName %>', () -> # load the directive's module - beforeEach module '<%= _.camelize(appname) %>App' + beforeEach module '<%= scriptAppName %>' scope = {} @@ -13,4 +13,4 @@ describe 'Directive: <%= _.camelize(name) %>', () -> it 'should make hidden element visible', inject ($compile) -> element = angular.element '<<%= _.dasherize(name) %>>>' element = $compile(element) scope - expect(element.text()).toBe 'this is the <%= _.camelize(name) %> directive' + expect(element.text()).toBe 'this is the <%= cameledName %> directive' diff --git a/templates/coffeescript-min/spec/filter.coffee b/templates/coffeescript-min/spec/filter.coffee index 765e2fca0..6dff4c806 100644 --- a/templates/coffeescript-min/spec/filter.coffee +++ b/templates/coffeescript-min/spec/filter.coffee @@ -1,15 +1,15 @@ 'use strict' -describe 'Filter: <%= _.camelize(name) %>', () -> +describe 'Filter: <%= cameledName %>', () -> # load the filter's module - beforeEach module '<%= _.camelize(appname) %>App' + beforeEach module '<%= scriptAppName %>' # initialize a new instance of the filter before each test - <%= _.camelize(name) %> = {} + <%= cameledName %> = {} beforeEach inject ($filter) -> - <%= _.camelize(name) %> = $filter '<%= _.camelize(name) %>' + <%= cameledName %> = $filter '<%= cameledName %>' - it 'should return the input prefixed with "<%= _.camelize(name) %> filter:"', () -> + it 'should return the input prefixed with "<%= cameledName %> filter:"', () -> text = 'angularjs' - expect(<%= _.camelize(name) %> text).toBe ('<%= _.camelize(name) %> filter: ' + text) + expect(<%= cameledName %> text).toBe ('<%= cameledName %> filter: ' + text) diff --git a/templates/coffeescript-min/spec/service.coffee b/templates/coffeescript-min/spec/service.coffee index 17bce6b2b..9eae32b3f 100644 --- a/templates/coffeescript-min/spec/service.coffee +++ b/templates/coffeescript-min/spec/service.coffee @@ -1,14 +1,14 @@ 'use strict' -describe 'Service: <%= _.classify(name) %>', () -> +describe 'Service: <%= classedName %>', () -> # load the service's module - beforeEach module '<%= _.classify(appname) %>App' + beforeEach module '<%= scriptAppName %>App' # instantiate service - <%= _.classify(name) %> = {} - beforeEach inject (_<%= _.classify(name) %>_) -> - <%= _.classify(name) %> = _<%= _.classify(name) %>_ + <%= classedName %> = {} + beforeEach inject (_<%= classedName %>_) -> + <%= classedName %> = _<%= classedName %>_ it 'should do something', () -> - expect(!!<%= _.classify(name) %>).toBe true + expect(!!<%= classedName %>).toBe true diff --git a/templates/coffeescript/app.coffee b/templates/coffeescript/app.coffee index bcec4268f..7383e998d 100644 --- a/templates/coffeescript/app.coffee +++ b/templates/coffeescript/app.coffee @@ -1,6 +1,6 @@ 'use strict' -angular.module('<%= _.camelize(appname) %>App', [<%= angularModules %>]) +angular.module('<%= scriptAppName %>', [<%= angularModules %>]) .config ($routeProvider) -> $routeProvider .when '/', diff --git a/templates/coffeescript/controller.coffee b/templates/coffeescript/controller.coffee index e429e86f9..cf02fd99c 100644 --- a/templates/coffeescript/controller.coffee +++ b/templates/coffeescript/controller.coffee @@ -1,7 +1,7 @@ 'use strict' -angular.module('<%= _.camelize(appname) %>App') - .controller '<%= _.classify(name) %>Ctrl', ($scope) -> +angular.module('<%= scriptAppName %>') + .controller '<%= classedName %>Ctrl', ($scope) -> $scope.awesomeThings = [ 'HTML5 Boilerplate' 'AngularJS' diff --git a/templates/coffeescript/decorator.coffee b/templates/coffeescript/decorator.coffee index f6be1c170..61603e6c3 100644 --- a/templates/coffeescript/decorator.coffee +++ b/templates/coffeescript/decorator.coffee @@ -1,6 +1,6 @@ 'use strict' -angular.module("<%= _.camelize(appname) %>App").config ($provide) -> - $provide.decorator "<%= _.camelize(name) %>", ($delegate) -> +angular.module("<%= scriptAppName").config ($provide) -> + $provide.decorator "<%= cameledName %>", ($delegate) -> # decorate the $delegate $delegate diff --git a/templates/coffeescript/directive.coffee b/templates/coffeescript/directive.coffee index 194af3e99..ac08bbe26 100644 --- a/templates/coffeescript/directive.coffee +++ b/templates/coffeescript/directive.coffee @@ -1,9 +1,9 @@ 'use strict' -angular.module('<%= _.camelize(appname) %>App') - .directive('<%= _.camelize(name) %>', () -> +angular.module('<%= scriptAppName %>') + .directive('<%= cameledName %>', () -> template: '
' restrict: 'E' link: (scope, element, attrs) -> - element.text 'this is the <%= _.camelize(name) %> directive' + element.text 'this is the <%= cameledName %> directive' ) diff --git a/templates/coffeescript/filter.coffee b/templates/coffeescript/filter.coffee index b85e6b457..b6789b8b0 100644 --- a/templates/coffeescript/filter.coffee +++ b/templates/coffeescript/filter.coffee @@ -1,6 +1,6 @@ 'use strict' -angular.module('<%= _.camelize(appname) %>App') - .filter '<%= _.camelize(name) %>', () -> +angular.module('<%= scriptAppName %>') + .filter '<%= cameledName %>', () -> (input) -> - '<%= _.camelize(name) %> filter: ' + input + '<%= cameledName %> filter: ' + input diff --git a/templates/coffeescript/service/constant.coffee b/templates/coffeescript/service/constant.coffee index e998f483b..49c0af7e2 100644 --- a/templates/coffeescript/service/constant.coffee +++ b/templates/coffeescript/service/constant.coffee @@ -1,4 +1,4 @@ 'use strict' -angular.module('<%= _.camelize(appname) %>App') - .constant '<%= _.camelize(name) %>', 42 +angular.module('<%= scriptAppName %>') + .constant '<%= cameledName %>', 42 diff --git a/templates/coffeescript/service/factory.coffee b/templates/coffeescript/service/factory.coffee index 7828f888d..7f4daf552 100644 --- a/templates/coffeescript/service/factory.coffee +++ b/templates/coffeescript/service/factory.coffee @@ -1,7 +1,7 @@ 'use strict' -angular.module('<%= _.camelize(appname) %>App') - .factory '<%= _.camelize(name) %>', () -> +angular.module('<%= scriptAppName %>') + .factory '<%= cameledName %>', () -> # Service logic # ... diff --git a/templates/coffeescript/service/provider.coffee b/templates/coffeescript/service/provider.coffee index 02e5048f9..9a8611bb2 100644 --- a/templates/coffeescript/service/provider.coffee +++ b/templates/coffeescript/service/provider.coffee @@ -1,7 +1,7 @@ 'use strict' -angular.module('<%= _.camelize(appname) %>App') - .provider '<%= _.camelize(name) %>', [-> +angular.module('<%= scriptAppName %>') + .provider '<%= cameledName %>', [-> # Private variables salutation = 'Hello' diff --git a/templates/coffeescript/service/service.coffee b/templates/coffeescript/service/service.coffee index 9268e48c7..ab30570f1 100644 --- a/templates/coffeescript/service/service.coffee +++ b/templates/coffeescript/service/service.coffee @@ -1,5 +1,5 @@ 'use strict' -angular.module('<%= _.camelize(appname) %>App') - .service '<%= _.classify(name) %>', () -> +angular.module('<%= scriptAppName %>') + .service '<%= classedName %>', () -> # AngularJS will instantiate a singleton by calling "new" on this function diff --git a/templates/coffeescript/service/value.coffee b/templates/coffeescript/service/value.coffee index 3bd4f898b..5e6b5427c 100644 --- a/templates/coffeescript/service/value.coffee +++ b/templates/coffeescript/service/value.coffee @@ -1,4 +1,4 @@ 'use strict' -angular.module('<%= _.camelize(appname) %>App') - .value '<%= _.camelize(name) %>', 42 +angular.module('<%= scriptAppName %>') + .value '<%= cameledName %>', 42 diff --git a/templates/coffeescript/spec/controller.coffee b/templates/coffeescript/spec/controller.coffee index 787c6924e..04a67b98c 100644 --- a/templates/coffeescript/spec/controller.coffee +++ b/templates/coffeescript/spec/controller.coffee @@ -1,17 +1,17 @@ 'use strict' -describe 'Controller: <%= _.classify(name) %>Ctrl', () -> +describe 'Controller: <%= classedName %>Ctrl', () -> # load the controller's module - beforeEach module '<%= _.camelize(appname) %>App' + beforeEach module '<%= scriptAppName %>' - <%= _.classify(name) %>Ctrl = {} + <%= classedName %>Ctrl = {} scope = {} # Initialize the controller and a mock scope beforeEach inject ($controller, $rootScope) -> scope = $rootScope.$new() - <%= _.classify(name) %>Ctrl = $controller '<%= _.classify(name) %>Ctrl', { + <%= classedName %>Ctrl = $controller '<%= classedName %>Ctrl', { $scope: scope } diff --git a/templates/coffeescript/spec/directive.coffee b/templates/coffeescript/spec/directive.coffee index 3c3cdd214..7cd04df27 100644 --- a/templates/coffeescript/spec/directive.coffee +++ b/templates/coffeescript/spec/directive.coffee @@ -1,9 +1,9 @@ 'use strict' -describe 'Directive: <%= _.camelize(name) %>', () -> +describe 'Directive: <%= cameledName %>', () -> # load the directive's module - beforeEach module '<%= _.camelize(appname) %>App' + beforeEach module '<%= scriptAppName %>' scope = {} @@ -13,4 +13,4 @@ describe 'Directive: <%= _.camelize(name) %>', () -> it 'should make hidden element visible', inject ($compile) -> element = angular.element '<<%= _.dasherize(name) %>>>' element = $compile(element) scope - expect(element.text()).toBe 'this is the <%= _.camelize(name) %> directive' + expect(element.text()).toBe 'this is the <%= cameledName %> directive' diff --git a/templates/coffeescript/spec/filter.coffee b/templates/coffeescript/spec/filter.coffee index 765e2fca0..6dff4c806 100644 --- a/templates/coffeescript/spec/filter.coffee +++ b/templates/coffeescript/spec/filter.coffee @@ -1,15 +1,15 @@ 'use strict' -describe 'Filter: <%= _.camelize(name) %>', () -> +describe 'Filter: <%= cameledName %>', () -> # load the filter's module - beforeEach module '<%= _.camelize(appname) %>App' + beforeEach module '<%= scriptAppName %>' # initialize a new instance of the filter before each test - <%= _.camelize(name) %> = {} + <%= cameledName %> = {} beforeEach inject ($filter) -> - <%= _.camelize(name) %> = $filter '<%= _.camelize(name) %>' + <%= cameledName %> = $filter '<%= cameledName %>' - it 'should return the input prefixed with "<%= _.camelize(name) %> filter:"', () -> + it 'should return the input prefixed with "<%= cameledName %> filter:"', () -> text = 'angularjs' - expect(<%= _.camelize(name) %> text).toBe ('<%= _.camelize(name) %> filter: ' + text) + expect(<%= cameledName %> text).toBe ('<%= cameledName %> filter: ' + text) diff --git a/templates/coffeescript/spec/service.coffee b/templates/coffeescript/spec/service.coffee index 17bce6b2b..9eae32b3f 100644 --- a/templates/coffeescript/spec/service.coffee +++ b/templates/coffeescript/spec/service.coffee @@ -1,14 +1,14 @@ 'use strict' -describe 'Service: <%= _.classify(name) %>', () -> +describe 'Service: <%= classedName %>', () -> # load the service's module - beforeEach module '<%= _.classify(appname) %>App' + beforeEach module '<%= scriptAppName %>App' # instantiate service - <%= _.classify(name) %> = {} - beforeEach inject (_<%= _.classify(name) %>_) -> - <%= _.classify(name) %> = _<%= _.classify(name) %>_ + <%= classedName %> = {} + beforeEach inject (_<%= classedName %>_) -> + <%= classedName %> = _<%= classedName %>_ it 'should do something', () -> - expect(!!<%= _.classify(name) %>).toBe true + expect(!!<%= classedName %>).toBe true diff --git a/templates/common/_bower.json b/templates/common/_bower.json index 20f39a8c6..d49cf6083 100644 --- a/templates/common/_bower.json +++ b/templates/common/_bower.json @@ -1,5 +1,5 @@ { - "name": "<%= _.camelize(appname) %>", + "name": "<%= _.slugify(_.humanize(appname)) %>", "version": "0.0.0", "dependencies": { "angular": "~1.0.7", diff --git a/templates/common/index.html b/templates/common/index.html index ba5774779..429e15591 100644 --- a/templates/common/index.html +++ b/templates/common/index.html @@ -11,7 +11,7 @@ - + diff --git a/templates/javascript-min/app.js b/templates/javascript-min/app.js index 3334eb63c..82f10a7ee 100644 --- a/templates/javascript-min/app.js +++ b/templates/javascript-min/app.js @@ -1,6 +1,6 @@ 'use strict'; -angular.module('<%= _.camelize(appname) %>App', [<%= angularModules %>]) +angular.module('<%= scriptAppName %>', [<%= angularModules %>]) .config(['$routeProvider', function ($routeProvider) { $routeProvider .when('/', { diff --git a/templates/javascript-min/controller.js b/templates/javascript-min/controller.js index f0385729a..64da5daae 100644 --- a/templates/javascript-min/controller.js +++ b/templates/javascript-min/controller.js @@ -1,7 +1,7 @@ 'use strict'; -angular.module('<%= _.camelize(appname) %>App') - .controller('<%= _.classify(name) %>Ctrl', ['$scope', function ($scope) { +angular.module('<%= scriptAppName %>') + .controller('<%= classedName %>Ctrl', ['$scope', function ($scope) { $scope.awesomeThings = [ 'HTML5 Boilerplate', 'AngularJS', diff --git a/templates/javascript-min/decorator.js b/templates/javascript-min/decorator.js index 7a0bcefd6..81a6c76d9 100644 --- a/templates/javascript-min/decorator.js +++ b/templates/javascript-min/decorator.js @@ -1,8 +1,8 @@ 'use strict'; -angular.module('<%= _.camelize(appname) %>App') +angular.module('<%= scriptAppName %>') .config(['$provide', function ($provide) { - $provide.decorator('<%= _.camelize(name) %>', function ($delegate) { + $provide.decorator('<%= cameledName %>', function ($delegate) { // decorate the $delegate return $delegate; }); diff --git a/templates/javascript-min/directive.js b/templates/javascript-min/directive.js index 524231bd2..d8da40289 100644 --- a/templates/javascript-min/directive.js +++ b/templates/javascript-min/directive.js @@ -1,12 +1,12 @@ 'use strict'; -angular.module('<%= _.camelize(appname) %>App') - .directive('<%= _.camelize(name) %>', [function () { +angular.module('<%= scriptAppName %>') + .directive('<%= cameledName %>', [function () { return { template: '
', restrict: 'E', link: function postLink(scope, element, attrs) { - element.text('this is the <%= _.camelize(name) %> directive'); + element.text('this is the <%= cameledName %> directive'); } }; }]); diff --git a/templates/javascript-min/filter.js b/templates/javascript-min/filter.js index bc25b4c1c..3635330c2 100644 --- a/templates/javascript-min/filter.js +++ b/templates/javascript-min/filter.js @@ -1,8 +1,8 @@ 'use strict'; -angular.module('<%= _.camelize(appname) %>App') - .filter('<%= _.camelize(name) %>', [function () { +angular.module('<%= scriptAppName %>') + .filter('<%= cameledName %>', [function () { return function (input) { - return '<%= _.camelize(name) %> filter: ' + input; + return '<%= cameledName %> filter: ' + input; }; }]); diff --git a/templates/javascript-min/service/constant.js b/templates/javascript-min/service/constant.js index 62686827c..0c02a8a8a 100644 --- a/templates/javascript-min/service/constant.js +++ b/templates/javascript-min/service/constant.js @@ -1,4 +1,4 @@ 'use strict'; -angular.module('<%= _.camelize(appname) %>App') - .constant('<%= _.camelize(name) %>', 42); +angular.module('<%= scriptAppName %>') + .constant('<%= cameledName %>', 42); diff --git a/templates/javascript-min/service/factory.js b/templates/javascript-min/service/factory.js index 9529c7325..5ad4b383c 100644 --- a/templates/javascript-min/service/factory.js +++ b/templates/javascript-min/service/factory.js @@ -1,7 +1,7 @@ 'use strict'; -angular.module('<%= _.camelize(appname) %>App') - .factory('<%= _.camelize(name) %>', [function() { +angular.module('<%= scriptAppName %>') + .factory('<%= cameledName %>', [function() { // Service logic // ... diff --git a/templates/javascript-min/service/provider.js b/templates/javascript-min/service/provider.js index 49789a81c..64ff52bfd 100644 --- a/templates/javascript-min/service/provider.js +++ b/templates/javascript-min/service/provider.js @@ -1,7 +1,7 @@ 'use strict'; -angular.module('<%= _.camelize(appname) %>App') - .provider('<%= _.camelize(name) %>', [function() { +angular.module('<%= scriptAppName %>') + .provider('<%= cameledName %>', [function() { // Private variables var salutation = 'Hello'; diff --git a/templates/javascript-min/service/service.js b/templates/javascript-min/service/service.js index 829dbd6e9..1adfe44b4 100644 --- a/templates/javascript-min/service/service.js +++ b/templates/javascript-min/service/service.js @@ -1,6 +1,6 @@ 'use strict'; -angular.module('<%= _.camelize(appname) %>App') - .service('<%= _.classify(name) %>', function <%= _.classify(name) %>() { +angular.module('<%= scriptAppName %>') + .service('<%= classedName %>', function <%= classedName %>() { // AngularJS will instantiate a singleton by calling "new" on this function }); diff --git a/templates/javascript-min/service/value.js b/templates/javascript-min/service/value.js index 90f219727..01507e03f 100644 --- a/templates/javascript-min/service/value.js +++ b/templates/javascript-min/service/value.js @@ -1,4 +1,4 @@ 'use strict'; -angular.module('<%= _.camelize(appname) %>App') - .value('<%= _.camelize(name) %>', 42); +angular.module('<%= scriptAppName %>') + .value('<%= cameledName %>', 42); diff --git a/templates/javascript-min/spec/controller.js b/templates/javascript-min/spec/controller.js index 6545c70f2..95005029e 100644 --- a/templates/javascript-min/spec/controller.js +++ b/templates/javascript-min/spec/controller.js @@ -1,17 +1,17 @@ 'use strict'; -describe('Controller: <%= _.classify(name) %>Ctrl', function () { +describe('Controller: <%= classedName %>Ctrl', function () { // load the controller's module - beforeEach(module('<%= _.camelize(appname) %>App')); + beforeEach(module('<%= scriptAppName %>')); - var <%= _.classify(name) %>Ctrl, + var <%= classedName %>Ctrl, scope; // Initialize the controller and a mock scope beforeEach(inject(function ($controller, $rootScope) { scope = $rootScope.$new(); - <%= _.classify(name) %>Ctrl = $controller('<%= _.classify(name) %>Ctrl', { + <%= classedName %>Ctrl = $controller('<%= classedName %>Ctrl', { $scope: scope }); })); diff --git a/templates/javascript-min/spec/directive.js b/templates/javascript-min/spec/directive.js index f0e12fb13..fbe52519c 100644 --- a/templates/javascript-min/spec/directive.js +++ b/templates/javascript-min/spec/directive.js @@ -1,9 +1,9 @@ 'use strict'; -describe('Directive: <%= _.camelize(name) %>', function () { +describe('Directive: <%= cameledName %>', function () { // load the directive's module - beforeEach(module('<%= _.camelize(appname) %>App')); + beforeEach(module('<%= scriptAppName %>')); var element, scope; @@ -15,6 +15,6 @@ describe('Directive: <%= _.camelize(name) %>', function () { it('should make hidden element visible', inject(function ($compile) { element = angular.element('<<%= _.dasherize(name) %>>>'); element = $compile(element)(scope); - expect(element.text()).toBe('this is the <%= _.camelize(name) %> directive'); + expect(element.text()).toBe('this is the <%= cameledName %> directive'); })); }); diff --git a/templates/javascript-min/spec/filter.js b/templates/javascript-min/spec/filter.js index 7aa6a7695..5799b7dee 100644 --- a/templates/javascript-min/spec/filter.js +++ b/templates/javascript-min/spec/filter.js @@ -1,19 +1,19 @@ 'use strict'; -describe('Filter: <%= _.camelize(name) %>', function () { +describe('Filter: <%= cameledName %>', function () { // load the filter's module - beforeEach(module('<%= _.camelize(appname) %>App')); + beforeEach(module('<%= scriptAppName %>')); // initialize a new instance of the filter before each test - var <%= _.camelize(name) %>; + var <%= cameledName %>; beforeEach(inject(function($filter) { - <%= _.camelize(name) %> = $filter('<%= _.camelize(name) %>'); + <%= cameledName %> = $filter('<%= cameledName %>'); })); - it('should return the input prefixed with "<%= _.camelize(name) %> filter:"', function () { + it('should return the input prefixed with "<%= cameledName %> filter:"', function () { var text = 'angularjs'; - expect(<%= _.camelize(name) %>(text)).toBe('<%= _.camelize(name) %> filter: ' + text); + expect(<%= cameledName %>(text)).toBe('<%= cameledName %> filter: ' + text); }); }); diff --git a/templates/javascript-min/spec/service.js b/templates/javascript-min/spec/service.js index 2634f1bac..93e717916 100644 --- a/templates/javascript-min/spec/service.js +++ b/templates/javascript-min/spec/service.js @@ -1,18 +1,18 @@ 'use strict'; -describe('Service: <%= _.classify(name) %>', function () { +describe('Service: <%= classedName %>', function () { // load the service's module - beforeEach(module('<%= _.classify(appname) %>App')); + beforeEach(module('<%= scriptAppName %>App')); // instantiate service - var <%= _.classify(name) %>; - beforeEach(inject(function(_<%= _.classify(name) %>_) { - <%= _.classify(name) %> = _<%= _.classify(name) %>_; + var <%= classedName %>; + beforeEach(inject(function(_<%= classedName %>_) { + <%= classedName %> = _<%= classedName %>_; })); it('should do something', function () { - expect(!!<%= _.classify(name) %>).toBe(true); + expect(!!<%= classedName %>).toBe(true); }); }); diff --git a/templates/javascript/app.js b/templates/javascript/app.js index 352460f16..4651cd995 100644 --- a/templates/javascript/app.js +++ b/templates/javascript/app.js @@ -1,6 +1,6 @@ 'use strict'; -angular.module('<%= _.camelize(appname) %>App', [<%= angularModules %>]) +angular.module('<%= scriptAppName %>', [<%= angularModules %>]) .config(function ($routeProvider) { $routeProvider .when('/', { diff --git a/templates/javascript/controller.js b/templates/javascript/controller.js index dcebb0a00..216a5ea20 100644 --- a/templates/javascript/controller.js +++ b/templates/javascript/controller.js @@ -1,7 +1,7 @@ 'use strict'; -angular.module('<%= _.camelize(appname) %>App') - .controller('<%= _.classify(name) %>Ctrl', function ($scope) { +angular.module('<%= scriptAppName %>') + .controller('<%= classedName %>Ctrl', function ($scope) { $scope.awesomeThings = [ 'HTML5 Boilerplate', 'AngularJS', diff --git a/templates/javascript/decorator.js b/templates/javascript/decorator.js index d5fb60087..57efaa3f6 100644 --- a/templates/javascript/decorator.js +++ b/templates/javascript/decorator.js @@ -1,8 +1,8 @@ 'use strict'; -angular.module('<%= _.camelize(appname) %>App') +angular.module('<%= scriptAppName %>') .config(function ($provide) { - $provide.decorator('<%= _.camelize(name) %>', function ($delegate) { + $provide.decorator('<%= cameledName %>', function ($delegate) { // decorate the $delegate return $delegate; }); diff --git a/templates/javascript/directive.js b/templates/javascript/directive.js index bec7df2d2..57b0e1f3d 100644 --- a/templates/javascript/directive.js +++ b/templates/javascript/directive.js @@ -1,12 +1,12 @@ 'use strict'; -angular.module('<%= _.camelize(appname) %>App') - .directive('<%= _.camelize(name) %>', function () { +angular.module('<%= scriptAppName %>') + .directive('<%= cameledName %>', function () { return { template: '
', restrict: 'E', link: function postLink(scope, element, attrs) { - element.text('this is the <%= _.camelize(name) %> directive'); + element.text('this is the <%= cameledName %> directive'); } }; }); diff --git a/templates/javascript/filter.js b/templates/javascript/filter.js index 7866f55f1..9f897ab76 100644 --- a/templates/javascript/filter.js +++ b/templates/javascript/filter.js @@ -1,8 +1,8 @@ 'use strict'; -angular.module('<%= _.camelize(appname) %>App') - .filter('<%= _.camelize(name) %>', function () { +angular.module('<%= scriptAppName %>') + .filter('<%= cameledName %>', function () { return function (input) { - return '<%= _.camelize(name) %> filter: ' + input; + return '<%= cameledName %> filter: ' + input; }; }); diff --git a/templates/javascript/service/constant.js b/templates/javascript/service/constant.js index 62686827c..0c02a8a8a 100644 --- a/templates/javascript/service/constant.js +++ b/templates/javascript/service/constant.js @@ -1,4 +1,4 @@ 'use strict'; -angular.module('<%= _.camelize(appname) %>App') - .constant('<%= _.camelize(name) %>', 42); +angular.module('<%= scriptAppName %>') + .constant('<%= cameledName %>', 42); diff --git a/templates/javascript/service/factory.js b/templates/javascript/service/factory.js index 821fa9173..f7e942eb9 100644 --- a/templates/javascript/service/factory.js +++ b/templates/javascript/service/factory.js @@ -1,7 +1,7 @@ 'use strict'; -angular.module('<%= _.camelize(appname) %>App') - .factory('<%= _.camelize(name) %>', function () { +angular.module('<%= scriptAppName %>') + .factory('<%= cameledName %>', function () { // Service logic // ... diff --git a/templates/javascript/service/provider.js b/templates/javascript/service/provider.js index 812e8f6a3..101e774c5 100644 --- a/templates/javascript/service/provider.js +++ b/templates/javascript/service/provider.js @@ -1,7 +1,7 @@ 'use strict'; -angular.module('<%= _.camelize(appname) %>App') - .provider('<%= _.camelize(name) %>', function () { +angular.module('<%= scriptAppName %>') + .provider('<%= cameledName %>', function () { // Private variables var salutation = 'Hello'; diff --git a/templates/javascript/service/service.js b/templates/javascript/service/service.js index 829dbd6e9..1adfe44b4 100644 --- a/templates/javascript/service/service.js +++ b/templates/javascript/service/service.js @@ -1,6 +1,6 @@ 'use strict'; -angular.module('<%= _.camelize(appname) %>App') - .service('<%= _.classify(name) %>', function <%= _.classify(name) %>() { +angular.module('<%= scriptAppName %>') + .service('<%= classedName %>', function <%= classedName %>() { // AngularJS will instantiate a singleton by calling "new" on this function }); diff --git a/templates/javascript/service/value.js b/templates/javascript/service/value.js index 90f219727..01507e03f 100644 --- a/templates/javascript/service/value.js +++ b/templates/javascript/service/value.js @@ -1,4 +1,4 @@ 'use strict'; -angular.module('<%= _.camelize(appname) %>App') - .value('<%= _.camelize(name) %>', 42); +angular.module('<%= scriptAppName %>') + .value('<%= cameledName %>', 42); diff --git a/templates/javascript/spec/controller.js b/templates/javascript/spec/controller.js index 6545c70f2..95005029e 100644 --- a/templates/javascript/spec/controller.js +++ b/templates/javascript/spec/controller.js @@ -1,17 +1,17 @@ 'use strict'; -describe('Controller: <%= _.classify(name) %>Ctrl', function () { +describe('Controller: <%= classedName %>Ctrl', function () { // load the controller's module - beforeEach(module('<%= _.camelize(appname) %>App')); + beforeEach(module('<%= scriptAppName %>')); - var <%= _.classify(name) %>Ctrl, + var <%= classedName %>Ctrl, scope; // Initialize the controller and a mock scope beforeEach(inject(function ($controller, $rootScope) { scope = $rootScope.$new(); - <%= _.classify(name) %>Ctrl = $controller('<%= _.classify(name) %>Ctrl', { + <%= classedName %>Ctrl = $controller('<%= classedName %>Ctrl', { $scope: scope }); })); diff --git a/templates/javascript/spec/directive.js b/templates/javascript/spec/directive.js index f0e12fb13..fbe52519c 100644 --- a/templates/javascript/spec/directive.js +++ b/templates/javascript/spec/directive.js @@ -1,9 +1,9 @@ 'use strict'; -describe('Directive: <%= _.camelize(name) %>', function () { +describe('Directive: <%= cameledName %>', function () { // load the directive's module - beforeEach(module('<%= _.camelize(appname) %>App')); + beforeEach(module('<%= scriptAppName %>')); var element, scope; @@ -15,6 +15,6 @@ describe('Directive: <%= _.camelize(name) %>', function () { it('should make hidden element visible', inject(function ($compile) { element = angular.element('<<%= _.dasherize(name) %>>>'); element = $compile(element)(scope); - expect(element.text()).toBe('this is the <%= _.camelize(name) %> directive'); + expect(element.text()).toBe('this is the <%= cameledName %> directive'); })); }); diff --git a/templates/javascript/spec/filter.js b/templates/javascript/spec/filter.js index 4344127de..7fbea7257 100644 --- a/templates/javascript/spec/filter.js +++ b/templates/javascript/spec/filter.js @@ -1,19 +1,19 @@ 'use strict'; -describe('Filter: <%= _.camelize(name) %>', function () { +describe('Filter: <%= cameledName %>', function () { // load the filter's module - beforeEach(module('<%= _.camelize(appname) %>App')); + beforeEach(module('<%= scriptAppName %>')); // initialize a new instance of the filter before each test - var <%= _.camelize(name) %>; + var <%= cameledName %>; beforeEach(inject(function ($filter) { - <%= _.camelize(name) %> = $filter('<%= _.camelize(name) %>'); + <%= cameledName %> = $filter('<%= cameledName %>'); })); - it('should return the input prefixed with "<%= _.camelize(name) %> filter:"', function () { + it('should return the input prefixed with "<%= cameledName %> filter:"', function () { var text = 'angularjs'; - expect(<%= _.camelize(name) %>(text)).toBe('<%= _.camelize(name) %> filter: ' + text); + expect(<%= cameledName %>(text)).toBe('<%= cameledName %> filter: ' + text); }); }); diff --git a/templates/javascript/spec/service.js b/templates/javascript/spec/service.js index e3c6c83d0..c4a6898a2 100644 --- a/templates/javascript/spec/service.js +++ b/templates/javascript/spec/service.js @@ -1,18 +1,18 @@ 'use strict'; -describe('Service: <%= _.classify(name) %>', function () { +describe('Service: <%= classedName %>', function () { // load the service's module - beforeEach(module('<%= _.classify(appname) %>App')); + beforeEach(module('<%= scriptAppName %>App')); // instantiate service - var <%= _.classify(name) %>; - beforeEach(inject(function (_<%= _.classify(name) %>_) { - <%= _.classify(name) %> = _<%= _.classify(name) %>_; + var <%= classedName %>; + beforeEach(inject(function (_<%= classedName %>_) { + <%= classedName %> = _<%= classedName %>_; })); it('should do something', function () { - expect(!!<%= _.classify(name) %>).toBe(true); + expect(!!<%= classedName %>).toBe(true); }); }); diff --git a/test/test-appname-substitution.js b/test/test-appname-substitution.js index 925bd2266..5951d8011 100644 --- a/test/test-appname-substitution.js +++ b/test/test-appname-substitution.js @@ -34,7 +34,7 @@ describe('Angular generator template mechanism', function () { }); it('should generate the same appName in every file', function (done) { - var expectedAppName = folderName + 'App'; + var expectedAppName = 'upperCaseBugApp'; var expected = [ 'app/scripts/app.js', 'app/scripts/controllers/main.js', diff --git a/util.js b/util.js index 5334e3c6e..ca9a74352 100644 --- a/util.js +++ b/util.js @@ -5,7 +5,8 @@ var fs = require('fs'); module.exports = { rewrite: rewrite, - rewriteFile: rewriteFile + rewriteFile: rewriteFile, + appName: appName }; function rewriteFile (args) { @@ -57,3 +58,17 @@ function rewrite (args) { return lines.join('\n'); } + +function appName (self) { + var counter = 0, suffix = self.options['app-suffix']; + // Have to check this because of generator bug #386 + process.argv.forEach(function(val) { + if (val.indexOf('--app-suffix') > -1) { + counter++; + } + }); + if (counter === 0 || (typeof suffix === 'boolean' && suffix)) { + suffix = 'App'; + } + return suffix ? self._.classify(suffix) : ''; +}