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
@@ -7,14 +7,14 @@ class <%= user_plural_class_name %>ControllerTest < ActionController::TestCase
7
7
  assert_template 'new'
8
8
  end
9
9
  end
10
-
10
+
11
11
  context "create action" do
12
12
  should "render new template when model is invalid" do
13
13
  <%= user_class_name %>.any_instance.stubs(:valid?).returns(false)
14
14
  post :create
15
15
  assert_template 'new'
16
16
  end
17
-
17
+
18
18
  should "redirect when model is valid" do
19
19
  <%= user_class_name %>.any_instance.stubs(:valid?).returns(true)
20
20
  post :create
@@ -5,14 +5,14 @@ class <%= session_plural_class_name %>ControllerTest < ActionController::TestCas
5
5
  get :new
6
6
  assert_template 'new'
7
7
  end
8
-
8
+
9
9
  <%- if options[:authlogic] -%>
10
10
  def test_create_invalid
11
11
  post :create, :<%= session_singular_name %> => { :username => "foo", :password => "badpassword" }
12
12
  assert_template 'new'
13
13
  assert_nil <%= session_class_name %>.find
14
14
  end
15
-
15
+
16
16
  def test_create_valid
17
17
  post :create, :<%= session_singular_name %> => { :username => "foo", :password => "secret" }
18
18
  assert_redirected_to root_url
@@ -25,7 +25,7 @@ class <%= session_plural_class_name %>ControllerTest < ActionController::TestCas
25
25
  assert_template 'new'
26
26
  assert_nil session['<%= user_singular_name %>_id']
27
27
  end
28
-
28
+
29
29
  def test_create_valid
30
30
  <%= user_class_name %>.stubs(:authenticate).returns(<%= user_class_name %>.first)
31
31
  post :create
@@ -11,74 +11,74 @@ class <%= user_class_name %>Test < ActiveSupport::TestCase
11
11
  <%= user_singular_name %>.valid? # run validations
12
12
  <%= user_singular_name %>
13
13
  end
14
-
14
+
15
15
  def setup
16
16
  <%= user_class_name %>.delete_all
17
17
  end
18
-
18
+
19
19
  def test_valid
20
20
  assert new_<%= user_singular_name %>.valid?
21
21
  end
22
-
22
+
23
23
  def test_require_username
24
24
  assert new_<%= user_singular_name %>(:username => '').errors.on(:username)
25
25
  end
26
-
26
+
27
27
  def test_require_password
28
28
  assert new_<%= user_singular_name %>(:password => '').errors.on(:password)
29
29
  end
30
-
30
+
31
31
  def test_require_well_formed_email
32
32
  assert new_<%= user_singular_name %>(:email => 'foo@bar@example.com').errors.on(:email)
33
33
  end
34
-
34
+
35
35
  def test_validate_uniqueness_of_email
36
36
  new_<%= user_singular_name %>(:email => 'bar@example.com').save!
37
37
  assert new_<%= user_singular_name %>(:email => 'bar@example.com').errors.on(:email)
38
38
  end
39
-
39
+
40
40
  def test_validate_uniqueness_of_username
41
41
  new_<%= user_singular_name %>(:username => 'uniquename').save!
42
42
  assert new_<%= user_singular_name %>(:username => 'uniquename').errors.on(:username)
43
43
  end
44
-
44
+
45
45
  def test_validate_odd_characters_in_username
46
46
  assert new_<%= user_singular_name %>(:username => 'odd ^&(@)').errors.on(:username)
47
47
  end
48
-
48
+
49
49
  def test_validate_password_length
50
50
  assert new_<%= user_singular_name %>(:password => 'bad').errors.on(:password)
51
51
  end
52
-
52
+
53
53
  def test_require_matching_password_confirmation
54
54
  assert new_<%= user_singular_name %>(:password_confirmation => 'nonmatching').errors.on(:password)
55
55
  end
56
-
56
+
57
57
  def test_generate_password_hash_and_salt_on_create
58
58
  <%= user_singular_name %> = new_<%= user_singular_name %>
59
59
  <%= user_singular_name %>.save!
