angularjs_scaffold 0.0.19 → 0.0.22

Sign up to get free protection for your applications and to get access to all the features.
Files changed (27) hide show
  1. data/README.md +28 -2
  2. data/app/views/layouts/angularjs_scaffold/application.html.erb +1 -1
  3. data/lib/angularjs_scaffold/angularjs_scaffold/angularjs_scaffold_generator.rb +1 -1
  4. data/lib/angularjs_scaffold/version.rb +1 -1
  5. data/lib/generators/angularjs/install/install_generator.rb +47 -20
  6. data/lib/generators/angularjs/install/templates/application.css +13 -0
  7. data/lib/generators/angularjs/install/templates/application.html.erb +8 -8
  8. data/lib/generators/angularjs/install/templates/application.js +2 -1
  9. data/lib/generators/angularjs/install/templates/csrf_controller.js +18 -0
  10. data/lib/generators/angularjs/install/templates/csrf_controller.js.coffee +10 -0
  11. data/lib/generators/angularjs/install/templates/favicon.ico +0 -0
  12. data/lib/generators/angularjs/install/templates/{index_welcome.html → index_welcome.html.erb} +1 -1
  13. data/lib/generators/angularjs/install/templates/routes.coffee.erb +15 -0
  14. data/lib/generators/angularjs/install/templates/routes.js.erb +21 -14
  15. data/lib/generators/angularjs/install/templates/welcome_controller.js +10 -2
  16. data/lib/generators/angularjs/install/templates/welcome_controller.js.coffee +7 -0
  17. data/lib/generators/angularjs/scaffold/scaffold_generator.rb +74 -30
  18. data/lib/generators/angularjs/scaffold/templates/{edit.html → edit.html.erb} +3 -3
  19. data/lib/generators/angularjs/scaffold/templates/{index.html → index.html.erb} +11 -6
  20. data/lib/generators/angularjs/scaffold/templates/{new.html → new.html.erb} +1 -1
  21. data/lib/generators/angularjs/scaffold/templates/plural_model_name.js +2 -26
  22. data/lib/generators/angularjs/scaffold/templates/plural_model_name.js.coffee +20 -0
  23. data/lib/generators/angularjs/scaffold/templates/plural_model_name_controller.js +8 -0
  24. data/lib/generators/angularjs/scaffold/templates/plural_model_name_controller.js.coffee +59 -0
  25. data/lib/generators/angularjs/scaffold/templates/{show.html → show.html.erb} +1 -1
  26. data/test/dummy/app/views/layouts/application.html.erb +1 -1
  27. metadata +16 -7
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- ## AngularjsScaffold
1
+ ## AngularjsScaffold + CoffeeScript
2
2
 
3
3
  A rails plugin for scaffolding views using Angular.js, Twitter bootstrap
4
4
  and font awesome
