nifty-generators 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. data/CHANGELOG +11 -0
  2. data/README.rdoc +2 -2
  3. data/features/nifty_authentication.feature +2 -2
  4. data/features/nifty_scaffold.feature +15 -0
  5. data/features/step_definitions/common_steps.rb +1 -1
  6. data/features/step_definitions/rails_setup_steps.rb +1 -1
  7. data/lib/generators/nifty.rb +2 -2
  8. data/lib/generators/nifty/authentication/USAGE +15 -15
  9. data/lib/generators/nifty/authentication/authentication_generator.rb +10 -9
  10. data/lib/generators/nifty/authentication/templates/authentication.rb +9 -9
  11. data/lib/generators/nifty/authentication/templates/migration.rb +1 -1
  12. data/lib/generators/nifty/authentication/templates/sessions_controller.rb +4 -4
  13. data/lib/generators/nifty/authentication/templates/tests/rspec/sessions_controller.rb +6 -6
  14. data/lib/generators/nifty/authentication/templates/tests/rspec/user.rb +15 -15
  15. data/lib/generators/nifty/authentication/templates/tests/rspec/users_controller.rb +5 -5
  16. data/lib/generators/nifty/authentication/templates/tests/shoulda/sessions_controller.rb +3 -3
  17. data/lib/generators/nifty/authentication/templates/tests/shoulda/user.rb +15 -15
  18. data/lib/generators/nifty/authentication/templates/tests/shoulda/users_controller.rb +2 -2
  19. data/lib/generators/nifty/authentication/templates/tests/testunit/sessions_controller.rb +3 -3
  20. data/lib/generators/nifty/authentication/templates/tests/testunit/user.rb +15 -15
  21. data/lib/generators/nifty/authentication/templates/tests/testunit/users_controller.rb +2 -2
  22. data/lib/generators/nifty/authentication/templates/user.rb +7 -7
  23. data/lib/generators/nifty/authentication/templates/users_controller.rb +1 -1
  24. data/lib/generators/nifty/config/USAGE +2 -2
  25. data/lib/generators/nifty/config/config_generator.rb +3 -3
  26. data/lib/generators/nifty/layout/USAGE +2 -2
  27. data/lib/generators/nifty/layout/layout_generator.rb +4 -4
  28. data/lib/generators/nifty/layout/templates/error_messages_helper.rb +2 -2
  29. data/lib/generators/nifty/layout/templates/layout.html.erb +1 -1
  30. data/lib/generators/nifty/layout/templates/layout.html.haml +4 -4
  31. data/lib/generators/nifty/layout/templates/layout_helper.rb +3 -3
  32. data/lib/generators/nifty/layout/templates/stylesheet.sass +41 -41
  33. data/lib/generators/nifty/scaffold/USAGE +9 -9
  34. data/lib/generators/nifty/scaffold/scaffold_generator.rb +8 -6
  35. data/lib/generators/nifty/scaffold/templates/migration.rb +1 -1
  36. data/lib/generators/nifty/scaffold/templates/tests/rspec/actions/create.rb +1 -1
  37. data/lib/generators/nifty/scaffold/templates/tests/rspec/actions/update.rb +1 -1
  38. data/lib/generators/nifty/scaffold/templates/tests/rspec/controller.rb +3 -3
  39. data/lib/generators/nifty/scaffold/templates/tests/shoulda/actions/create.rb +1 -1
  40. data/lib/generators/nifty/scaffold/templates/tests/shoulda/actions/update.rb +1 -1
  41. data/lib/generators/nifty/scaffold/templates/tests/testunit/actions/create.rb +1 -1
  42. data/lib/generators/nifty/scaffold/templates/tests/testunit/actions/update.rb +1 -1
  43. data/rails_generators/nifty_authentication/USAGE +15 -15
  44. data/rails_generators/nifty_authentication/lib/insert_commands.rb +8 -8
  45. data/rails_generators/nifty_authentication/nifty_authentication_generator.rb +20 -20
  46. data/rails_generators/nifty_authentication/templates/authentication.rb +9 -9
  47. data/rails_generators/nifty_authentication/templates/migration.rb +1 -1
  48. data/rails_generators/nifty_authentication/templates/sessions_controller.rb +4 -4
  49. data/rails_generators/nifty_authentication/templates/tests/rspec/sessions_controller.rb +5 -5
  50. data/rails_generators/nifty_authentication/templates/tests/rspec/user.rb +15 -15
  51. data/rails_generators/nifty_authentication/templates/tests/rspec/users_controller.rb +4 -4
  52. data/rails_generators/nifty_authentication/templates/tests/shoulda/sessions_controller.rb +3 -3
  53. data/rails_generators/nifty_authentication/templates/tests/shoulda/user.rb +15 -15
  54. data/rails_generators/nifty_authentication/templates/tests/shoulda/users_controller.rb +2 -2
  55. data/rails_generators/nifty_authentication/templates/tests/testunit/sessions_controller.rb +3 -3
  56. data/rails_generators/nifty_authentication/templates/tests/testunit/user.rb +15 -15
  57. data/rails_generators/nifty_authentication/templates/tests/testunit/users_controller.rb +2 -2
  58. data/rails_generators/nifty_authentication/templates/user.rb +7 -7
  59. data/rails_generators/nifty_authentication/templates/users_controller.rb +1 -1
  60. data/rails_generators/nifty_config/USAGE +2 -2
  61. data/rails_generators/nifty_config/nifty_config_generator.rb +3 -3
  62. data/rails_generators/nifty_layout/USAGE +2 -2
  63. data/rails_generators/nifty_layout/nifty_layout_generator.rb +3 -3
  64. data/rails_generators/nifty_layout/templates/helper.rb +3 -3
  65. data/rails_generators/nifty_layout/templates/layout.html.erb +2 -2
  66. data/rails_generators/nifty_layout/templates/layout.html.haml +4 -4
  67. data/rails_generators/nifty_scaffold/USAGE +9 -9
  68. data/rails_generators/nifty_scaffold/nifty_scaffold_generator.rb +38 -38
  69. data/rails_generators/nifty_scaffold/templates/migration.rb +1 -1
  70. data/rails_generators/nifty_scaffold/templates/tests/rspec/actions/create.rb +1 -1
  71. data/rails_generators/nifty_scaffold/templates/tests/rspec/actions/update.rb +1 -1
  72. data/rails_generators/nifty_scaffold/templates/tests/rspec/controller.rb +2 -2
  73. data/rails_generators/nifty_scaffold/templates/tests/shoulda/actions/create.rb +1 -1
  74. data/rails_generators/nifty_scaffold/templates/tests/shoulda/actions/update.rb +1 -1
  75. data/rails_generators/nifty_scaffold/templates/tests/testunit/actions/create.rb +1 -1
  76. data/rails_generators/nifty_scaffold/templates/tests/testunit/actions/update.rb +1 -1
  77. data/test/test_helper.rb +7 -7
  78. data/test/test_nifty_authentication_generator.rb +30 -30
  79. data/test/test_nifty_config_generator.rb +4 -4
  80. data/test/test_nifty_layout_generator.rb +5 -5
  81. data/test/test_nifty_scaffold_generator.rb +93 -93
  82. metadata +6 -4