60
60
  assert <%= user_singular_name %>.password_hash
61
61
  assert <%= user_singular_name %>.password_salt
62
62
  end
63
-
63
+
64
64
  def test_authenticate_by_username
65
65
  <%= user_class_name %>.delete_all
66
66
  <%= user_singular_name %> = new_<%= user_singular_name %>(:username => 'foobar', :password => 'secret')
67
67
  <%= user_singular_name %>.save!
68
68
  assert_equal <%= user_singular_name %>, <%= user_class_name %>.authenticate('foobar', 'secret')
69
69
  end
70
-
70
+
71
71
  def test_authenticate_by_email
72
72
  <%= user_class_name %>.delete_all
73
73
  <%= user_singular_name %> = new_<%= user_singular_name %>(:email => 'foo@bar.com', :password => 'secret')
74
74
  <%= user_singular_name %>.save!
75
75
  assert_equal <%= user_singular_name %>, <%= user_class_name %>.authenticate('foo@bar.com', 'secret')
76
76
  end
77
-
77
+
78
78
  def test_authenticate_bad_username
79
79
  assert_nil <%= user_class_name %>.authenticate('nonexisting', 'secret')
80
80
  end
81
-
81
+
82
82
  def test_authenticate_bad_password
83
83
  <%= user_class_name %>.delete_all
84
84
  new_<%= user_singular_name %>(:username => 'foobar', :password => 'secret').save!
@@ -5,13 +5,13 @@ class <%= user_plural_class_name %>ControllerTest < ActionController::TestCase
5
5
  get :new
6
6
  assert_template 'new'
7
7
  end
8
-
8
+
9
9
  def test_create_invalid
10
10
  <%= user_class_name %>.any_instance.stubs(:valid?).returns(false)
11
11
  post :create
12
12
  assert_template 'new'
13
13
  end
14
-
14
+
15
15
  def test_create_valid
16
16
  <%= user_class_name %>.any_instance.stubs(:valid?).returns(true)
17
17
  post :create
@@ -4,10 +4,10 @@ class <%= user_class_name %> < ActiveRecord::Base
4
4
  <%- else -%>
5
5
  # new columns need to be added here to be writable through mass assignment
6
6
  attr_accessible :username, :email, :password, :password_confirmation
7
-
7
+
8
8
  attr_accessor :password
9
9
  before_save :prepare_password
10
-
10
+
11
11
  validates_presence_of :username
12
12
  validates_uniqueness_of :username, :email, :allow_blank => true
13
13
  validates_format_of :username, :with => /^[-\w\._@]+$/i, :allow_blank => true, :message => "should only contain letters, numbers, or .-_@"
@@ -15,26 +15,26 @@ class <%= user_class_name %> < ActiveRecord::Base
15
15
  validates_presence_of :password, :on => :create
16
16
  validates_confirmation_of :password
17
17
  validates_length_of :password, :minimum => 4, :allow_blank => true
18
-
18
+
19
19
  # login can be either username or email address
20
20
  def self.authenticate(login, pass)
21
21
  <%= user_singular_name %> = find_by_username(login) || find_by_email(login)
22
22
  return <%= user_singular_name %> if <%= user_singular_name %> && <%= user_singular_name %>.matching_password?(pass)
23
23
  end
24
-
24
+
25
25
  def matching_password?(pass)
26
26
  self.password_hash == encrypt_password(pass)
27
27
  end
28
-
28
+
29
29
  private
30
-
30
+
31
31
  def prepare_password
32
32
  unless password.blank?
33
33
  self.password_salt = Digest::SHA1.hexdigest([Time.now, rand].join)
34
34
  self.password_hash = encrypt_password(password)
35
35
  end
36
36
  end
37
-
37
+
38
38
  def encrypt_password(pass)
39
39
  Digest::SHA1.hexdigest([pass, password_salt].join)
40
40
  end
@@ -2,7 +2,7 @@ class <%= user_plural_class_name %>Controller < ApplicationController
2
2
  def new
3
3
  @<%= user_singular_name %> = <%= user_class_name %>.new
4
4
  end
5
-
5
+
6
6
  def create
