explainer_angularjs_scaffold 0.0.21 → 0.0.22

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,3 @@
1
1
  module AngularjsScaffold
2
- VERSION = "0.0.21"
2
+ VERSION = "0.0.22"
3
3
  end
@@ -11,8 +11,19 @@ module Angularjs
11
11
  desc: "Choose your preferred language, 'coffeescript' or 'javascript' "
12
12
 
13
13
  def init_angularjs
14
- copy_file "application.css", "app/assets/stylesheets/application.css"
15
- copy_file "application.js", "app/assets/javascripts/application.js"
14
+ if File.exist?('app/assets/javascripts/application.js')
15
+ insert_into_file "app/assets/javascripts/application.js",
16
+ "//= require_tree ./angularjs/\n", :after => "jquery_ujs\n"
17
+ else
18
+ copy_file "application.js", "app/assets/javascripts/application.js"
19
+ end
20
+ @application_css_file ='app/assets/stylesheets/application.css'
21
+ if (!(File.exist?('app/assets/stylesheets/application.css')) &&
22
+ File.exist?('app/assets/stylesheets/application.css.scss'))
23
+ @application_css_file ='app/assets/stylesheets/application.css.scss'
24
+ elsif !File.exist?('app/assets/stylesheets/application.css')
25
+ create_file @application_css_file
26
+ end
16
27
  directory "underscore", "app/assets/javascripts/underscore/"
17
28
  directory "angularjs", "app/assets/javascripts/angularjs/"
18
29
  if options["no-jquery"]
@@ -32,15 +43,15 @@ module Angularjs
32
43
  directory "bootstrap/css", "app/assets/stylesheets/bootstrap/"
33
44
  directory "bootstrap/js", "app/assets/javascripts/bootstrap/"
34
45
  directory "bootstrap/img", "app/assets/javascripts/img/"
35
- insert_into_file "app/assets/stylesheets/application.css",
36
- " *= require bootstrap/bootstrap.min.css\n", after: "require_self\n"
37
- insert_into_file "app/assets/stylesheets/application.css",
46
+ insert_into_file @application_css_file,
47
+ " *= require bootstrap/bootstrap.min.css\n", :after => "require_self\n"
48
+ insert_into_file @application_css_file,
38
49
  " *= require bootstrap/bootstrap-responsive.min.css\n",
39
- after: "bootstrap.min.css\n"
40
- insert_into_file "app/assets/stylesheets/application.css",
50
+ :after => "bootstrap.min.css\n"
51
+ insert_into_file @application_css_file,
41
52
  " *= require fontawesome/font-awesome.css\n",
42
- after: "bootstrap-responsive.min.css\n"
43
- append_to_file "app/assets/stylesheets/application.css",
53
+ :after => "bootstrap-responsive.min.css\n"
54
+ append_to_file @application_css_file,
44
55
  "\nbody { padding-top: 60px; }\n"
45
56
  unless options["no-jquery"]
46
57
  insert_into_file "app/assets/javascripts/application.js",
@@ -58,9 +69,7 @@ module Angularjs
58
69
  end
59
70
 
60
71
  def generate_welcome_controller
61
- @app_name = Rails.application.class.parent_name
62
- #Rails.logger.info "#{__FILE__}, #{__LINE__}, @app_name: #{@app_name}"
63
- remove_file "public/index.html"
72
+ remove_file "public/index.html"
64
73
  uncomment_lines 'config/routes.rb', /root :to => 'welcome#index'/
65
74
  run "rails g controller welcome index"
66
75
  copy_file "AngularJS-medium.png", "app/assets/images/AngularJS-medium.png"
@@ -69,8 +78,9 @@ module Angularjs
69
78
  empty_directory "app/assets/templates/welcome"
70
79
  copy_file "index_welcome.html.erb", "app/assets/templates/welcome/index.html.erb"
71
80
  if @language == 'coffeescript'
72
- remove_file 'app/assets/javascripts/routes.js.erb'
73
- # Rails.logger.info "#{__FILE__}, #{__LINE__}, @app_name: #{@app_name}"
81
+ if File.exists?('app/assets/javascripts/routes.js.erb')
82
+ remove_file 'app/assets/javascripts/routes.js.erb'
83
+ end
74
84
  copy_file "routes.coffee.erb", "app/assets/javascripts/routes.coffee.erb"
