angularjs_scaffold 0.0.23 → 0.0.24

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -30,22 +30,4 @@ Now run the angularjs:scaffold command and it will rewrite everything the Angula
30
30
 
31
31
  $ rails g angularjs:scaffold Posts # adds everything needed using AngularJS
32
32
 
33
- The "AngularJS way", in my opinion, follows the Unobtrusive Javascript paradigm, but uses CoffeeScript in place of Javascript. To me, Javascript is like programming in Assembler, while CoffeeScript is much more readable, and produces very high quality JS as output. When combined with the Rails asset pipeline, CoffeeScript has a lot of advantages, and little or no downside. What's not to like? But, you have the install-time option --language=javascript.
34
-
35
- The name given the AngularJS app is based on the Rails app name, plus 'Client', so a rails app named 'Sue' would deploy an AngularJS app 'SueClient' to the browser.
36
-
37
- Another change I made to this scaffold is adding the .erb extension on the generated template files, so
38
-
39
- index.html
40
-
41
- becomes
42
-
43
- index.html.erb
44
-
45
- No big deal, but this makes it clear that the AngularJS templates can take advantage of 'server-side provisioning'. If that term is unclear, I suggest you look at the file
46
-
47
- routes.coffee.erb
48
-
49
- where the AngularJS routes are populated by Rails route helpers. It just makes sense that the server should specify to the view how it should be accessed.
50
-
51
33
  Enjoy!
@@ -1,3 +1,3 @@
1
1
  module AngularjsScaffold
2
- VERSION = "0.0.23"
2
+ VERSION = "0.0.24"
3
3
  end