7
7
  @<%= user_singular_name %> = <%= user_class_name %>.new(params[:<%= user_singular_name %>])
8
8
  if @<%= user_singular_name %>.save
@@ -3,11 +3,11 @@ Description:
3
3
  directory and an initializer to load this config. The config has a
4
4
  separate section for each environment. This is a great place to put
5
5
  any config settings you don't want in your app.
6
-
6
+
7
7
  The config is loaded into a constant called APP_CONFIG by default,
8
8
  this changes depending on the name you choose to pass the generator.
9
9
  Use this constant to access the config settings like this.
10
-
10
+
11
11
  APP_CONFIG[:some_setting]
12
12
 
13
13
 
@@ -3,7 +3,7 @@ class NiftyConfigGenerator < Rails::Generator::Base
3
3
  super
4
4
  @name = @args.first || 'app'
5
5
  end
6
-
6
+
7
7
  def manifest
8
8
  record do |m|
9
9
  m.directory 'config/initializers'
@@ -12,11 +12,11 @@ class NiftyConfigGenerator < Rails::Generator::Base
12
12
  m.file "config.yml", "config/#{file_name}_config.yml"
13
13
  end
14
14
  end
15
-
15
+
16
16
  def file_name
17
17
  @name.underscore
18
18
  end
19
-
19
+
20
20
  def constant_name
21
21
  @name.underscore.upcase
22
22
  end
@@ -1,11 +1,11 @@
1
1
  Description:
2
2
  The nifty_layout generator creates a basic layout, stylesheet and
3
3
  helper which will give some structure to a starting Rails app.
4
-
4
+
5
5
  The generator takes one argument which will be the name of the
6
6
  layout and stylesheet files. If no argument is passed then it defaults
7
7
  to "application".
8
-
8
+
9
9
  The helper module includes some methods which can be called in any
10
10
  template or partial to set variables to be used in the layout, such as
11
11
  page title and javascript/stylesheet includes.
@@ -3,13 +3,13 @@ class NiftyLayoutGenerator < Rails::Generator::Base
3
3
  super
4
4
  @name = @args.first || 'application'
5
5
  end
6
-
6
+
7
7
  def manifest
8
8
  record do |m|
9
9
  m.directory 'app/views/layouts'
10
10
  m.directory 'public/stylesheets'
11
11
  m.directory 'app/helpers'
12
-
12
+
13
13
  if options[:haml]
14
14
  m.directory 'public/stylesheets/sass'
15
15
  m.template "layout.html.haml", "app/views/layouts/#{file_name}.html.haml"
@@ -21,7 +21,7 @@ class NiftyLayoutGenerator < Rails::Generator::Base
21
21
  m.file "helper.rb", "app/helpers/layout_helper.rb"
22
22
  end
23
23
  end
24
-
24
+
25
25
  def file_name
26
26
  @name.underscore
27
27
  end
@@ -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
@@ -11,11 +11,11 @@
11
11
  <%%- flash.each do |name, msg| -%>
12
12
  <%%= content_tag :div, msg, :id => "flash_#{name}" %>
13
13
  <%%- end -%>
14
-
14
+
15
15
  <%%- if show_title? -%>
16
16
  <h1><%%=h yield(:title) %></h1>
17
17
  <%%- end -%>
18
-
18
+
19
19
  <%%= yield %>
20
20
  </div>
21
21
  </body>
@@ -1,19 +1,19 @@
1
1
  !!! Strict
2
2
  %html{html_attrs}
3
-
3
+
4
4
  %head
5
5
  %title
6
6
  = h(yield(:title) || "Untitled")
7
7
  %meta{"http-equiv"=>"Content-Type", :content=>"text/html; charset=utf-8"}/
8
8
  = stylesheet_link_tag '<%= file_name %>'
9
9
  = yield(:head)
10
-
10
+
11
11
  %body
12
12
  #container
13
13
  - flash.each do |name, msg|
14
14
  = content_tag :div, msg, :id => "flash_#{name}"
15
-
15
+
16
16
  - if show_title?
17
17
  %h1=h yield(:title)
18
-
18
+
19
19
  = yield