@@ -1,6 +1,6 @@
1
1
  !!!
2
2
  %html
3
-
3
+
4
4
  %head
5
5
  %title
6
6
  = yield(:title) || "Untitled"
@@ -9,13 +9,13 @@
9
9
  = javascript_include_tag :defaults
10
10
  = csrf_meta_tag
11
11
  = yield(:head)
12
-
12
+
13
13
  %body
14
14
  #container
15
15
  - flash.each do |name, msg|
16
16
  = content_tag :div, msg, :id => "flash_#{name}"
17
-
17
+
18
18
  - if show_title?
19
19
  %h1= yield(:title)
20
-
20
+
21
21
  = yield
@@ -7,15 +7,15 @@ module LayoutHelper
7
7
  content_for(:title) { page_title.to_s }
8
8
  @show_title = show_title
9
9
  end
10
-
10
+
11
11
  def show_title?
12
12
  @show_title
13
13
  end
14
-
14
+
15
15
  def stylesheet(*args)
16
16
  content_for(:head) { stylesheet_link_tag(*args) }
17
17
  end
18
-
18
+
19
19
  def javascript(*args)
20
20
  content_for(:head) { javascript_include_tag(*args) }
21
21
  end
@@ -1,66 +1,66 @@
1
- !primary_color = #4B7399
1
+ $primary_color: #4b7399
2
2
 