@@ -1,15 +1,19 @@
1
- angular.module('<%= @plural_model_name%>', ['ngResource']).
2
- factory('<%= @model_name%>', ['$resource', function($resource) {
3
- var <%= @model_name%> = $resource('/<%= @plural_model_name%>/:id', {id: '@id'},
4
- {
5
- update: { method: 'PUT' },
6
- destroy: { method: 'DELETE'}
7
- }
8
- );
1
+ angular.module("<%= @plural_model_name %>", ["ngResource"]).
2
+ factory("<%= @model_name %>", ['$resource', function($resource) {
3
+ var <%= @model_name %>;
4
+ <%= @model_name %> = $resource("/<%= @plural_model_name %>/:id",
5
+ { id: "@id" },
6
+ {
7
+ update: { method: "PUT" },
8
+ destroy: { method: "DELETE" }
9
+ });
9
10
 
10
- <%= @model_name%>.prototype.destroy = function(cb) {
11
- return <%= @model_name%>.remove({id: this.id}, cb);
12
- };
11
+ <%= @model_name %>.prototype.destroy = function(cb) {
12
+ return <%= @model_name %>.remove({
13
+ id: this.id
14
+ }, cb);
15
+ };
13
16
 
14
- return <%= @model_name%>;
15
- }]);
17
+ return <%= @model_name %>;
18
+ }
19
+ ]);
@@ -1,63 +1,71 @@
1
- function <%= @controller%>IndexCtrl($scope, <%= @model_name%>) {
2
- $scope.<%= @plural_model_name %> = <%= @model_name%>.query();
3
-
4
- $scope.destroy = function() {
5
- dconfirm = confirm('Are you sure?');
6
- if(dconfirm){
7
- var original = this.<%= @resource_name%>
8
- this.<%= @resource_name%>.destroy(function() {
9
- $scope.<%= @plural_model_name %> = _.without($scope.<%= @plural_model_name%>, original);
1
+ <%= @controller %>IndexCtrl = function($scope, <%= @model_name %>) {
2
+ $scope.<%= @plural_model_name %> = <%= @model_name %>.query();
3
+
4
+ return $scope.destroy = function() {
5
+ var original;
6
+ if (confirm("Are you sure?")) {
7
+ original = this.<%= @resource_name %>;
8
+ return this.<%= @resource_name %>.destroy(function() {
9
+ return $scope.<%= @plural_model_name %> = _.without($scope.<%= @plural_model_name %>, original);
10
10
  });
11
11
  }
12
12
  };
13
- }
13
+ };
14
14
 
15
- <%= @controller%>IndexCtrl.$inject = ['$scope', '<%= @model_name%>'];
15
+ <%= @controller %>IndexCtrl.$inject = ['$scope', '<%= @model_name %>'];
16
16
 
17
- function <%= @controller%>CreateCtrl($scope, $location, <%= @model_name%>) {
18
- $scope.save = function() {
19
- <%= @model_name%>.save($scope.<%= @resource_name%>, function(<%= @resource_name%>) {
20
- $location.path('/<%= @plural_model_name %>/' + <%= @resource_name%>.id + '/edit');
17
+ <%= @controller %>CreateCtrl = function($scope, $location, <%= @model_name %>) {
18
+ return $scope.save = function() {
19
+ return <%= @model_name %>.save($scope.<%= @resource_name %>, function(<%= @resource_name %>) {
20
+ return $location.path("/<%= @plural_model_name %>/" + <%= @resource_name %>.id + "/edit");
21
21
  });
22
- }
23
- }
24
-
25
- <%= @controller%>CreateCtrl.$inject = ['$scope', '$location', '<%= @model_name%>'];
22
+ };
23
+ };
26
24
 
27
- function <%= @controller%>ShowCtrl($scope, $location, $routeParams, <%= @model_name%>) {
28
- <%= @model_name%>.get({id: $routeParams.id}, function(<%= @resource_name%>) {
29
- self.original = <%= @resource_name%>;
30
- $scope.<%= @resource_name%> = new <%= @model_name%>(self.original);
31
- });
32
- }
25
+ <%= @controller %>CreateCtrl.$inject = ['$scope', '$location', '<%= @model_name %>'];
33
26
 
34
- <%= @controller%>ShowCtrl.$inject = ['$scope', '$location', '$routeParams', '<%= @model_name%>'];
27
+ <%= @controller %>ShowCtrl = function($scope, $location, $routeParams, <%= @model_name %>) {
28
+ <%= @model_name %>.get({
29
+ id: $routeParams.id
30
+ }, function(<%= @resource_name %>) {
31
+ this.original = <%= @resource_name %>;
32
+ return $scope.<%= @resource_name %> = new <%= @model_name %>(this.original);
33
+ });
34
+ return $scope.destroy = function() {
35
+ if (confirm("Are you sure?")) {
36
+ return $scope.<%= @resource_name %>.destroy(function() {
37
+ return $location.path("/<%= @plural_model_name %>");
38
+ });
39
+ }
40
+ };
41
+ };
35
42
 
36
- function <%= @controller%>EditCtrl($scope, $location, $routeParams, <%= @model_name%>) {
37
- var self = this;
43
+ <%= @controller %>ShowCtrl.$inject = ['$scope', '$location', '$routeParams', '<%= @model_name %>'];
38
44
 
39
- <%= @model_name%>.get({id: $routeParams.id}, function(<%= @resource_name%>) {
40
- self.original = <%= @resource_name%>;
41
- $scope.<%= @resource_name%> = new <%= @model_name%>(self.original);
45
+ <%= @controller %>EditCtrl = function($scope, $location, $routeParams, <%= @model_name %>) {
46
+ <%= @model_name %>.get({
47
+ id: $routeParams.id
48
+ }, function(<%= @resource_name %>) {
49
+ this.original = <%= @resource_name %>;
50
+ return $scope.<%= @resource_name %> = new <%= @model_name %>(this.original);
42
51
  });
43
-
44
52
  $scope.isClean = function() {
45
- return angular.equals(self.original, $scope.<%= @resource_name%>);
46
- }
47
-
53
+ return angular.equals(this.original, $scope.<%= @resource_name %>);
54
+ };
48
55
  $scope.destroy = function() {
49
- dconfirm = confirm('Are you sure?');
50
- if(dconfirm){
51
- $scope.<%= @resource_name %>.destroy(function() {
52
- $location.path('/<%= @plural_model_name %>');
53
- });}
56
+ if (confirm("Are you sure?")) {
57
+ return $scope.<%= @resource_name %>.destroy(function() {
58
+ return $location.path("/<%= @plural_model_name %>");
59
+ });
60
+ }
54
61
  };
55
-
56
- $scope.save = function() {
57
- <%= @model_name%>.update($scope.<%= @resource_name%>, function(<%= @resource_name%>) {
58
- $location.path('/<%= @plural_model_name %>');
62
+ return $scope.save = function() {
63
+ return <%= @model_name %>.update($scope.<%= @resource_name %>, function(<%= @resource_name %>) {
64
+ return $location.path("/<%= @plural_model_name %>");
59
65
  });
60
66
  };
61
- }
67
+ };
68
+
69
+ <%= @controller %>EditCtrl.$inject = ['$scope', '$location', '$routeParams', '<%= @model_name %>'];
70
+
62
71
 
63
- <%= @controller%>EditCtrl.$inject = ['$scope', '$location', '$routeParams', '<%= @model_name%>'];
@@ -1,59 +1,62 @@
1
1
 
2
2
  root = global ? window
3
3
 
4
- <%= @controller%>IndexCtrl = ($scope, <%= @model_name%>) ->
5
- $scope.<%= @plural_model_name %> = <%= @model_name%>.query()
4
+ <%= @controller %>IndexCtrl = ($scope, <%= @model_name %>) ->
5
+ $scope.<%= @plural_model_name %> = <%= @model_name %>.query()
6
+
6
7
  $scope.destroy = ->
7
- dconfirm = confirm("Are you sure?")
8
- if dconfirm
9
- original = @<%= @resource_name%>
10
- @<%= @resource_name%>.destroy ->
8
+ if confirm("Are you sure?")
9
+ original = @<%= @resource_name %>
10
+ @<%= @resource_name %>.destroy ->
11
11
  $scope.<%= @plural_model_name %> = _.without($scope.<%= @plural_model_name %>, original)
12
+
13
+ <%= @controller %>IndexCtrl.$inject = ['$scope', '<%= @model_name %>'];
12
14
 
13
- <%= @controller%>IndexCtrl.$inject = ['$scope', '<%= @model_name%>'];
14
-
15
- <%= @controller%>CreateCtrl = ($scope, $location, <%= @model_name%>) ->
15
+ <%= @controller %>CreateCtrl = ($scope, $location, <%= @model_name %>) ->
16
16
  $scope.save = ->
17
- <%= @model_name%>.save $scope.<%= @resource_name%>, (<%= @resource_name%>) ->
18
- $location.path "/<%= @plural_model_name %>/#{<%= @resource_name%>.id}/edit"
17
+ <%= @model_name %>.save $scope.<%= @resource_name %>, (<%= @resource_name %>) ->
18
+ $location.path "/<%= @plural_model_name %>/#{<%= @resource_name %>.id}/edit"
19
19
 
20
- <%= @controller%>CreateCtrl.$inject = ['$scope', '$location', '<%= @model_name%>'];
20
+ <%= @controller %>CreateCtrl.$inject = ['$scope', '$location', '<%= @model_name %>'];
21
21
 
22
- <%= @controller%>ShowCtrl = ($scope, $location, $routeParams, <%= @model_name%>) ->
23
- <%= @model_name%>.get
22
+ <%= @controller %>ShowCtrl = ($scope, $location, $routeParams, <%= @model_name %>) ->
23
+ <%= @model_name %>.get
24
24
  id: $routeParams.id
25
- , (<%= @resource_name%>) ->
26
- self.original = <%= @resource_name%>
27
- $scope.<%= @resource_name%> = new <%= @model_name%>(self.original)
25
+ , (<%= @resource_name %>) ->
26
+ @original = <%= @resource_name %>
27
+ $scope.<%= @resource_name %> = new <%= @model_name %>(@original)
28
+
29
+ $scope.destroy = ->
30
+ if confirm("Are you sure?")
31
+ $scope.<%= @resource_name %>.destroy ->
32
+ $location.path "/<%= @plural_model_name %>"
28
33
 
29
- <%= @controller%>ShowCtrl.$inject = ['$scope', '$location', '$routeParams', '<%= @model_name%>'];
34
+ <%= @controller %>ShowCtrl.$inject = ['$scope', '$location', '$routeParams', '<%= @model_name %>'];
30
35
 
31
- <%= @controller%>EditCtrl = ($scope, $location, $routeParams, <%= @model_name%>) ->
32
- self = this
33
- <%= @model_name%>.get
36
+ <%= @controller %>EditCtrl = ($scope, $location, $routeParams, <%= @model_name %>) ->
37
+ <%= @model_name %>.get
34
38
  id: $routeParams.id
35
- , (<%= @resource_name%>) ->
36
- self.original = <%= @resource_name%>
37
- $scope.<%= @resource_name%> = new <%= @model_name%>(self.original)
39
+ , (<%= @resource_name %>) ->
40
+ @original = <%= @resource_name %>
41
+ $scope.<%= @resource_name %> = new <%= @model_name %>(@original)
38
42
 
39
43
  $scope.isClean = ->
40
- angular.equals self.original, $scope.<%= @resource_name%>
44
+ console.log "[<%= @controller %>EditCtrl, $scope.isClean]"
45
+ angular.equals @original, $scope.<%= @resource_name %>
41
46
 
42
47
  $scope.destroy = ->
43
- dconfirm = confirm("Are you sure?")
44
- if dconfirm
45
- $scope.<%= @resource_name%>.destroy ->
48
+ if confirm("Are you sure?")
49
+ $scope.<%= @resource_name %>.destroy ->
46
50
  $location.path "/<%= @plural_model_name %>"
47
51
 
48
-
49
52
  $scope.save = ->
50
- <%= @model_name%>.update $scope.<%= @resource_name%>, (<%= @resource_name%>) ->
53
+ <%= @model_name %>.update $scope.<%= @resource_name %>, (<%= @resource_name %>) ->
51
54
  $location.path "/<%= @plural_model_name %>"
52
55
 
53
- <%= @controller%>EditCtrl.$inject = ['$scope', '$location', '$routeParams', '<%= @model_name%>'];
56
+ <%= @controller %>EditCtrl.$inject = ['$scope', '$location', '$routeParams', '<%= @model_name %>'];
54
57
 
55
58
  # exports
56
- root.<%= @controller%>IndexCtrl = <%= @controller%>IndexCtrl
57
- root.<%= @controller%>CreateCtrl = <%= @controller%>CreateCtrl
58
- root.<%= @controller%>ShowCtrl = <%= @controller%>ShowCtrl
59
- root.<%= @controller%>EditCtrl = <%= @controller%>EditCtrl
59
+ root.<%= @controller %>IndexCtrl = <%= @controller %>IndexCtrl
60
+ root.<%= @controller %>CreateCtrl = <%= @controller %>CreateCtrl
61
+ root.<%= @controller %>ShowCtrl = <%= @controller %>ShowCtrl
62
+ root.<%= @controller %>EditCtrl = <%= @controller %>EditCtrl
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: angularjs_scaffold
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.23
4
+ version: 0.0.24
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,24 +10,24 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-01-21 00:00:00.000000000 Z
13
+ date: 2013-02-07 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails
17
17
  requirement: !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
- - - ~>
20
+ - - ! '>='
21
21
  - !ruby/object:Gem::Version
22
- version: 3.2.6
22
+ version: 3.2.11
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  none: false
27
27
  requirements:
28
- - - ~>
28
+ - - ! '>='
29
29
  - !ruby/object:Gem::Version
30
- version: 3.2.6
30
+ version: 3.2.11
31
31
  - !ruby/object:Gem::Dependency
32
32
  name: sqlite3
33
33
  requirement: !ruby/object:Gem::Requirement