@@ -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
  script/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
  script/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
  script/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.
@@ -1,14 +1,14 @@
1
1
  class NiftyScaffoldGenerator < Rails::Generator::Base
2
2
  attr_accessor :name, :attributes, :controller_actions
3
-
3
+
4
4
  def initialize(runtime_args, runtime_options = {})
5
5
  super
6
6
  usage if @args.empty?
7
-
7
+
8
8
  @name = @args.first
9
9
  @controller_actions = []
10
10
  @attributes = []
11
-
11
+
12
12
  @args[1..-1].each do |arg|
13
13
  if arg == '!'
14
14
  options[:invert] = true
@@ -20,14 +20,14 @@ class NiftyScaffoldGenerator < Rails::Generator::Base
20
20
  @controller_actions << 'update' if arg == 'edit'
21
21
  end
22
22
  end
23
-
23
+
24
24
  @controller_actions.uniq!
25
25
  @attributes.uniq!
26
-
26
+
27
27
  if options[:invert] || @controller_actions.empty?
28
28
  @controller_actions = all_actions - @controller_actions
29
29
  end
30
-
30
+
31
31
  if @attributes.empty?
32
32
  options[:skip_model] = true # default to skipping model if no attributes passed
33
33
  if model_exists?
@@ -39,7 +39,7 @@ class NiftyScaffoldGenerator < Rails::Generator::Base
39
39
  end
40
40
  end
41
41
  end
42
-
42
+
43
43
  def manifest
44
44
  record do |m|
45
45
  unless options[:skip_model]
@@ -48,7 +48,7 @@ class NiftyScaffoldGenerator < Rails::Generator::Base
48
48
  unless options[:skip_migration]
49
49
  m.migration_template "migration.rb", "db/migrate", :migration_file_name => "create_#{plural_name}"
50
50
  end
51
-
51
+
52
52
  if rspec?
53
53
  m.directory "spec/models"
54
54
  m.template "tests/#{test_framework}/model.rb", "spec/models/#{singular_name}_spec.rb"
@@ -61,27 +61,27 @@ class NiftyScaffoldGenerator < Rails::Generator::Base
61
61
  m.template "fixtures.yml", "test/fixtures/#{plural_name}.yml"
62
62
  end
63
63
  end
64
-
64
+
65
65
  unless options[:skip_controller]
66
66
  m.directory "app/controllers"
67
67
  m.template "controller.rb", "app/controllers/#{plural_name}_controller.rb"
68
-
68
+
69
69
  m.directory "app/helpers"
70
70
  m.template "helper.rb", "app/helpers/#{plural_name}_helper.rb"
71
-
71
+
72
72
  m.directory "app/views/#{plural_name}"
73
73
  controller_actions.each do |action|
74
74
  if File.exist? source_path("views/#{view_language}/#{action}.html.#{view_language}")
75
75
  m.template "views/#{view_language}/#{action}.html.#{view_language}", "app/views/#{plural_name}/#{action}.html.#{view_language}"
76
76
  end
77
77
  end
78
-
78
+
79
79
  if form_partial?
80
80
  m.template "views/#{view_language}/_form.html.#{view_language}", "app/views/#{plural_name}/_form.html.#{view_language}"
81
81
  end
82
-
82
+
83
83
  m.route_resources plural_name
84
-
84
+
85
85
  if rspec?
86
86
  m.directory "spec/controllers"
87
87
  m.template "tests/#{test_framework}/controller.rb", "spec/controllers/#{plural_name}_controller_spec.rb"
@@ -92,45 +92,45 @@ class NiftyScaffoldGenerator < Rails::Generator::Base
92
92
  end
93
93
  end
94
94
  end
95
-
95
+
96
96
  def form_partial?
97
97
  actions? :new, :edit
98
98
  end
99
-
99
+
100
100
  def all_actions
101
101
  %w[index show new create edit update destroy]
102
102
  end
103
-
103
+
104
104
  def action?(name)
105
105
  controller_actions.include? name.to_s
106
106
  end
107
-
107
+
108
108
  def actions?(*names)
109
109
  names.all? { |n| action? n.to_s }