@@ -13,13 +13,39 @@ Second install it, this will add angularjs, bootstrap and fontawesome (there's a
13
13
 
14
14
  $ rails g angularjs:install # adds angular.js and a dummy welcome JS controller
15
15
 
16
+ options:
17
+
18
+ --layout-type=fixed [fluid]
19
+ --no-jquery
20
+ --no-bootstrap
21
+ --language=coffeescript [javascript] NOTE: this setting will be set for the entire rails app
22
+ and will affect all subsequent 'rails generate angularjs:scaffold <<model>>' commands
23
+
16
24
  Run your usual scaffold command:
17
25
 
18
26
  $ rails g scaffold Post title:string body:string
19
27
  $ rake db:migrate
20
28
 
21
- Now run the angularjs command and it will rewrite everything the AngularJS way:
29
+ Now run the angularjs:scaffold command and it will rewrite everything the AngularJS way:
22
30
 
23
31
  $ rails g angularjs:scaffold Posts # adds everything needed using AngularJS
24
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
+
25
51
  Enjoy!
@@ -2,7 +2,7 @@
2
2
  <html>
3
3
  <head>
4
4
  <title>AngularjsScaffold</title>
5
- <%= stylesheet_link_tag "angularjs_scaffold/application", :media => "all" %>
5
+ <%= stylesheet_link_tag "angularjs_scaffold/application", media: "all" %>
6
6
  <%= javascript_include_tag "angularjs_scaffold/application" %>
7
7
  <%= csrf_meta_tags %>
8
8
  </head>
@@ -1,6 +1,6 @@
1
1
  class AngularjsScaffoldGenerator < Rails::Generators::NamedBase
2
2
  source_root File.expand_path('../templates', __FILE__)
3
- argument :file_name, :type => :string, :default => "angularjs_scaffold"
3
+ argument :file_name, type: :string, default: "angularjs_scaffold"
4
4
  def init_angularjs
5
5
  copy_file "stylesheet.css", "app/assets/stylesheets/#{file_name}.css"
6
6
  end
@@ -1,3 +1,3 @@
1
1
  module AngularjsScaffold
2
- VERSION = "0.0.19"
2
+ VERSION = "0.0.22"
3
3
  end
@@ -1,12 +1,14 @@
1
1
  module Angularjs
2
2
  class InstallGenerator < Rails::Generators::Base
3
3
  source_root File.expand_path('../templates', __FILE__)
4
- class_option 'layout-type', :type => :string, :default => "fixed",
5
- :banner => "*fixed or fluid", :aliases => ["-lt"]
6
- class_option 'no-jquery', :type => :boolean, :aliases => ["-njq"],
4
+ class_option 'layout-type', type: :string, default: "fixed",
5
+ banner: "*fixed or fluid", aliases: ["-lt"]
6
+ class_option 'no-jquery', type: :boolean, aliases: ["-njq"],
7
7
  desc: "Don't include jquery"
8
- class_option 'no-bootstrap', :type => :boolean, :aliases => ["-nb"],
8
+ class_option 'no-bootstrap', type: :boolean, aliases: ["-nb"],
9
9
  desc: "Don't include bootstrap"
10
+ class_option 'language', type: :string, default: 'coffeescript', aliases: ["-ln"],
11
+ desc: "Choose your preferred language, 'coffeescript' or 'javascript' "
10
12
 
11
13
  def init_angularjs
12
14
  if File.exist?('app/assets/javascripts/application.js')
@@ -22,7 +24,7 @@ module Angularjs
22
24
  elsif !File.exist?('app/assets/stylesheets/application.css')
23
25
  create_file @application_css_file
24
26
  end
25
- directory "underscore", "app/assets/javascripts/underscoree/"
27
+ directory "underscore", "app/assets/javascripts/underscore/"
26
28
  directory "angularjs", "app/assets/javascripts/angularjs/"
27
29
  if options["no-jquery"]
28
30
  gsub_file "app/assets/javascripts/application.js",
@@ -40,7 +42,7 @@ module Angularjs
40
42
  directory "fontawesome", "app/assets/stylesheets/fontawesome/"
41
43
  directory "bootstrap/css", "app/assets/stylesheets/bootstrap/"
42
44
  directory "bootstrap/js", "app/assets/javascripts/bootstrap/"
43
- directory "bootstrap/img", "app/assets/images/bootstrap/"
45
+ directory "bootstrap/img", "app/assets/javascripts/img/"
44
46
  insert_into_file @application_css_file,
45
47
  " *= require bootstrap/bootstrap.min.css\n", :after => "require_self\n"
46
48
  insert_into_file @application_css_file,
@@ -53,15 +55,16 @@ module Angularjs
53
55
  "\nbody { padding-top: 60px; }\n"
54
56
  unless options["no-jquery"]
55
57
  insert_into_file "app/assets/javascripts/application.js",
56
- "//= require_tree ./bootstrap/\n", :after => "angularjs/\n"
58
+ "//= require_tree ./bootstrap/\n", after: "angularjs/\n"
57
59
  end
58
60
  end
59
61
  end
60
62
 
61
- attr_reader :app_name, :container_class
63
+ attr_reader :app_name, :container_class, :language
62
64
  def init_twitter_bootstrap_layout
63
65
  @app_name = Rails.application.class.parent_name
64
66
  @container_class = options["layout-type"] == "fluid" ? "container-fluid" : "container"
67
+ @language = options["language"] == 'javascript' ? "javascript" : "coffeescript"
65
68
  template "application.html.erb", "app/views/layouts/application.html.erb"
66
69
  end
67
70
 
@@ -69,17 +72,41 @@ module Angularjs
69
72
  remove_file "public/index.html"
70
73
  uncomment_lines 'config/routes.rb', /root :to => 'welcome#index'/
71
74
  run "rails g controller welcome index"
72
- copy_file "AngularJS-medium.png", 'app/assets/images/AngularJS-medium.png'
73
- empty_directory 'app/assets/templates'
74
- empty_directory 'app/assets/templates/welcome'
75
- copy_file "index_welcome.html", 'app/assets/templates/welcome/index.html'
76
- copy_file "routes.js.erb", "app/assets/javascripts/routes.js.erb"
77
- copy_file "welcome_controller.js",
78
- "app/assets/javascripts/welcome_controller.js"
79
- append_to_file "app/assets/javascripts/application.js",
80
- "//= require routes\n"
81
- append_to_file "app/assets/javascripts/application.js",
82
- "//= require welcome_controller\n"
75
+ copy_file "AngularJS-medium.png", "app/assets/images/AngularJS-medium.png"
76
+ copy_file 'favicon.ico', "app/assets/images/favicon.ico"
77
+ empty_directory "app/assets/templates"
78
+ empty_directory "app/assets/templates/welcome"
79
+ copy_file "index_welcome.html.erb", "app/assets/templates/welcome/index.html.erb"
80
+ if @language == 'coffeescript'
81
+ if File.exists?('app/assets/javascripts/routes.js.erb')
82
+ remove_file 'app/assets/javascripts/routes.js.erb'
83
+ end
84
+ copy_file "routes.coffee.erb", "app/assets/javascripts/routes.coffee.erb"
85
+ insert_into_file "app/assets/javascripts/routes.coffee.erb", @app_name, before: 'Client'
86
+ ['csrf', 'welcome'].each do |prefix|
87
+ copy_file "#{prefix}_controller.js.coffee",
88
+ "app/assets/javascripts/#{prefix}_controller.js.coffee"
89
+ remove_file "app/assets/javascripts/#{prefix}_controller.js"
90
+ end
91
+ # insert_into_file "app/assets/javascripts/welcome_controller.js.coffee", @app_name, before: 'Client'
92
+ else # javascript
93
+ if File.exists?('app/assets/javascripts/routes.coffee.erb')
94
+ remove_file 'app/assets/javascripts/routes.coffee.erb'
95
+ end
96
+ copy_file "routes.js.erb", "app/assets/javascripts/routes.js.erb" #if File.exists?("app/assets/javascripts/routes.js.erb")
97
+ # Rails.logger.info "#{__FILE__}, #{__LINE__}, @app_name: #{@app_name}"
98
+ insert_into_file "app/assets/javascripts/routes.js.erb", @app_name, before: 'Client'
99
+ ['csrf', 'welcome'].each do |prefix|
100
+ copy_file "#{prefix}_controller.js",
101
+ "app/assets/javascripts/#{prefix}_controller.js"
102
+ remove_file "app/assets/javascripts/#{prefix}_controller.js.coffee" # if File.exists?("app/assets/javascripts/#{prefix}_controller.js.coffee")
103
+ end
104
+ # insert_into_file "app/assets/javascripts/welcome_controller.js", @app_name, before: 'Client'
105
+ end
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"
83
110
  append_to_file @application_css_file,
84
111
  ".center {text-align: center;}\n"
85
112
  insert_into_file "app/controllers/application_controller.rb",
@@ -93,7 +120,7 @@ module Angularjs
93
120
  form_authenticity_token == params[request_forgery_protection_token] ||
94
121
  form_authenticity_token == request.headers['X-XSRF-Token']
95
122
  end
96
- }, :before => "end"
123
+ }, before: "end"
97
124
 
