Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style(templates:coffee): cleanup & consistency fix of .coffee files #3

Merged
merged 1 commit into from
Jul 20, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion templates/controller/name.controller.coffee
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
'use strict'

angular.module('<%= scriptAppName %>').controller '<%= classedName %>Ctrl', ($scope) ->
angular.module '<%= scriptAppName %>'
.controller '<%= classedName %>Ctrl', ($scope) ->
$scope.message = 'Hello'
9 changes: 4 additions & 5 deletions templates/controller/name.controller.spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@
describe 'Controller: <%= classedName %>Ctrl', ->

# load the controller's module
beforeEach module('<%= scriptAppName %>')
beforeEach module '<%= scriptAppName %>'
<%= classedName %>Ctrl = undefined
scope = undefined

# Initialize the controller and a mock scope
beforeEach inject(($controller, $rootScope) ->
beforeEach inject ($controller, $rootScope) ->
scope = $rootScope.$new()
<%= classedName %>Ctrl = $controller('<%= classedName %>Ctrl',
<%= classedName %>Ctrl = $controller '<%= classedName %>Ctrl',
$scope: scope
)
)

it 'should ...', ->
expect(1).toEqual 1
5 changes: 3 additions & 2 deletions templates/decorator/name.decorator.coffee
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict'

angular.module("<%= scriptAppName %>").config ($provide) ->
$provide.decorator "<%= cameledName %>", ($delegate) ->
angular.module '<%= scriptAppName %>'
.config ($provide) ->
$provide.decorator '<%= cameledName %>', ($delegate) ->
# decorate the $delegate
$delegate
3 changes: 2 additions & 1 deletion templates/directiveComplex/name.directive.coffee
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict'

angular.module('<%= scriptAppName %>').directive '<%= cameledName %>', ->
angular.module '<%= scriptAppName %>'
.directive '<%= cameledName %>', ->
templateUrl: '<%= htmlUrl %>'
restrict: 'EA'
link: (scope, element, attrs) ->
16 changes: 8 additions & 8 deletions templates/directiveComplex/name.directive.spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
describe 'Directive: <%= cameledName %>', ->

# load the directive's module and view
beforeEach module('<%= scriptAppName %>')
beforeEach module('<%= htmlUrl %>')
beforeEach module '<%= scriptAppName %>'
beforeEach module '<%= htmlUrl %>'
element = undefined
scope = undefined
beforeEach inject(($rootScope) ->
beforeEach inject ($rootScope) ->
scope = $rootScope.$new()
)
it 'should make hidden element visible', inject(($compile) ->
element = angular.element('<<%= _.dasherize(name) %>></<%= _.dasherize(name) %>>')
element = $compile(element)(scope)

it 'should make hidden element visible', inject ($compile) ->
element = angular.element '<<%= _.dasherize(name) %>></<%= _.dasherize(name) %>>'
element = $compile(element) scope
scope.$apply()
expect(element.text()).toBe 'this is the <%= cameledName %> directive'
)

3 changes: 2 additions & 1 deletion templates/directiveSimple/name.directive.coffee
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict'

angular.module('<%= scriptAppName %>').directive '<%= cameledName %>', ->
angular.module '<%= scriptAppName %>'
.directive '<%= cameledName %>', ->
template: '<div></div>'
restrict: 'EA'
link: (scope, element, attrs) ->
Expand Down
13 changes: 6 additions & 7 deletions templates/directiveSimple/name.directive.spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
describe 'Directive: <%= cameledName %>', ->

# load the directive's module
beforeEach module('<%= scriptAppName %>')
beforeEach module '<%= scriptAppName %>'
element = undefined
scope = undefined
beforeEach inject(($rootScope) ->
beforeEach inject ($rootScope) ->
scope = $rootScope.$new()
)
it 'should make hidden element visible', inject(($compile) ->
element = angular.element('<<%= _.dasherize(name) %>></<%= _.dasherize(name) %>>')
element = $compile(element)(scope)

it 'should make hidden element visible', inject ($compile) ->
element = angular.element '<<%= _.dasherize(name) %>></<%= _.dasherize(name) %>>'
element = $compile(element) scope
expect(element.text()).toBe 'this is the <%= cameledName %> directive'
)
3 changes: 2 additions & 1 deletion templates/factory/name.service.coffee
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict'

angular.module('<%= scriptAppName %>').factory '<%= cameledName %>', ->
angular.module '<%= scriptAppName %>'
.factory '<%= cameledName %>', ->

# Service logic
# ...
Expand Down
6 changes: 3 additions & 3 deletions templates/factory/name.service.spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
describe 'Service: <%= cameledName %>', ->

# load the service's module
beforeEach module('<%= scriptAppName %>')
beforeEach module '<%= scriptAppName %>'

# instantiate service
<%= cameledName %> = undefined
beforeEach inject((_<%= cameledName %>_) ->
beforeEach inject (_<%= cameledName %>_) ->
<%= cameledName %> = _<%= cameledName %>_
)

it 'should do something', ->
expect(!!<%= cameledName %>).toBe true
3 changes: 2 additions & 1 deletion templates/filter/name.filter.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict'