75
85
  insert_into_file "app/assets/javascripts/routes.coffee.erb", @app_name, before: 'Client'
76
86
  ['csrf', 'welcome'].each do |prefix|
@@ -80,7 +90,9 @@ module Angularjs
80
90
  end
81
91
  # insert_into_file "app/assets/javascripts/welcome_controller.js.coffee", @app_name, before: 'Client'
82
92
  else # javascript
83
- remove_file 'app/assets/javascripts/routes.coffee.erb' #if File.exists?('app/assets/javascripts/routes.coffee.erb')
93
+ if File.exists?('app/assets/javascripts/routes.coffee.erb')
94
+ remove_file 'app/assets/javascripts/routes.coffee.erb'
95
+ end
84
96
  copy_file "routes.js.erb", "app/assets/javascripts/routes.js.erb" #if File.exists?("app/assets/javascripts/routes.js.erb")
85
97
  # Rails.logger.info "#{__FILE__}, #{__LINE__}, @app_name: #{@app_name}"
86
98
  insert_into_file "app/assets/javascripts/routes.js.erb", @app_name, before: 'Client'
@@ -91,11 +103,11 @@ module Angularjs
91
103
  end
92
104
  # insert_into_file "app/assets/javascripts/welcome_controller.js", @app_name, before: 'Client'
93
105
  end
94
- append_to_file "app/assets/javascripts/application.js",
95
- "//= require routes\n"
96
- append_to_file "app/assets/javascripts/application.js",
97
- "//= require welcome_controller\n"
98
- append_to_file "app/assets/stylesheets/application.css",
106
+ # append_to_file "app/assets/javascripts/application.js",
107
+ # "//= require routes\n"
108
+ # append_to_file "app/assets/javascripts/application.js",
109
+ # "//= require welcome_controller\n"
110
+ append_to_file @application_css_file,
99
111
  ".center {text-align: center;}\n"
100
112
  insert_into_file "app/controllers/application_controller.rb",