3
3
  body
4
- :background-color = !primary_color
5
- :font
6
- :family Verdana, Helvetica, Arial
7
- :size 14px
4
+ background-color: $primary_color
5
+ font:
6
+ family: Verdana, Helvetica, Arial
7
+ size: 14px
8
8
 
9
9
  a
10
- :color #0000FF
10
+ color: blue
11
11
  img
12
- :border none
12
+ border: none
13
13
 
14
14
  .clear
15
- :clear both
16
- :height 0
17
- :overflow hidden
15
+ clear: both
16
+ height: 0
17
+ overflow: hidden
18
18
 
19
19
  #container
20
- :width 75%
21
- :margin 0 auto
22
- :background #fff
23
- :padding 20px 40px
24
- :border solid 1px black
25
- :margin-top 20px
20
+ width: 75%
21
+ margin: 0 auto
22
+ background: white
23
+ padding: 20px 40px
24
+ border: solid 1px black
25
+ margin-top: 20px
26
26
 
27
27
  #flash_notice,
28
28
  #flash_error,
29
29
  #flash_alert
30
- :padding 5px 8px
31
- :margin 10px 0
30
+ padding: 5px 8px
31
+ margin: 10px 0
32
32
 
33
33
  #flash_notice
34
- :background-color #CFC
35
- :border solid 1px #6C6
34
+ background-color: #ccffcc
35
+ border: solid 1px #66cc66
36
36
 
37
37
  #flash_error,
38
38
  #flash_alert
39
- :background-color #FCC
40
- :border solid 1px #C66
39
+ background-color: #ffcccc
40
+ border: solid 1px #cc6666
41
41
 
42
42
  .fieldWithErrors
43
- :display inline
43
+ display: inline
44
44
 
45
45
  .error_messages
46
- :width 400px
47
- :border 2px solid #CF0000
48
- :padding 0
49
- :padding-bottom 12px
50
- :margin-bottom 20px
51
- :background-color #f0f0f0
52
- :font
53
- :size 12px
46
+ width: 400px
47
+ border: 2px solid #cf0000
48
+ padding: 0
49
+ padding-bottom: 12px
50
+ margin-bottom: 20px
51
+ background-color: #f0f0f0
52
+ font:
53
+ size: 12px
54
54
  h2
55
- :text-align left
56
- :padding 5px 5px 5px 15px
57
- :margin 0
58
- :font
59
- :weight bold
60
- :size 12px
61
- :background-color #c00
62
- :color #fff
55
+ text-align: left
56
+ padding: 5px 5px 5px 15px
57
+ margin: 0
58
+ font:
59
+ weight: bold
60
+ size: 12px
61
+ background-color: #cc0000
62
+ color: white
63
63
  p
64
- :margin 8px 10px
64
+ margin: 8px 10px
65
65
  ul
66
- :margin 0
66
+ margin: 0
@@ -3,17 +3,17 @@ Description:
3
3
  views. The resource is ready to use as a starting point for your restful,
4
4
  resource-oriented application. Tests or specs are also generated depending
5
5
  on if you have a "spec" directory or not.
6
-
6
+
7
7
  IMPORTANT: This generator uses the "title" helper method which is generated
8
8
  by the nifty_layout generator. You may want to run that generator first.