98
125
  end
99
126
  end
@@ -0,0 +1,13 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the top of the
9
+ * compiled file, but it's generally better to create a new file per style scope.
10
+ *
11
+ *= require_self
12
+ *= require_tree .
13
+ */
@@ -1,5 +1,5 @@
1
1
  <!DOCTYPE html>
2
- <html ng-app="angapp" lang="en">
2
+ <html ng-app="<%= app_name %>Client" lang="en">
3
3
  <head>
4
4
  <meta charset="utf-8">
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
@@ -11,12 +11,12 @@
11
11
  <script src="http://html5shim.googlecode.com/svn/trunk/html5.js" type="text/javascript"></script>
12
12
  <![endif]-->
13
13
 
14
- <%%= stylesheet_link_tag "application", :media => "all" %>
14
+ <%%= stylesheet_link_tag "application", media: "all" %>
15
15
  <%%= javascript_include_tag "application" %>
16
16
  <meta id='csrf' ng-controller="CsrfCtrl".
17
17
  data-csrf="<%%= form_authenticity_token%>">
18
18
 
19
- <link href="images/favicon.ico" rel="shortcut icon">
19
+ <!-- <link href="assets/favicon.ico" rel="shortcut icon"> -->
20
20
  <link href="images/apple-touch-icon.png" rel="apple-touch-icon">
21
21
  <link href="images/apple-touch-icon-72x72.png" rel="apple-touch-icon" sizes="72x72">
22
22
  <link href="images/apple-touch-icon-114x114.png" rel="apple-touch-icon" sizes="114x114">
@@ -34,9 +34,7 @@
34
34
  <a class="brand" href="/"><%= app_name %></a>
35
35
  <div class="<%= container_class %> nav-collapse">
36
36
  <ul class="nav">
37
- <li><%%= link_to "Link1", "/path1" %></li>
38
- <li><%%= link_to "Link2", "/path2" %></li>
39
- <li><%%= link_to "Link3", "/path3" %></li>
37
+ <!-- main menu models -->
40
38
  </ul>
41
39
  </div><!--/.nav-collapse -->
42
40
  </div>
@@ -46,13 +44,15 @@
46
44
  <div class="container">
47
45
  <div class="content">
48
46
  <div class="row">
49
- <div ng-view class="span9">
50
- </div>
47
+ <!-- templates load here -->
48
+ <div ng-view class="span9"></div>
49
+ <!-- templates load here -->
51
50
  <div class="span3">