101
113
  %{
@@ -49,9 +49,13 @@
49
49
  <!-- templates load here -->
50
50
  <div class="span3">
51
51
  <div class="well sidebar-nav">
52
+ <h3>Sidebar</h3>
52
53
  <ul class="nav nav-list">
53
54
  <li class="nav-header">Sidebar</li>
54
55
  <!-- sidebar menu models -->
56
+ <li><%%= link_to "Link1", "/path1" %></li>
57
+ <li><%%= link_to "Link2", "/path2" %></li>
58
+ <li><%%= link_to "Link3", "/path3" %></li>
55
59
  </ul>
56
60
  </div><!--/.well -->
57
61
  </div><!--/span-->
@@ -14,7 +14,4 @@
14
14
  //= require jquery_ujs
15
15
  //= require_tree ./underscore/
16
16
  //= require_tree ./angularjs/
17
- //= require_tree ./bootstrap/
18
- //= require_tree .
19
- //= require routes
20
- //= require welcome_controller
17
+
@@ -1,15 +1,18 @@
1
1
  // Generated by CoffeeScript 1.4.0
2
+
2
3
  (function() {
3
- var CsrfCtrl, root;
4
+ var CsrfCtrl, angular, root;
4
5
 
5
6
  root = typeof global !== "undefined" && global !== null ? global : window;
6
7
 
7
- CsrfCtrl = [
8
- "$cookieStore", function($cookieStore) {
9
- return $cookieStore.put("XSRF-TOKEN", angular.element(document.getElementById("csrf")).attr("data-csrf"));
10
- }
11
- ];
12
- // exports
8
+ angular = root.angular;
9
+
10
+ CsrfCtrl = function($cookieStore) {
11
+ return $cookieStore.put("XSRF-TOKEN", angular.element(document.getElementById("csrf")).attr("data-csrf"));
12
+ };
13
+
14
+ CsrfCtrl.$inject = ['$cookieStore'];
15
+
13
16
  root.CsrfCtrl = CsrfCtrl;
14
17
 
15
18
  }).call(this);
@@ -1,8 +1,10 @@
1
1
  root = global ? window
2
+ angular = root.angular
3
+
4
+ CsrfCtrl = ($cookieStore) ->
5
+ $cookieStore.put "XSRF-TOKEN", angular.element(document.getElementById("csrf")).attr("data-csrf")
6
+
7
+ CsrfCtrl.$inject = ['$cookieStore'];
2
8
 
3
- CsrfCtrl = ["$cookieStore", ($cookieStore) ->
4
- $cookieStore.put "XSRF-TOKEN",
5
- angular.element(document.getElementById("csrf")).attr("data-csrf")
6
- ]
7
9
  # exports
8
10
  root.CsrfCtrl = CsrfCtrl
@@ -1,15 +1,15 @@
1
1
  root = global ? window
2
2
  angular = root.angular
3
3
 
4
- thisApp = angular.module("Client", ["ngCookies"]).config(($routeProvider, $locationProvider) ->
4
+ thisApp = angular.module("Client", ['ngCookies']).config(['$routeProvider', '$locationProvider' ,
5
+ ($routeProvider, $locationProvider) ->
6
+ #$locationProvider.hashPrefix('');
5
7
  $locationProvider.html5Mode true
6
8
  $routeProvider.when("/",
7
9
  controller: "WelcomeCtrl"
8
10
  templateUrl: "<%= asset_path('welcome/index.html') %>"
9
11
  ).otherwise redirectTo: "/"
10
- )
11
- # exports
12
- root.thisApp = thisApp
13
-
12
+ ])
14
13
 
14
+ root.thisApp = thisApp
15
15
 
@@ -1,3 +1,4 @@
1
+ // Generated by CoffeeScript 1.4.0
1
2
  (function() {
2
3
  var angular, root, thisApp;
3
4
 
@@ -5,15 +6,17 @@
5
6
 
6
7
  angular = root.angular;
7
8
 
8
- thisApp = angular.module("Client", ["ngCookies"]).config(function($routeProvider, $locationProvider) {
9
- $locationProvider.html5Mode(true);
10
- return $routeProvider.when("/", {
11
- controller: "WelcomeCtrl",
12
- templateUrl: "<%= asset_path('welcome/index.html') %>"
13
- }).otherwise({
14
- redirectTo: "/"
15
- });
16
- });
9
+ thisApp = angular.module("Client", ['ngCookies']).config([
10
+ '$routeProvider', '$locationProvider', function($routeProvider, $locationProvider) {
11
+ $locationProvider.html5Mode(true);
12
+ return $routeProvider.when("/", {
13
+ controller: "WelcomeCtrl",
14
+ templateUrl: "<%= asset_path('welcome/index.html') %>"
15
+ }).otherwise({
16
+ redirectTo: "/"
17
+ });
18
+ }
19
+ ]);
17
20
 
18
21
  root.thisApp = thisApp;
19
22
 
@@ -1,12 +1,11 @@
1
1
  // Generated by CoffeeScript 1.4.0
2
2
  (function() {
3
- var WelcomeCtrl, root;
3
+ var root, thisApp;
4
4
 
5
5
  root = typeof global !== "undefined" && global !== null ? global : window;
6
6
 
7
- WelcomeCtrl = ["$scope", function($scope) {}];
7
+ thisApp = root.thisApp;
8
8
 
9
- // exports
10
- root.thisApp.controller("WelcomeCtrl", WelcomeCtrl);
9
+ thisApp.controller("WelcomeCtrl", function() {});
11
10
 
12
11
  }).call(this);
@@ -1,7 +1,7 @@
1
1
  root = global ? window
2
2
 
3
- WelcomeCtrl = ["$scope", ($scope) ->
4
- ]
5
- # exports
6
- root.thisApp.controller "WelcomeCtrl", WelcomeCtrl
3
+ thisApp = root.thisApp
4
+
5
+ thisApp.controller "WelcomeCtrl", ->
6
+
7
7
 
@@ -16,17 +16,10 @@ module Angularjs
16
16
  end
17
17
 
18
18
  def init_vars
19
- # Rails.logger.info "--> init_vars"
20
19
  @model_name = controller_name.singularize #"Post"
21
- # Rails.logger.info "@model_name: #{@model_name}"
22
20
  @controller = controller_name #"Posts"
23
- # Rails.logger.info "@controller: #{@controller}"
24
21
  @resource_name = @model_name.demodulize.underscore #post
25
- # Rails.logger.info "@resource_name: #{@resource_name}"
26
22
  @plural_model_name = @resource_name.pluralize #posts
27
- # Rails.logger.info "@plural_model_name: #{@plural_model_name}"
28
- @language = language_option # 'coffeescript or javascript'
29
- # Rails.logger.info "@language: #{@language}"
30
23
  end
31
24
 
32
25
  def columns
@@ -47,42 +40,40 @@ module Angularjs
47
40
  end
48
41
 
49
42
  def generate
50
- #Rails.logger.info "columns: #{columns}"
51
- remove_file "app/assets/stylesheets/scaffolds.css.scss"
52
- append_to_file "app/assets/javascripts/application.js",
53
- "//= require #{@plural_model_name}_controller\n"
54
- append_to_file "app/assets/javascripts/application.js",
55
- "//= require #{@plural_model_name}\n"
56
- if @language == 'coffeescript'
43
+ remove_file "app/assets/stylesheets/scaffolds.css.scss"
44
+ # append_to_file "app/assets/javascripts/application.js",
45
+ # "//= require #{@plural_model_name}_controller\n"
46
+ # append_to_file "app/assets/javascripts/application.js",
47
+ # "//= require #{@plural_model_name}\n"
48
+ if language_option == 'coffeescript'
57
49
  insert_into_file "app/assets/javascripts/routes.coffee.erb",
58
- ", \'#{@plural_model_name}\'", before: "]"
50
+ ", \'#{@plural_model_name}\'", :after => "'ngCookies'"
59
51
  insert_into_file "app/assets/javascripts/routes.coffee.erb",
60
52
  %{when("/#{@plural_model_name}",
61
- controller: \'#{@controller}IndexCtrl\'
62
- templateUrl: "<%= asset_path(\'#{@plural_model_name}/index.html\') %>"
53
+ controller: #{@controller}IndexCtrl
54
+ templateUrl: '<%= asset_path(\"#{@plural_model_name}/index.html\") %>'
63
55
  ).when("/#{@plural_model_name}/new",
64
- controller: \'#{@controller}CreateCtrl\'
65
- templateUrl: "<%= asset_path(\'#{@plural_model_name}/new.html\') %>"
56
+ controller: #{@controller}CreateCtrl
57
+ templateUrl: '<%= asset_path(\"#{@plural_model_name}/new.html\") %>'
66
58
  ).when("/#{@plural_model_name}/:id",
67
- controller: \'#{@controller}ShowCtrl\'
68
- templateUrl: "<%= asset_path(\'#{@plural_model_name}/show.html\') %>"
59
+ controller: #{@controller}ShowCtrl
60
+ templateUrl: '<%= asset_path(\"#{@plural_model_name}/show.html\") %>'
69
61
  ).when("/#{@plural_model_name}/:id/edit",
70
- controller: \'#{@controller}EditCtrl\'
71
- templateUrl: "<%= asset_path(\'#{@plural_model_name}/edit.html\') %>"
72
- ).}, before: 'otherwise'
62
+ controller: #{@controller}EditCtrl
63
+ templateUrl: '<%= asset_path(\"#{@plural_model_name}/edit.html\") %>'
64
+ ).}, :before => 'otherwise'
73
65
  else
74
66
  insert_into_file "app/assets/javascripts/routes.js.erb",
75
- ", '#{@plural_model_name}'", after: "'ngCookies'"
67
+ ", '#{@plural_model_name}'", :after => "'ngCookies'"
76
68
  insert_into_file "app/assets/javascripts/routes.js.erb",
77
- %{ when('/#{@plural_model_name}', {controller: \'#{@controller}IndexCtrl\',
78
- templateUrl:'<%= asset_path("#{@plural_model_name}/index.html") %>'}).
79
- when('/#{@plural_model_name}/new', {controller: \'#{@controller}CreateCtrl\',
80
- templateUrl:'<%= asset_path("#{@plural_model_name}/new.html") %>'}).
81
- when('/#{@plural_model_name}/:id', {controller: \'#{@controller}ShowCtrl\',
82
- templateUrl:'<%= asset_path("#{@plural_model_name}/show.html") %>'}).
83
- when('/#{@plural_model_name}/:id/edit', {controller: \'#{@controller}EditCtrl\',
84
- templateUrl:'<%= asset_path("#{@plural_model_name}/edit.html") %>'}).\n
85
- }, before: 'otherwise'
69
+ %{\n when('/#{@plural_model_name}', {controller:#{@controller}IndexCtrl,
70
+ templateUrl:'<%= asset_path("#{@plural_model_name}/index.html") %>'}).
71
+ when('/#{@plural_model_name}/new', {controller:#{@controller}CreateCtrl,
72
+ templateUrl:'<%= asset_path("#{@plural_model_name}/new.html") %>'}).
73
+ when('/#{@plural_model_name}/:id', {controller:#{@controller}ShowCtrl,
74
+ templateUrl:'<%= asset_path("#{@plural_model_name}/show.html") %>'}).
75
+ when('/#{@plural_model_name}/:id/edit', {controller:#{@controller}EditCtrl,
76
+ templateUrl:'<%= asset_path("#{@plural_model_name}/edit.html") %>'}).}, :before => 'otherwise'
86
77
  end
87
78
 
88
79
  inject_into_class "app/controllers/#{@plural_model_name}_controller.rb",
@@ -104,18 +95,20 @@ module Angularjs
104
95
  insert_into_file "app/views/layouts/application.html.erb", model_index_link,
105
96
  after: "<!-- main menu models -->"
106
97
 
107
- if @language == 'coffeescript'
98
+ if language_option == 'coffeescript'
108
99
  remove_file "app/assets/javascripts/#{@plural_model_name}.js"
109
100
  remove_file "app/assets/javascripts/#{@plural_model_name}_controller.js"
110
101
  template "plural_model_name.js.coffee", "app/assets/javascripts/#{@plural_model_name}.js.coffee"
111
102
  template "plural_model_name_controller.js.coffee",
112
103
  "app/assets/javascripts/#{@plural_model_name}_controller.js.coffee"
113
104
  else
114
- remove_file "app/assets/javascripts/#{@plural_model_name}.coffee"
115
- remove_file "app/assets/javascripts/#{@plural_model_name}_controller.coffee"
105
+ remove_file "app/assets/javascripts/#{@plural_model_name}.js.coffee"
106
+ remove_file "app/assets/javascripts/#{@plural_model_name}_controller.js.coffee"
116
107
  template "plural_model_name.js", "app/assets/javascripts/#{@plural_model_name}.js"
117
108
  template "plural_model_name_controller.js",
118
109
  "app/assets/javascripts/#{@plural_model_name}_controller.js"
110
+ # remove the default .js.coffee file added by rails.
111
+ remove_file "app/assets/javascripts/#{@plural_model_name}.js.coffee"
119
112
  end
120
113
  end
121
114
  end
@@ -38,7 +38,7 @@
38
38
  class="btn btn-danger">
39
39
  <i class="icon-trash"></i>Delete
40
40
  </button>
41
- <a href="/<%= @resource_name%>s" class="btn">
41
+ <a href="/<%= @plural_model_name%>" class="btn">
42
42
  Back to <%= @plural_model_name%>
43
43
  </a>
44
44
  </div>
@@ -38,7 +38,7 @@
38
38
  class="btn btn-danger">
39
39
  <i class="icon-trash"></i> Delete
40
40
  </button>
41
- <a href="/<%= @resource_name%>s" class="btn">Back to <%= @resource_name%>s</a>
41
+ <a href="/<%= @plural_model_name%>" class="btn">Back to <%= @plural_model_name%></a>
42
42
  </div>
43
43
  </fieldset>
44
44
  </form>
@@ -1,15 +1,15 @@
1
- angular.module('<%= @plural_model_name %>', ['ngResource']).
2
- factory('<%= @model_name %>', function($resource) {
3
- var <%= @model_name %> = $resource('/<%= @plural_model_name %>/:id', {id: '@id'},
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
4
  {
5
5
  update: { method: 'PUT' },
6
6
  destroy: { method: 'DELETE'}
7
7
  }
8
8
  );
9
9
 
10
- <%= @model_name %>.prototype.destroy = function(cb) {
11
- return <%= @model_name %>.remove({id: this.id}, cb);
10
+ <%= @model_name%>.prototype.destroy = function(cb) {
11
+ return <%= @model_name%>.remove({id: this.id}, cb);
12
12
  };
13
13
 
14
- return <%= @model_name %>;
15
- });
14
+ return <%= @model_name%>;
15
+ }]);
@@ -1,7 +1,7 @@
1
1
  root = global ? window