9
9
 
10
10
  Usage:
11
11
  Pass the name of the model, either CamelCased or under_scored, as the first
12
12
  argument along with an optional list of attribute pairs and controller actions.
13
-
13
+
14
14
  If no controller actions are specified, they will default to index, show,
15
15
  new, create, edit, update, and destroy.
16
-
16
+
17
17
  IMPORTANT: If no attribute pairs are specified, no model will be generated.
18
18
  It will try to determine the attributes from an existing model.
19
19
 
@@ -26,26 +26,26 @@ Usage:
26
26
  the create/show/update/destroy, forms to create and edit your posts, and
27
27
  an index that lists them all, as well as a map.resources :posts
28
28
  declaration in config/routes.rb.
29
-
29
+
30
30
  Adding an "!" in the mix of arguments will invert the passed controller
31
31
  actions. This will include all 7 controller actitons except the ones
32
32
  mentioned. This option doesn't affect model attributes.
33
33
 
34
34
  Examples:
35
35
  rails generate nifty:scaffold post
36
-
36
+
37
37
  Will create a controller called "posts" it will contain all seven
38
38
  CRUD actions along with the views. A model will NOT be created,
39
39
  instead it will look for an existing model and use those attributes.
40
-
40
+
41
41
  rails generate nifty:scaffold post name:string content:text index new edit
42
-
42
+
43
43
  Will create a Post model and migration file with the name and content
44
44
  attributes. It will also create a controller with index, new, create,
45
45
  edit, and update actions. Notice the create and update actions are
46
46
  added automatically with new and edit.
47
-
47
+
48
48
  rails generate nifty:scaffold post ! show new
49
-
49
+
50
50
  Creates a posts controller (no model) with index, edit, update, and
51
51
  destroy actions.
@@ -27,10 +27,12 @@ module Nifty
27
27
 
28
28
  @controller_actions = []
29
29
  @model_attributes = []
30
+ @skip_model = options.skip_model?
31
+ @invert_actions = options.invert?
30
32
 
31
33
  args_for_c_m.each do |arg|
32
34
  if arg == '!'
33
- options[:invert] = true
35
+ @invert_actions = true
34
36
  elsif arg.include?(':')
35
37
  @model_attributes << Rails::Generators::GeneratedAttribute.new(*arg.split(':'))
36
38
  else
@@ -43,12 +45,12 @@ module Nifty
43
45
  @controller_actions.uniq!
44
46
  @model_attributes.uniq!
45
47
 
46
- if options.invert? || @controller_actions.empty?
48
+ if @invert_actions || @controller_actions.empty?
47
49
  @controller_actions = all_actions - @controller_actions
48
50
  end
49
51
 
50
52
  if @model_attributes.empty?
51
- options[:skip_model] = true # default to skipping model if no attributes passed
53
+ @skip_model = true # skip model if no attributes
52
54
  if model_exists?
53
55
  model_columns_for_attributes.each do |column|
54
56
  @model_attributes << Rails::Generators::GeneratedAttribute.new(column.name.to_s, column.type.to_s)
@@ -60,7 +62,7 @@ module Nifty
60
62
  end
61
63
 
62
64
  def create_model
63
- unless options.skip_model?
65
+ unless @skip_model
64
66
  template 'model.rb', "app/models/#{singular_name}.rb"
65
67
  if options.rspec?
66
68
  template "tests/rspec/model.rb", "spec/models/#{singular_name}_spec.rb"
@@ -73,7 +75,7 @@ module Nifty
73
75
  end
74
76
 
75
77
  def create_migration
76
- unless options.skip_model? || options.skip_migration?
78
+ unless @skip_model || options.skip_migration?
77
79
  migration_template 'migration.rb', "db/migrate/create_#{plural_name}.rb"
78
80
  end
79
81
  end
@@ -105,7 +107,7 @@ module Nifty
105
107
  end
106
108
 
107
109
  private
108
-
110
+
109
111
  def form_partial?
110
112
  actions? :new, :edit