52
51
  <div class="well sidebar-nav">
53
52
  <h3>Sidebar</h3>
54
53
  <ul class="nav nav-list">
55
54
  <li class="nav-header">Sidebar</li>
55
+ <!-- sidebar menu models -->
56
56
  <li><%%= link_to "Link1", "/path1" %></li>
57
57
  <li><%%= link_to "Link2", "/path2" %></li>
58
58
  <li><%%= link_to "Link3", "/path3" %></li>
@@ -12,5 +12,6 @@
12
12
  //
13
13
  //= require jquery
14
14
  //= require jquery_ujs
15
- //= require_tree ./angularjs/
16
15
  //= require_tree ./underscore/
16
+ //= require_tree ./angularjs/
17
+
@@ -0,0 +1,18 @@
1
+ // Generated by CoffeeScript 1.4.0
2
+
3
+ (function() {
4
+ var CsrfCtrl, angular, root;
5
+
6
+ root = typeof global !== "undefined" && global !== null ? global : window;
7
+
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
+
16
+ root.CsrfCtrl = CsrfCtrl;
17
+
18
+ }).call(this);
@@ -0,0 +1,10 @@
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'];
8
+
9
+ # exports
10
+ root.CsrfCtrl = CsrfCtrl
@@ -1,5 +1,5 @@
1
1
  <div class="hero-unit center">
2
- <p><h1>AngularJS &lt;3 Rails!</h1></p>
2
+ <p><h1>AngularJS, CoffeeScript and Rails!</h1></p>
3
3
  <p>
4
4
  <img src="/assets/AngularJS-medium.png">
5
5
  </p>
@@ -0,0 +1,15 @@
1
+ root = global ? window
2
+ angular = root.angular
3
+
4
+ thisApp = angular.module("Client", ['ngCookies']).config(['$routeProvider', '$locationProvider' ,
5
+ ($routeProvider, $locationProvider) ->
6
+ #$locationProvider.hashPrefix('');
7
+ $locationProvider.html5Mode true
8
+ $routeProvider.when("/",
9
+ controller: "WelcomeCtrl"
10
+ templateUrl: "<%= asset_path('welcome/index.html') %>"
11
+ ).otherwise redirectTo: "/"
12
+ ])
13
+
14
+ root.thisApp = thisApp
15
+
@@ -1,16 +1,23 @@
1
- var angapp = angular.module('angapp', ['ngCookies']).
2
- config(function($routeProvider, $locationProvider) {
3
- //$locationProvider.hashPrefix('');
4
- $locationProvider.html5Mode(true);
5
- $routeProvider.
6
- when('/', {controller: 'WelcomeCtrl',
7
- templateUrl:'<%= asset_path("welcome/index.html") %>'}).
8
- otherwise({redirectTo:'/'});
9
- });
1
+ // Generated by CoffeeScript 1.4.0
2
+ (function() {
3
+ var angular, root, thisApp;
10
4
 
11
- function CsrfCtrl($cookieStore){
12
- $cookieStore.put("XSRF-TOKEN",
13
- angular.element(document.getElementById('csrf')).
14
- attr('data-csrf'));
15
- }
5
+ root = typeof global !== "undefined" && global !== null ? global : window;
16
6
 
7
+ angular = root.angular;
8
+
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
+ ]);
20
+
21
+ root.thisApp = thisApp;
22
+
23
+ }).call(this);
@@ -1,3 +1,11 @@
1
- angapp.controller('WelcomeCtrl', function() {
2
- });
1
+ // Generated by CoffeeScript 1.4.0
2
+ (function() {
3
+ var root, thisApp;
3
4
 
5
+ root = typeof global !== "undefined" && global !== null ? global : window;
6
+
7
+ thisApp = root.thisApp;
8
+
9
+ thisApp.controller("WelcomeCtrl", function() {});
10
+
11
+ }).call(this);
@@ -0,0 +1,7 @@
1
+ root = global ? window
2
+
3
+ thisApp = root.thisApp
4
+
5
+ thisApp.controller "WelcomeCtrl", ->
6
+
7
+
@@ -4,17 +4,22 @@ require 'rails/generators/generated_attribute'
4
4
  module Angularjs
5
5
  class ScaffoldGenerator < Rails::Generators::Base
6
6
  source_root File.expand_path('../templates', __FILE__)
7
- argument :controller_name, :type => :string
7
+ argument :controller_name, type: :string
8
+
9
+ def language_option
10
+ if File.exist?("app/assets/javascripts/routes.js.erb")
11
+ answer = 'javascript'
12
+ else
13
+ answer = 'coffeescript'
14
+ end
15
+ answer
16
+ end
8
17
 
9
18
  def init_vars
10
19
  @model_name = controller_name.singularize #"Post"
11
20
  @controller = controller_name #"Posts"