2
2
 
3
- angular.module("<%= @plural_model_name %>", ["ngResource"]).factory "<%= @model_name %>", ($resource) ->
4
- <%= @model_name %> = $resource("/<%= @plural_model_name %>/:id",
3
+ angular.module("<%= @plural_model_name %>", ["ngResource"]).factory "<%= @model_name %>", ['$resource', ($resource) ->
4
+ <%= "#{@model_name}" %> = $resource("/<%= @plural_model_name %>/:id",
5
5
  id: "@id"
6
6
  ,
7
7
  update:
@@ -10,11 +10,11 @@ angular.module("<%= @plural_model_name %>", ["ngResource"]).factory "<%= @model_
10
10
  destroy:
11
11
  method: "DELETE"
12
12
  )
13
- <%= @model_name %>::destroy = (cb) ->
14
- <%= @model_name %>.remove
13
+ <%= "#{@model_name}" %>::destroy = (cb) ->
14
+ <%= "#{@model_name}" %>.remove
15
15
  id: @id
16
16
  , cb
17
17
 
18
- <%= @model_name %>
19
-
18
+ <%= "#{@model_name}" %>
19
+ ]
20
20
  root.angular = angular
@@ -1,42 +1,48 @@
1
- <%= @controller %>IndexCtrl = ['$scope', '<%= @model_name %>', function($scope, <%= @model_name %>) {
2
- $scope.<%= @plural_model_name %> = <%= @model_name %>.query();
1
+ function <%= @controller%>IndexCtrl($scope, <%= @model_name%>) {
2
+ $scope.<%= @plural_model_name %> = <%= @model_name%>.query();
3
3
 
4
4
  $scope.destroy = function() {
5
5
  dconfirm = confirm('Are you sure?');
6
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);
7
+ var original = this.<%= @resource_name%>
8
+ this.<%= @resource_name%>.destroy(function() {
9
+ $scope.<%= @plural_model_name %> = _.without($scope.<%= @plural_model_name%>, original);
10
10
  });
11
11
  }
12
12
  };
13
- }];
13
+ }
14
14
 