111
113
  end
@@ -9,7 +9,7 @@ class Create<%= plural_class_name %> < ActiveRecord::Migration
9
9
  <%- end -%>
10
10
  end
11
11
  end
12
-
12
+
13
13
  def self.down
14
14
  drop_table :<%= plural_name %>
15
15
  end
@@ -3,7 +3,7 @@
3
3
  post :create
4
4
  response.should render_template(:new)
5
5
  end
6
-
6
+
7
7
  it "create action should redirect when model is valid" do
8
8
  <%= class_name %>.any_instance.stubs(:valid?).returns(true)
9
9
  post :create
@@ -3,7 +3,7 @@
3
3
  put :update, :id => <%= class_name %>.first
4
4
  response.should render_template(:edit)
5
5
  end
6
-
6
+
7
7
  it "update action should redirect when model is valid" do
8
8
  <%= class_name %>.any_instance.stubs(:valid?).returns(true)
9
9
  put :update, :id => <%= class_name %>.first
@@ -1,8 +1,8 @@
1
1
  require File.dirname(__FILE__) + '/../spec_helper'
2
-
2
+
3
3
  describe <%= plural_class_name %>Controller do
4
4
  fixtures :all
5
- integrate_views
6
-
5
+ render_views
6
+
7
7
  <%= controller_methods 'tests/rspec/actions' %>
8
8
  end
@@ -4,7 +4,7 @@
4
4
  post :create
5
5
  assert_template 'new'
6
6
  end
7
-
7
+
8
8
  should "redirect when model is valid" do
9
9
  <%= class_name %>.any_instance.stubs(:valid?).returns(true)
10
10
  post :create
@@ -4,7 +4,7 @@
4
4
  put :update, :id => <%= class_name %>.first
5
5
  assert_template 'edit'
6
6
  end
7
-
7
+
8
8
  should "redirect when model is valid" do
9
9
  <%= class_name %>.any_instance.stubs(:valid?).returns(true)
10
10
  put :update, :id => <%= class_name %>.first
@@ -3,7 +3,7 @@
3
3
  post :create
4
4
  assert_template 'new'
5
5
  end
6
-
6
+
7
7
  def test_create_valid
8
8
  <%= class_name %>.any_instance.stubs(:valid?).returns(true)
9
9
  post :create
@@ -3,7 +3,7 @@
3
3
  put :update, :id => <%= class_name %>.first
4
4
  assert_template 'edit'
5
5
  end
6
-
6
+
7
7
  def test_update_valid
8
8
  <%= class_name %>.any_instance.stubs(:valid?).returns(true)
9
9
  put :update, :id => <%= class_name %>.first
@@ -1,9 +1,9 @@
1
1
  Description:
2
- Generates a user model, users controller, and sessions controller. The
3
- users controller handles the registration and the sessions controller
4
- handles authentication. This is similar to restful_authentication, but
2
+ Generates a user model, users controller, and sessions controller. The
3
+ users controller handles the registration and the sessions controller
4
+ handles authentication. This is similar to restful_authentication, but
5
5
  simpler.
6
-
6
+
7
7
  IMPORTANT: This generator uses the "title" helper method which is generated
8
8
  by the nifty_layout generator. You may want to run that generator first.
9
9
 
@@ -12,28 +12,28 @@ Usage:
12
12
  the authentication controller will default to "session". You can override
13
13
  each of these respectively by passing one or two arguments. Either name can
14
14
  be CamelCased or under_scored.
15
-
15
+
16
16
  Make sure to setup the authlogic gem if you are using that option.
17
-
17
+
18
18
  config.gem "authlogic"
19
19
 
20
20
  Examples:
21
21
  script/generate nifty_authentication
22
-
22
+
23
23
  Creates user model, users_controller, and sessions_controller.
24
-
24
+
25
25
  script/generate nifty_authentication account
26
-
26
+
27
27
  Creates account model, accounts_controller, and sessions_controller.