110
110
  end
111
-
111
+
112
112
  def singular_name
113
113
  name.underscore
114
114
  end
115
-
115
+
116
116
  def plural_name
117
117
  name.underscore.pluralize
118
118
  end
119
-
119
+
120
120
  def class_name
121
121
  name.camelize
122
122
  end
123
-
123
+
124
124
  def plural_class_name
125
125
  plural_name.camelize
126
126
  end
127
-
127
+
128
128
  def controller_methods(dir_name)
129
129
  controller_actions.map do |action|
130
130
  read_template("#{dir_name}/#{action}.rb")
131
131
  end.join(" \n").strip
132
132
  end
133
-
133
+
134
134
  def render_form
135
135
  if form_partial?
136
136
  if options[:haml]
@@ -142,7 +142,7 @@ class NiftyScaffoldGenerator < Rails::Generator::Base
142
142
  read_template("views/#{view_language}/_form.html.#{view_language}")
143
143
  end
144
144
  end
145
-
145
+
146
146
  def items_path(suffix = 'path')
147
147
  if action? :index
148
148
  "#{plural_name}_#{suffix}"
@@ -150,7 +150,7 @@ class NiftyScaffoldGenerator < Rails::Generator::Base
150
150
  "root_#{suffix}"
151
151
  end
152
152
  end
153
-
153
+
154
154
  def item_path(suffix = 'path')
155
155
  if action? :show
156
156
  "@#{singular_name}"
@@ -158,7 +158,7 @@ class NiftyScaffoldGenerator < Rails::Generator::Base
158
158
  items_path(suffix)
159
159
  end
160
160
  end
161
-
161
+
162
162
  def item_path_for_spec(suffix = 'path')
163
163
  if action? :show
164
164
  "#{singular_name}_#{suffix}(assigns[:#{singular_name}])"
@@ -166,7 +166,7 @@ class NiftyScaffoldGenerator < Rails::Generator::Base
166
166
  items_path(suffix)
167
167
  end
168
168
  end
169
-
169
+
170
170
  def item_path_for_test(suffix = 'path')
171
171
  if action? :show
172
172
  "#{singular_name}_#{suffix}(assigns(:#{singular_name}))"
@@ -174,31 +174,31 @@ class NiftyScaffoldGenerator < Rails::Generator::Base
174
174
  items_path(suffix)
175
175
  end
176
176
  end
177
-
177
+
178
178
  def model_columns_for_attributes
179
179
  class_name.constantize.columns.reject do |column|
180
180
  column.name.to_s =~ /^(id|created_at|updated_at)$/
181
181
  end
182
182
  end
183
-
183
+
184
184
  def rspec?
185
185
  test_framework == :rspec
186
186
  end
187
-
187
+
188
188
  protected
189
-
189
+
190
190
  def view_language
191
191
  options[:haml] ? 'haml' : 'erb'
192
192
  end
193
-
193
+
194
194
  def test_framework
195
195
  options[:test_framework] ||= default_test_framework
196
196
  end
197
-
197
+
198
198
  def default_test_framework
199
199
  File.exist?(destination_path("spec")) ? :rspec : :testunit
200
200
  end
201
-
201
+
202
202
  def add_options!(opt)
203
203
  opt.separator ''
204
204
  opt.separator 'Options:'
@@ -212,16 +212,16 @@ protected
212
212
  opt.on("--rspec", "Use RSpec for test files.") { options[:test_framework] = :rspec }
213
213
  opt.on("--shoulda", "Use Shoulda for test files.") { options[:test_framework] = :shoulda }
214
214
  end
215
-
215
+
216
216
  # is there a better way to do this? Perhaps with const_defined?
217
217
  def model_exists?
218
218
  File.exist? destination_path("app/models/#{singular_name}.rb")
219
219
  end
220
-
220
+
221
221
  def read_template(relative_path)
222
222
  ERB.new(File.read(source_path(relative_path)), nil, '-').result(binding)
223
223
  end
224
-
224
+
225
225
  def banner
226
226
  <<-EOS
227
227
  Creates a controller and optional model given the name, actions, and attributes.