12
21
  @resource_name = @model_name.demodulize.underscore #post
13
22
  @plural_model_name = @resource_name.pluralize #posts
14
- @model_name.constantize.columns.
15
- each{|c|
16
- (['name','title'].include?(c.name)) ? @resource_legend = c.name.capitalize : ''}
17
- @resource_legend = 'ID' if @resource_legend.blank?
18
23
  end
19
24
 
20
25
  def columns
@@ -36,36 +41,75 @@ module Angularjs
36
41
 
37
42
  def generate
38
43
  remove_file "app/assets/stylesheets/scaffolds.css.scss"
39
- append_to_file "app/assets/javascripts/application.js",
40
- "//= require #{@plural_model_name}_controller \n"
41
- append_to_file "app/assets/javascripts/application.js",
42
- "//= require #{@plural_model_name} \n"
43
- insert_into_file "app/assets/javascripts/routes.js.erb",
44
- ", '#{@plural_model_name}'", :after => "'ngCookies'"
45
- insert_into_file "app/assets/javascripts/routes.js.erb",
46
- %{ when('/#{@plural_model_name}', {controller:#{@controller}IndexCtrl,
47
- templateUrl:'<%= asset_path("#{@plural_model_name}/index.html") %>'}).
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'
49
+ insert_into_file "app/assets/javascripts/routes.coffee.erb",
50
+ ", \'#{@plural_model_name}\'", :after => "'ngCookies'"
51
+ insert_into_file "app/assets/javascripts/routes.coffee.erb",
52
+ %{when("/#{@plural_model_name}",
53
+ controller: #{@controller}IndexCtrl
54
+ templateUrl: '<%= asset_path(\"#{@plural_model_name}/index.html\") %>'
55
+ ).when("/#{@plural_model_name}/new",
56
+ controller: #{@controller}CreateCtrl
57
+ templateUrl: '<%= asset_path(\"#{@plural_model_name}/new.html\") %>'
58
+ ).when("/#{@plural_model_name}/:id",
59
+ controller: #{@controller}ShowCtrl
60
+ templateUrl: '<%= asset_path(\"#{@plural_model_name}/show.html\") %>'
61
+ ).when("/#{@plural_model_name}/:id/edit",
62
+ controller: #{@controller}EditCtrl
63
+ templateUrl: '<%= asset_path(\"#{@plural_model_name}/edit.html\") %>'
64
+ ).}, :before => 'otherwise'
65
+ else
66
+ insert_into_file "app/assets/javascripts/routes.js.erb",
67
+ ", '#{@plural_model_name}'", :after => "'ngCookies'"
68
+ insert_into_file "app/assets/javascripts/routes.js.erb",
69
+ %{\n when('/#{@plural_model_name}', {controller:#{@controller}IndexCtrl,
70
+ templateUrl:'<%= asset_path("#{@plural_model_name}/index.html") %>'}).
48
71
  when('/#{@plural_model_name}/new', {controller:#{@controller}CreateCtrl,
49
- templateUrl:'<%= asset_path("#{@plural_model_name}/new.html") %>'}).
72
+ templateUrl:'<%= asset_path("#{@plural_model_name}/new.html") %>'}).
50
73
  when('/#{@plural_model_name}/:id', {controller:#{@controller}ShowCtrl,
51
- templateUrl:'<%= asset_path("#{@plural_model_name}/show.html") %>'}).
74
+ templateUrl:'<%= asset_path("#{@plural_model_name}/show.html") %>'}).
52
75
  when('/#{@plural_model_name}/:id/edit', {controller:#{@controller}EditCtrl,
53
- templateUrl:'<%= asset_path("#{@plural_model_name}/edit.html") %>'}).\n
54
-
55
- }, :before => 'otherwise'
76
+ templateUrl:'<%= asset_path("#{@plural_model_name}/edit.html") %>'}).}, :before => 'otherwise'
77
+ end
78
+
56
79
  inject_into_class "app/controllers/#{@plural_model_name}_controller.rb",
57
80
  "#{@controller}Controller".constantize, "respond_to :json\n"