28
-
28
+
29
29
  script/generate nifty_authentication Account UserSession
30
-
30
+
31
31
  Creates account model, accounts_controller, and user_sessions_controller.
32
32
 
33
33
  Methods:
34
34
  There are several methods generated which you can use in your application.
35
35
  Here's a common example of what you might add to your layout.
36
-
36
+
37
37
  <% if logged_in? %>
38
38
  Welcome <%= current_user.username %>! Not you?
39
39
  <%= link_to "Log out", logout_path %>
@@ -41,10 +41,10 @@ Methods:
41
41
  <%= link_to "Sign up", signup_path %> or
42
42
  <%= link_to "log in", login_path %>.
43
43
  <% end %>
44
-
44
+
45
45
  You can also restrict unregistered users from accessing a controller using
46
46
  a before filter. For example.
47
-
47
+
48
48
  before_filter :login_required, :except => [:index, :show]
49
-
49
+
50
50
  See the generated file lib/authentication.rb for details.
@@ -2,7 +2,7 @@ Rails::Generator::Commands::Create.class_eval do
2
2
  def route_resource(*resources)
3
3
  resource_list = resources.map { |r| r.to_sym.inspect }.join(', ')
4
4
  sentinel = 'ActionController::Routing::Routes.draw do |map|'
5
-
5
+
6
6
  logger.route "map.resource #{resource_list}"
7
7
  unless options[:pretend]
8
8
  gsub_file 'config/routes.rb', /(#{Regexp.escape(sentinel)})/mi do |match|
@@ -10,10 +10,10 @@ Rails::Generator::Commands::Create.class_eval do
10
10
  end
11
11
  end
12
12
  end
13
-
13
+
14
14
  def route_name(name, path, route_options = {})
15
15
  sentinel = 'ActionController::Routing::Routes.draw do |map|'
16
-
16
+
17
17
  logger.route "map.#{name} '#{path}', :controller => '#{route_options[:controller]}', :action => '#{route_options[:action]}'"
18
18
  unless options[:pretend]
19
19
  gsub_file 'config/routes.rb', /(#{Regexp.escape(sentinel)})/mi do |match|
@@ -21,7 +21,7 @@ Rails::Generator::Commands::Create.class_eval do
21
21
  end
22
22
  end
23
23
  end
24
-
24
+
25
25
  def insert_into(file, line)
26
26
  logger.insert "#{line} into #{file}"
27
27
  unless options[:pretend]
@@ -41,7 +41,7 @@ Rails::Generator::Commands::Destroy.class_eval do
41
41
  gsub_file 'config/routes.rb', /(#{look_for})/mi, ''
42
42
  end
43
43
  end
44
-
44
+
45
45
  def route_name(name, path, route_options = {})
46
46
  look_for = "\n map.#{name} '#{path}', :controller => '#{route_options[:controller]}', :action => '#{route_options[:action]}'"
47
47
  logger.route "map.#{name} '#{path}', :controller => '#{route_options[:controller]}', :action => '#{route_options[:action]}'"
@@ -49,7 +49,7 @@ Rails::Generator::Commands::Destroy.class_eval do
49
49
  gsub_file 'config/routes.rb', /(#{look_for})/mi, ''
50
50
  end
51
51
  end
52
-
52
+
53
53
  def insert_into(file, line)
54
54
  logger.remove "#{line} from #{file}"
55
55
  unless options[:pretend]
@@ -63,11 +63,11 @@ Rails::Generator::Commands::List.class_eval do
63
63
  resource_list = resources.map { |r| r.to_sym.inspect }.join(', ')
64
64
  logger.route "map.resource #{resource_list}"
65
65
  end
66
-
66
+
67
67
  def route_name(name, path, options = {})
68
68
  logger.route "map.#{name} '#{path}', :controller => '{options[:controller]}', :action => '#{options[:action]}'"
69
69
  end
70
-
70
+
71
71
  def insert_into(file, line)
72
72
  logger.insert "#{line} into #{file}"
73
73
  end