15
- <%= @controller %>CreateCtrl = ['$scope', '$location', '<%= @model_name %>', function ($scope, $location, <%= @model_name %>) {
15
+ <%= @controller%>IndexCtrl.$inject = ['$scope', '<%= @model_name%>'];
16
+
17
+ function <%= @controller%>CreateCtrl($scope, $location, <%= @model_name%>) {
16
18
  $scope.save = function() {
17
- <%= @model_name %>.save($scope.<%= @resource_name %>, function(<%= @resource_name %>) {
18
- $location.path('/<%= @plural_model_name %>/' + <%= @resource_name %>.id + '/edit');
19
+ <%= @model_name%>.save($scope.<%= @resource_name%>, function(<%= @resource_name%>) {
20
+ $location.path('/<%= @plural_model_name %>/' + <%= @resource_name%>.id + '/edit');
19
21
  });
20
22
  }
21
- }];
23
+ }
24
+
25
+ <%= @controller%>CreateCtrl.$inject = ['$scope', '$location', '<%= @model_name%>'];
22
26
 
23
- <%= @controller %>ShowCtrl = ['$scope', '$location', '$routeParams', '<%= @model_name %>', function ($scope, $location, $routeParams, <%= @model_name %>) {
24
- <%= @model_name %>.get({id: $routeParams.id}, function(<%= @resource_name %>) {
25
- self.original = <%= @resource_name %>;
26
- $scope.<%= @resource_name %> = new <%= @model_name %>(self.original);
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);
27
31
  });
28
- }];
32
+ }
29
33
 