58
- template "new.html",
59
- "app/assets/templates/#{@plural_model_name}/new.html"
60
- template "edit.html",
61
- "app/assets/templates/#{@plural_model_name}/edit.html"
62
- template "show.html",
63
- "app/assets/templates/#{@plural_model_name}/show.html"
64
- template "index.html",
65
- "app/assets/templates/#{@plural_model_name}/index.html"
66
- template "plural_model_name.js", "app/assets/javascripts/#{@plural_model_name}.js"
67
- template "plural_model_name_controller.js",
68
- "app/assets/javascripts/#{@plural_model_name}_controller.js"
81
+ template "new.html.erb",
82
+ "app/assets/templates/#{@plural_model_name}/new.html.erb"
83
+ template "edit.html.erb",
84
+ "app/assets/templates/#{@plural_model_name}/edit.html.erb"
85
+ template "show.html.erb",
86
+ "app/assets/templates/#{@plural_model_name}/show.html.erb"
87
+ template "index.html.erb",
88
+ "app/assets/templates/#{@plural_model_name}/index.html.erb"
89
+
90
+ model_index_link = "\n<li><%= link_to \'#{@controller_name}\', #{@plural_model_name}_path %></li>"
91
+
92
+ # insert_into_file "app/views/layouts/application.html.erb", model_index_link,
93
+ # after: "<!-- sidebar menu models -->"
94
+
95
+ insert_into_file "app/views/layouts/application.html.erb", model_index_link,
96
+ after: "<!-- main menu models -->"
97
+
98
+ if language_option == 'coffeescript'
99
+ remove_file "app/assets/javascripts/#{@plural_model_name}.js"
100
+ remove_file "app/assets/javascripts/#{@plural_model_name}_controller.js"
101
+ template "plural_model_name.js.coffee", "app/assets/javascripts/#{@plural_model_name}.js.coffee"
102
+ template "plural_model_name_controller.js.coffee",
103
+ "app/assets/javascripts/#{@plural_model_name}_controller.js.coffee"
104
+ else
105
+ remove_file "app/assets/javascripts/#{@plural_model_name}.js.coffee"
106
+ remove_file "app/assets/javascripts/#{@plural_model_name}_controller.js.coffee"
107
+ template "plural_model_name.js", "app/assets/javascripts/#{@plural_model_name}.js"
108
+ template "plural_model_name_controller.js",
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"
112
+ end
69
113
  end
70
114
  end
71
115
  end
@@ -38,10 +38,10 @@
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
- </div>
45
- </fieldset>
44
+ </div>
45
+ </fieldset>
46
46
  </form>
47
47
 
@@ -2,21 +2,26 @@
2
2
  <table class="table table-striped">
3
3
  <thead>
4
4
  <tr>
5
- <th><%= @resource_legend %></th>
6
- <th>Created at</th>
5
+ <%- columns.each do |column| -%>
6
+ <th><%= column.name.humanize %></th>
7
+ <%- end -%>
7
8
  <th>Actions</th>
8
9
  </tr>
9
10
  </thead>
11
+ <%- @columns = columns -%>
12
+ <%- tag_column = @columns.shift -%>
10
13
  <tbody>
11
14
  <tr ng-repeat="<%= @resource_name%> in <%= @plural_model_name%>">
12
15
  <td>
13
16
  <a href="/<%= @plural_model_name%>/{{<%= @resource_name%>.id}}">
14
- {{<%= "#{@resource_name}.#{@resource_legend.downcase}"%>}}
17
+ {{<%= "#{@resource_name}.#{tag_column.name}"%>}}
15
18
  </a>
16
19
  </td>
17
- <td>
18
- {{<%= @resource_name%>.created_at}}
19
- </td>
20
+ <%- @columns.each do |column| -%>
21
+ <td>
22
+ {{<%= @resource_name%>.<%= column.name %>}}
23
+ </td>
24
+ <%- end -%>
20
25
  <td>
21
26
  <a href="/<%= @plural_model_name%>/{{<%= @resource_name%>.id}}/edit"
22
27
  class="btn btn-primary"><i class="icon-edit"></i>
@@ -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,5 +1,5 @@
1
1
  angular.module('<%= @plural_model_name%>', ['ngResource']).
2
- factory('<%= @model_name%>', function($resource) {
2
+ factory('<%= @model_name%>', ['$resource', function($resource) {
3
3
  var <%= @model_name%> = $resource('/<%= @plural_model_name%>/:id', {id: '@id'},
4
4
  {
5
5
  update: { method: 'PUT' },
@@ -12,28 +12,4 @@ angular.module('<%= @plural_model_name%>', ['ngResource']).
12
12
  };
13
13
 
14
14
  return <%= @model_name%>;
15
- });
16
- /*
17
- angular.module('<%= @plural_model_name%>', ['ngResource']).
18
- factory('<%= @model_name%>', function($resource) {
19
- var <%= @model_name%> = $resource('/<%= @plural_model_name%>/:id',
20
- {}, {
21
- update: { method: 'PUT' },
22
- destroy: { method: 'DELETE'}
23
- }
24
- );
25
-
26
- <%= @model_name%>.prototype.update = function(cb) {
27
- return <%= @model_name%>.update({id: this._id},
28
- angular.extend({},
29
- this,
30
- {id:undefined}), cb);
31
- };
32
-
33
- <%= @model_name%>.prototype.destroy = function(cb) {
34
- return <%= @model_name%>.remove({id: this._id}, cb);
35
- };
36
-
37
- return <%= @model_name%>;
38
- });
39
- */
15
+ }]);
@@ -0,0 +1,20 @@
1
+ root = global ? window
2
+
3
+ angular.module("<%= @plural_model_name %>", ["ngResource"]).factory "<%= @model_name %>", ['$resource', ($resource) ->
4
+ <%= "#{@model_name}" %> = $resource("/<%= @plural_model_name %>/:id",
5
+ id: "@id"
6
+ ,
7
+ update:
8
+ method: "PUT"
9
+
10
+ destroy:
11
+ method: "DELETE"
12
+ )
13
+ <%= "#{@model_name}" %>::destroy = (cb) ->
14
+ <%= "#{@model_name}" %>.remove
15
+ id: @id
16
+ , cb
17
+
18
+ <%= "#{@model_name}" %>
19
+ ]
20
+ root.angular = angular
@@ -12,6 +12,8 @@ function <%= @controller%>IndexCtrl($scope, <%= @model_name%>) {
12
12
  };
13
13
  }