angular.module('<%= scriptAppName %>').filter '<%= cameledName %>', ->
angular.module '<%= scriptAppName %>'
.filter '<%= cameledName %>', ->
(input) ->
'<%= cameledName %> filter: ' + input
10 changes: 5 additions & 5 deletions templates/filter/name.filter.spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
describe 'Filter: <%= cameledName %>', ->

# load the filter's module
beforeEach module('<%= scriptAppName %>')
beforeEach module '<%= scriptAppName %>'

# initialize a new instance of the filter before each test
<%= cameledName %> = undefined
beforeEach inject(($filter) ->
<%= cameledName %> = $filter('<%= cameledName %>')
)
beforeEach inject ($filter) ->
<%= cameledName %> = $filter '<%= cameledName %>'

it 'should return the input prefixed with \'<%= cameledName %> filter:\'', ->
text = 'angularjs'
expect(<%= cameledName %>(text)).toBe '<%= cameledName %> filter: ' + text
expect(<%= cameledName %> text).toBe '<%= cameledName %> filter: ' + text
30 changes: 15 additions & 15 deletions templates/provider/name.service.coffee
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
'use strict'

angular.module('<%= scriptAppName %>')
.provider '<%= cameledName %>', ->
angular.module '<%= scriptAppName %>'
.provider '<%= cameledName %>', ->

# Private variables
salutation = 'Hello'
# Private variables
salutation = 'Hello'

# Private constructor
class Greeter
@greet = ->
salutation
# Private constructor
class Greeter
@greet = ->
salutation

# Public API for configuration
@setSalutation = (s) ->
salutation = s
# Public API for configuration
@setSalutation = (s) ->
salutation = s

# Method for instantiating
@$get = ->
new Greeter()
# Method for instantiating
@$get = ->
new Greeter()

return
return
6 changes: 3 additions & 3 deletions templates/provider/name.service.spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
describe 'Service: <%= cameledName %>', ->

# load the service's module
beforeEach module('<%= scriptAppName %>')
beforeEach module '<%= scriptAppName %>'

# instantiate service
<%= cameledName %> = undefined
beforeEach inject((_<%= cameledName %>_) ->
beforeEach inject (_<%= cameledName %>_) ->
<%= cameledName %> = _<%= cameledName %>_
)

it 'should do something', ->
expect(!!<%= cameledName %>).toBe true
3 changes: 2 additions & 1 deletion templates/route/name(ngroute).coffee
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict'

angular.module('<%= scriptAppName %>').config ($routeProvider) ->
angular.module '<%= scriptAppName %>'
.config ($routeProvider) ->
$routeProvider.when '<%= route %>',
templateUrl: '<%= htmlUrl %>'
controller: '<%= classedName %>Ctrl'
3 changes: 2 additions & 1 deletion templates/route/name(uirouter).coffee
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict'

angular.module('<%= scriptAppName %>').config ($stateProvider) ->
angular.module '<%= scriptAppName %>'
.config ($stateProvider) ->
$stateProvider.state '<%= name %>',
url: '<%= route %>'
templateUrl: '<%= htmlUrl %>'
Expand Down
3 changes: 2 additions & 1 deletion templates/route/name.controller.coffee
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
'use strict'

angular.module('<%= scriptAppName %>').controller '<%= classedName %>Ctrl', ($scope) ->
angular.module '<%= scriptAppName %>'
.controller '<%= classedName %>Ctrl', ($scope) ->
$scope.message = 'Hello'
9 changes: 4 additions & 5 deletions templates/route/name.controller.spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@
describe 'Controller: <%= classedName %>Ctrl', ->

# load the controller's module
beforeEach module('<%= scriptAppName %>')
beforeEach module '<%= scriptAppName %>'
<%= classedName %>Ctrl = undefined
scope = undefined

# Initialize the controller and a mock scope
beforeEach inject(($controller, $rootScope) ->
beforeEach inject ($controller, $rootScope) ->
scope = $rootScope.$new()
<%= classedName %>Ctrl = $controller('<%= classedName %>Ctrl',
<%= classedName %>Ctrl = $controller '<%= classedName %>Ctrl',
$scope: scope
)
)

it 'should ...', ->
expect(1).toEqual 1
3 changes: 2 additions & 1 deletion templates/service/name.service.coffee
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
'use strict'

angular.module('<%= scriptAppName %>').service '<%= classedName %>', <%= classedName %> = ->
angular.module '<%= scriptAppName %>'
.service '<%= classedName %>', <%= classedName %> = ->
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DaftMonk Any particular reason why we need to "name" function in a second parameter?

This regards to JS version as well:

angular.module('<%= scriptAppName %>')
  .service('<%= classedName %>', function <%= IS_THIS_NAME_NEEDED? %>() {
    // AngularJS will instantiate a singleton by calling "new" on this function
  });

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, actually that second name isn't really necessary.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also we should change that to use cameledName name rather than classedName.

# AngularJS will instantiate a singleton by calling 'new' on this function
6 changes: 3 additions & 3 deletions templates/service/name.service.spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
describe 'Service: <%= classedName %>', ->

# load the service's module
beforeEach module('<%= scriptAppName %>')
beforeEach module '<%= scriptAppName %>'

# instantiate service
<%= classedName %> = undefined
beforeEach inject((_<%= classedName %>_) ->
beforeEach inject (_<%= classedName %>_) ->
<%= classedName %> = _<%= classedName %>_
)

it 'should do something', ->
expect(!!<%= classedName %>).toBe true