30
- <%= @controller %>EditCtrl = ['$scope', '$location', '$routeParams', '<%= @model_name %>', function ($scope, $location, $routeParams, <%= @model_name %>) {
34
+ <%= @controller%>ShowCtrl.$inject = ['$scope', '$location', '$routeParams', '<%= @model_name%>'];
35
+
36
+ function <%= @controller%>EditCtrl($scope, $location, $routeParams, <%= @model_name%>) {
31
37
  var self = this;
32
38
 
33
- <%= @model_name %>.get({id: $routeParams.id}, function(<%= @resource_name %>) {
34
- self.original = <%= @resource_name %>;
35
- $scope.<%= @resource_name %> = new <%= @model_name %>(self.original);
39
+ <%= @model_name%>.get({id: $routeParams.id}, function(<%= @resource_name%>) {
40
+ self.original = <%= @resource_name%>;
41
+ $scope.<%= @resource_name%> = new <%= @model_name%>(self.original);
36
42
  });
37
43
 
38
44
  $scope.isClean = function() {
39
- return angular.equals(self.original, $scope.<%= @resource_name %>);
45
+ return angular.equals(self.original, $scope.<%= @resource_name%>);
40
46
  }
41
47
 
42
48
  $scope.destroy = function() {
@@ -48,8 +54,10 @@
48
54
  };
49
55
 
50
56
  $scope.save = function() {
51
- <%= @model_name %>.update($scope.<%= @resource_name %>, function(<%= @resource_name %>) {
57
+ <%= @model_name%>.update($scope.<%= @resource_name%>, function(<%= @resource_name%>) {
52
58
  $location.path('/<%= @plural_model_name %>');
53
59
  });
54
60
  };
55
- }];
61
+ }
62
+
63
+ <%= @controller%>EditCtrl.$inject = ['$scope', '$location', '$routeParams', '<%= @model_name%>'];
@@ -1,54 +1,59 @@
1
+
1
2
  root = global ? window
2
3
 
3
- <%= @controller %>IndexCtrl = ["$scope", "<%= @model_name %>", ($scope, <%= @model_name %>) ->
4
- $scope.<%= @plural_model_name %> = <%= @model_name %>.query()
4
+ <%= @controller%>IndexCtrl = ($scope, <%= @model_name%>) ->
5
+ $scope.<%= @plural_model_name %> = <%= @model_name%>.query()
5
6
  $scope.destroy = ->
6
7
  dconfirm = confirm("Are you sure?")
7
8
  if dconfirm
8
- original = @<%= @resource_name %>
9
- @<%= @resource_name %>.destroy ->
9
+ original = @<%= @resource_name%>
10
+ @<%= @resource_name%>.destroy ->
10
11
  $scope.<%= @plural_model_name %> = _.without($scope.<%= @plural_model_name %>, original)
11
12
 
12
- ]
13
- <%= @controller %>CreateCtrl = ["$scope", "$location", "<%= @model_name %>", ($scope, $location, <%= @model_name %>) ->
13
+ <%= @controller%>IndexCtrl.$inject = ['$scope', '<%= @model_name%>'];
14
+
15
+ <%= @controller%>CreateCtrl = ($scope, $location, <%= @model_name%>) ->
14
16
  $scope.save = ->
15
- <%= @model_name %>.save $scope.<%= @resource_name %>, (<%= @resource_name %>) ->
16
- $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
+
20
+ <%= @controller%>CreateCtrl.$inject = ['$scope', '$location', '<%= @model_name%>'];
17
21
 
18
- ]
19
- <%= @controller %>ShowCtrl = ["$scope", "$location", "$routeParams", "<%= @model_name %>", ($scope, $location, $routeParams, <%= @model_name %>) ->
20
- <%= @model_name %>.get
22
+ <%= @controller%>ShowCtrl = ($scope, $location, $routeParams, <%= @model_name%>) ->
23
+ <%= @model_name%>.get
21
24
  id: $routeParams.id
22
- , (<%= @resource_name %>) ->
23
- self.original = <%= @resource_name %>
24
- $scope.<%= @resource_name %> = new <%= @model_name %>(self.original)
25
+ , (<%= @resource_name%>) ->
26
+ self.original = <%= @resource_name%>
27
+ $scope.<%= @resource_name%> = new <%= @model_name%>(self.original)
25
28
 
26
- ]
27
- <%= @controller %>EditCtrl = ["$scope", "$location", "$routeParams", "<%= @model_name %>", ($scope, $location, $routeParams, <%= @model_name %>) ->
29
+ <%= @controller%>ShowCtrl.$inject = ['$scope', '$location', '$routeParams', '<%= @model_name%>'];
30
+
31
+ <%= @controller%>EditCtrl = ($scope, $location, $routeParams, <%= @model_name%>) ->
28
32
  self = this
29
- <%= @model_name %>.get
33
+ <%= @model_name%>.get
30
34
  id: $routeParams.id
31
- , (<%= @resource_name %>) ->
32
- self.original = <%= @resource_name %>
33
- $scope.<%= @resource_name %> = new <%= @model_name %>(self.original)
35
+ , (<%= @resource_name%>) ->
36
+ self.original = <%= @resource_name%>
37
+ $scope.<%= @resource_name%> = new <%= @model_name%>(self.original)
34
38
 
35
39
  $scope.isClean = ->
36
- angular.equals self.original, $scope.<%= @resource_name %>
40
+ angular.equals self.original, $scope.<%= @resource_name%>
37
41
 
38
42
  $scope.destroy = ->
39
43
  dconfirm = confirm("Are you sure?")
40
44
  if dconfirm
41
- $scope.<%= @resource_name %>.destroy ->
45
+ $scope.<%= @resource_name%>.destroy ->
42
46
  $location.path "/<%= @plural_model_name %>"
43
47
 
44
48
 
45
49
  $scope.save = ->
46
- <%= @model_name %>.update $scope.<%= @resource_name %>, (<%= @resource_name %>) ->
50
+ <%= @model_name%>.update $scope.<%= @resource_name%>, (<%= @resource_name%>) ->
47
51
  $location.path "/<%= @plural_model_name %>"
48
52
 
49
- ]
53
+ <%= @controller%>EditCtrl.$inject = ['$scope', '$location', '$routeParams', '<%= @model_name%>'];
54
+
50
55
  # exports
51
- root.<%= @controller %>IndexCtrl = <%= @controller %>IndexCtrl
52
- root.<%= @controller %>CreateCtrl = <%= @controller %>CreateCtrl
53
- root.<%= @controller %>ShowCtrl = <%= @controller %>ShowCtrl
54
- root.<%= @controller %>EditCtrl = <%= @controller %>EditCtrl
56
+ root.<%= @controller%>IndexCtrl = <%= @controller%>IndexCtrl
57
+ root.<%= @controller%>CreateCtrl = <%= @controller%>CreateCtrl
58
+ root.<%= @controller%>ShowCtrl = <%= @controller%>ShowCtrl
59
+ root.<%= @controller%>EditCtrl = <%= @controller%>EditCtrl
@@ -15,7 +15,7 @@
15
15
  <button ng-click="destroy()" class="btn btn-danger">
16
16
  <i class="icon-trash"></i> Delete
17
17
  </button>
18
- <a href="/<%= @resource_name%>s" class="btn">
18
+ <a href="/<%= @plural_model_name%>" class="btn">
19
19
  Back to <%= @plural_model_name%>
20
20
  </a>
21
21
  </div>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: explainer_angularjs_scaffold
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.21
4
+ version: 0.0.22
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-28 00:00:00.000000000 Z
12
+ date: 2013-01-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -160,7 +160,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
160
160
  version: '0'
161
161
  requirements: []
162
162
  rubyforge_project:
163
- rubygems_version: 1.8.23
163
+ rubygems_version: 1.8.24
164
164
  signing_key:
165
165
  specification_version: 3
166
166
  summary: Angularjs scaffolding.