14
14
 
15
+ <%= @controller%>IndexCtrl.$inject = ['$scope', '<%= @model_name%>'];
16
+
15
17
  function <%= @controller%>CreateCtrl($scope, $location, <%= @model_name%>) {
16
18
  $scope.save = function() {
17
19
  <%= @model_name%>.save($scope.<%= @resource_name%>, function(<%= @resource_name%>) {
@@ -20,6 +22,8 @@ function <%= @controller%>CreateCtrl($scope, $location, <%= @model_name%>) {
20
22
  }
21
23
  }
22
24
 
25
+ <%= @controller%>CreateCtrl.$inject = ['$scope', '$location', '<%= @model_name%>'];
26
+
23
27
  function <%= @controller%>ShowCtrl($scope, $location, $routeParams, <%= @model_name%>) {
24
28
  <%= @model_name%>.get({id: $routeParams.id}, function(<%= @resource_name%>) {
25
29
  self.original = <%= @resource_name%>;
@@ -27,6 +31,8 @@ function <%= @controller%>ShowCtrl($scope, $location, $routeParams, <%= @model_n
27
31
  });
28
32
  }
29
33
 
34
+ <%= @controller%>ShowCtrl.$inject = ['$scope', '$location', '$routeParams', '<%= @model_name%>'];
35
+
30
36
  function <%= @controller%>EditCtrl($scope, $location, $routeParams, <%= @model_name%>) {
31
37
  var self = this;
32
38
 
@@ -53,3 +59,5 @@ function <%= @controller%>EditCtrl($scope, $location, $routeParams, <%= @model_n
53
59
  });
54
60
  };
55
61
  }
62
+
63
+ <%= @controller%>EditCtrl.$inject = ['$scope', '$location', '$routeParams', '<%= @model_name%>'];
@@ -0,0 +1,59 @@
1
+
2
+ root = global ? window
3
+
4
+ <%= @controller%>IndexCtrl = ($scope, <%= @model_name%>) ->
5
+ $scope.<%= @plural_model_name %> = <%= @model_name%>.query()
6
+ $scope.destroy = ->
7
+ dconfirm = confirm("Are you sure?")
8
+ if dconfirm
9
+ original = @<%= @resource_name%>
10
+ @<%= @resource_name%>.destroy ->
11
+ $scope.<%= @plural_model_name %> = _.without($scope.<%= @plural_model_name %>, original)
12
+
13
+ <%= @controller%>IndexCtrl.$inject = ['$scope', '<%= @model_name%>'];
14
+
15
+ <%= @controller%>CreateCtrl = ($scope, $location, <%= @model_name%>) ->
16
+ $scope.save = ->
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%>'];
21
+
22
+ <%= @controller%>ShowCtrl = ($scope, $location, $routeParams, <%= @model_name%>) ->
23
+ <%= @model_name%>.get
24
+ id: $routeParams.id
25
+ , (<%= @resource_name%>) ->
26
+ self.original = <%= @resource_name%>
27
+ $scope.<%= @resource_name%> = new <%= @model_name%>(self.original)
28
+
29
+ <%= @controller%>ShowCtrl.$inject = ['$scope', '$location', '$routeParams', '<%= @model_name%>'];
30
+
31
+ <%= @controller%>EditCtrl = ($scope, $location, $routeParams, <%= @model_name%>) ->
32
+ self = this
33
+ <%= @model_name%>.get
34
+ id: $routeParams.id
35
+ , (<%= @resource_name%>) ->
36
+ self.original = <%= @resource_name%>
37
+ $scope.<%= @resource_name%> = new <%= @model_name%>(self.original)
38
+
39
+ $scope.isClean = ->
40
+ angular.equals self.original, $scope.<%= @resource_name%>
41
+
42
+ $scope.destroy = ->
43
+ dconfirm = confirm("Are you sure?")
44
+ if dconfirm
45
+ $scope.<%= @resource_name%>.destroy ->
46
+ $location.path "/<%= @plural_model_name %>"
47
+
48
+
49
+ $scope.save = ->
50
+ <%= @model_name%>.update $scope.<%= @resource_name%>, (<%= @resource_name%>) ->
51
+ $location.path "/<%= @plural_model_name %>"
52
+
53
+ <%= @controller%>EditCtrl.$inject = ['$scope', '$location', '$routeParams', '<%= @model_name%>'];
54
+
55
+ # 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
@@ -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>
@@ -2,7 +2,7 @@
2
2
  <html>
3
3
  <head>
4
4
  <title>Dummy</title>
5
- <%= stylesheet_link_tag "application", :media => "all" %>
5
+ <%= stylesheet_link_tag "application", media: "all" %>
6
6
  <%= javascript_include_tag "application" %>
7
7
  <%= csrf_meta_tags %>
8
8
  </head>
metadata CHANGED
@@ -1,15 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: angularjs_scaffold
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.19
4
+ version: 0.0.22
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Patrick Aljord
9
+ - Ken Burgett
9
10
  autorequire:
10
11
  bindir: bin
11
12
  cert_chain: []
12
- date: 2012-11-06 00:00:00.000000000 Z
13
+ date: 2013-01-04 00:00:00.000000000 Z
13
14
  dependencies:
14
15
  - !ruby/object:Gem::Dependency
15
16
  name: rails
@@ -58,12 +59,14 @@ files:
58
59
  - app/views/layouts/angularjs_scaffold/application.html.erb
59
60
  - config/routes.rb
60
61
  - lib/tasks/angularjs_scaffold_tasks.rake
61
- - lib/generators/angularjs/scaffold/templates/show.html
62
+ - lib/generators/angularjs/scaffold/templates/index.html.erb
63
+ - lib/generators/angularjs/scaffold/templates/plural_model_name_controller.js.coffee
62
64
  - lib/generators/angularjs/scaffold/templates/plural_model_name.js
65
+ - lib/generators/angularjs/scaffold/templates/plural_model_name.js.coffee
63
66
  - lib/generators/angularjs/scaffold/templates/plural_model_name_controller.js
64
- - lib/generators/angularjs/scaffold/templates/edit.html
65
- - lib/generators/angularjs/scaffold/templates/index.html
66
- - lib/generators/angularjs/scaffold/templates/new.html
67
+ - lib/generators/angularjs/scaffold/templates/show.html.erb
68
+ - lib/generators/angularjs/scaffold/templates/new.html.erb
69
+ - lib/generators/angularjs/scaffold/templates/edit.html.erb
67
70
  - lib/generators/angularjs/scaffold/scaffold_generator.rb
68
71
  - lib/generators/angularjs/install/templates/application.html.erb
69
72
  - lib/generators/angularjs/install/templates/underscore/underscore-min.js
@@ -75,15 +78,21 @@ files:
75
78
  - lib/generators/angularjs/install/templates/angularjs/angular-cookies-1.0.1.min.js
76
79
  - lib/generators/angularjs/install/templates/angularjs/angular-bootstrap-1.0.1.min.js
77
80
  - lib/generators/angularjs/install/templates/application.js
78
- - lib/generators/angularjs/install/templates/index_welcome.html
81
+ - lib/generators/angularjs/install/templates/csrf_controller.js.coffee
79
82
  - lib/generators/angularjs/install/templates/fonts/fontawesome-webfont.woff
80
83
  - lib/generators/angularjs/install/templates/fonts/fontawesome-webfont.svgz
81
84
  - lib/generators/angularjs/install/templates/fonts/fontawesome-webfont.svg
82
85
  - lib/generators/angularjs/install/templates/fonts/fontawesome-webfont.ttf
83
86
  - lib/generators/angularjs/install/templates/fonts/fontawesome-webfont.eot
87
+ - lib/generators/angularjs/install/templates/index_welcome.html.erb
88
+ - lib/generators/angularjs/install/templates/routes.coffee.erb
84
89
  - lib/generators/angularjs/install/templates/welcome_controller.js
85
90
  - lib/generators/angularjs/install/templates/fontawesome/font-awesome.css
91
+ - lib/generators/angularjs/install/templates/csrf_controller.js
92
+ - lib/generators/angularjs/install/templates/favicon.ico
86
93
  - lib/generators/angularjs/install/templates/AngularJS-medium.png
94
+ - lib/generators/angularjs/install/templates/welcome_controller.js.coffee
95
+ - lib/generators/angularjs/install/templates/application.css
87
96
  - lib/generators/angularjs/install/templates/bootstrap/img/glyphicons-halflings.png
88
97
  - lib/generators/angularjs/install/templates/bootstrap/img/glyphicons-halflings-white.png
89
98
  - lib/generators/angularjs/install/templates/bootstrap/css/bootstrap-responsive.min.css