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.
- data/CHANGELOG +11 -0
- data/README.rdoc +2 -2
- data/features/nifty_authentication.feature +2 -2
- data/features/nifty_scaffold.feature +15 -0
- data/features/step_definitions/common_steps.rb +1 -1
- data/features/step_definitions/rails_setup_steps.rb +1 -1
- data/lib/generators/nifty.rb +2 -2
- data/lib/generators/nifty/authentication/USAGE +15 -15
- data/lib/generators/nifty/authentication/authentication_generator.rb +10 -9
- data/lib/generators/nifty/authentication/templates/authentication.rb +9 -9
- data/lib/generators/nifty/authentication/templates/migration.rb +1 -1
- data/lib/generators/nifty/authentication/templates/sessions_controller.rb +4 -4
- data/lib/generators/nifty/authentication/templates/tests/rspec/sessions_controller.rb +6 -6
- data/lib/generators/nifty/authentication/templates/tests/rspec/user.rb +15 -15
- data/lib/generators/nifty/authentication/templates/tests/rspec/users_controller.rb +5 -5
- data/lib/generators/nifty/authentication/templates/tests/shoulda/sessions_controller.rb +3 -3
- data/lib/generators/nifty/authentication/templates/tests/shoulda/user.rb +15 -15
- data/lib/generators/nifty/authentication/templates/tests/shoulda/users_controller.rb +2 -2
- data/lib/generators/nifty/authentication/templates/tests/testunit/sessions_controller.rb +3 -3
- data/lib/generators/nifty/authentication/templates/tests/testunit/user.rb +15 -15
- data/lib/generators/nifty/authentication/templates/tests/testunit/users_controller.rb +2 -2
- data/lib/generators/nifty/authentication/templates/user.rb +7 -7
- data/lib/generators/nifty/authentication/templates/users_controller.rb +1 -1
- data/lib/generators/nifty/config/USAGE +2 -2
- data/lib/generators/nifty/config/config_generator.rb +3 -3
- data/lib/generators/nifty/layout/USAGE +2 -2
- data/lib/generators/nifty/layout/layout_generator.rb +4 -4
- data/lib/generators/nifty/layout/templates/error_messages_helper.rb +2 -2
- data/lib/generators/nifty/layout/templates/layout.html.erb +1 -1
- data/lib/generators/nifty/layout/templates/layout.html.haml +4 -4
- data/lib/generators/nifty/layout/templates/layout_helper.rb +3 -3
- data/lib/generators/nifty/layout/templates/stylesheet.sass +41 -41
- data/lib/generators/nifty/scaffold/USAGE +9 -9
- data/lib/generators/nifty/scaffold/scaffold_generator.rb +8 -6
- data/lib/generators/nifty/scaffold/templates/migration.rb +1 -1
- data/lib/generators/nifty/scaffold/templates/tests/rspec/actions/create.rb +1 -1
- data/lib/generators/nifty/scaffold/templates/tests/rspec/actions/update.rb +1 -1
- data/lib/generators/nifty/scaffold/templates/tests/rspec/controller.rb +3 -3
- data/lib/generators/nifty/scaffold/templates/tests/shoulda/actions/create.rb +1 -1
- data/lib/generators/nifty/scaffold/templates/tests/shoulda/actions/update.rb +1 -1
- data/lib/generators/nifty/scaffold/templates/tests/testunit/actions/create.rb +1 -1
- data/lib/generators/nifty/scaffold/templates/tests/testunit/actions/update.rb +1 -1
- data/rails_generators/nifty_authentication/USAGE +15 -15
- data/rails_generators/nifty_authentication/lib/insert_commands.rb +8 -8
- data/rails_generators/nifty_authentication/nifty_authentication_generator.rb +20 -20
- data/rails_generators/nifty_authentication/templates/authentication.rb +9 -9
- data/rails_generators/nifty_authentication/templates/migration.rb +1 -1
- data/rails_generators/nifty_authentication/templates/sessions_controller.rb +4 -4
- data/rails_generators/nifty_authentication/templates/tests/rspec/sessions_controller.rb +5 -5
- data/rails_generators/nifty_authentication/templates/tests/rspec/user.rb +15 -15
- data/rails_generators/nifty_authentication/templates/tests/rspec/users_controller.rb +4 -4
- data/rails_generators/nifty_authentication/templates/tests/shoulda/sessions_controller.rb +3 -3
- data/rails_generators/nifty_authentication/templates/tests/shoulda/user.rb +15 -15
- data/rails_generators/nifty_authentication/templates/tests/shoulda/users_controller.rb +2 -2
- data/rails_generators/nifty_authentication/templates/tests/testunit/sessions_controller.rb +3 -3
- data/rails_generators/nifty_authentication/templates/tests/testunit/user.rb +15 -15
- data/rails_generators/nifty_authentication/templates/tests/testunit/users_controller.rb +2 -2
- data/rails_generators/nifty_authentication/templates/user.rb +7 -7
- data/rails_generators/nifty_authentication/templates/users_controller.rb +1 -1
- data/rails_generators/nifty_config/USAGE +2 -2
- data/rails_generators/nifty_config/nifty_config_generator.rb +3 -3
- data/rails_generators/nifty_layout/USAGE +2 -2
- data/rails_generators/nifty_layout/nifty_layout_generator.rb +3 -3
- data/rails_generators/nifty_layout/templates/helper.rb +3 -3
- data/rails_generators/nifty_layout/templates/layout.html.erb +2 -2
- data/rails_generators/nifty_layout/templates/layout.html.haml +4 -4
- data/rails_generators/nifty_scaffold/USAGE +9 -9
- data/rails_generators/nifty_scaffold/nifty_scaffold_generator.rb +38 -38
- data/rails_generators/nifty_scaffold/templates/migration.rb +1 -1
- data/rails_generators/nifty_scaffold/templates/tests/rspec/actions/create.rb +1 -1
- data/rails_generators/nifty_scaffold/templates/tests/rspec/actions/update.rb +1 -1
- data/rails_generators/nifty_scaffold/templates/tests/rspec/controller.rb +2 -2
- data/rails_generators/nifty_scaffold/templates/tests/shoulda/actions/create.rb +1 -1
- data/rails_generators/nifty_scaffold/templates/tests/shoulda/actions/update.rb +1 -1
- data/rails_generators/nifty_scaffold/templates/tests/testunit/actions/create.rb +1 -1
- data/rails_generators/nifty_scaffold/templates/tests/testunit/actions/update.rb +1 -1
- data/test/test_helper.rb +7 -7
- data/test/test_nifty_authentication_generator.rb +30 -30
- data/test/test_nifty_config_generator.rb +4 -4
- data/test/test_nifty_layout_generator.rb +5 -5
- data/test/test_nifty_scaffold_generator.rb +93 -93
- metadata +6 -4
@@ -1,20 +1,20 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
-
|
2
|
+
|
3
3
|
describe <%= user_plural_class_name %>Controller do
|
4
4
|
fixtures :all
|
5
|
-
|
6
|
-
|
5
|
+
render_views
|
6
|
+
|
7
7
|
it "new action should render new template" do
|
8
8
|
get :new
|
9
9
|
response.should render_template(:new)
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
12
|
it "create action 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
|
response.should render_template(:new)
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
it "create action should redirect when model is valid" do
|
19
19
|
<%= user_class_name %>.any_instance.stubs(:valid?).returns(true)
|
20
20
|
post :create
|
@@ -7,7 +7,7 @@ class <%= session_plural_class_name %>ControllerTest < ActionController::TestCas
|
|
7
7
|
assert_template 'new'
|
8
8
|
end
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
11
|
context "create action" do
|
12
12
|
<%- if options[:authlogic] -%>
|
13
13
|
should "render new template when authentication is invalid" do
|
@@ -15,7 +15,7 @@ class <%= session_plural_class_name %>ControllerTest < ActionController::TestCas
|
|
15
15
|
assert_template 'new'
|
16
16
|
assert_nil <%= session_class_name %>.find
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
should "redirect when authentication is valid" do
|
20
20
|
post :create, :<%= session_singular_name %> => { :username => "foo", :password => "secret" }
|
21
21
|
assert_redirected_to "/"
|
@@ -28,7 +28,7 @@ class <%= session_plural_class_name %>ControllerTest < ActionController::TestCas
|
|
28
28
|
assert_template 'new'
|
29
29
|
assert_nil session['<%= user_singular_name %>_id']
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
should "redirect when authentication is valid" do
|
33
33
|
<%= user_class_name %>.stubs(:authenticate).returns(<%= user_class_name %>.first)
|
34
34
|
post :create
|
@@ -11,72 +11,72 @@ 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
|
should "be valid" do
|
20
20
|
assert new_<%= user_singular_name %>.valid?
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
should "require username" do
|
24
24
|
assert new_<%= user_singular_name %>(:username => '').errors[:username]
|
25
25
|
end
|
26
|
-
|
26
|
+
|
27
27
|
should "require password" do
|
28
28
|
assert new_<%= user_singular_name %>(:password => '').errors[:password]
|
29
29
|
end
|
30
|
-
|
30
|
+
|
31
31
|
should "require well formed email" do
|
32
32
|
assert new_<%= user_singular_name %>(:email => 'foo@bar@example.com').errors[:email]
|
33
33
|
end
|
34
|
-
|
34
|
+
|
35
35
|
should "validate uniqueness of email" do
|
36
36
|
new_<%= user_singular_name %>(:email => 'bar@example.com').save!
|
37
37
|
assert new_<%= user_singular_name %>(:email => 'bar@example.com').errors[:email]
|
38
38
|
end
|
39
|
-
|
39
|
+
|
40
40
|
should "validate uniqueness of username" do
|
41
41
|
new_<%= user_singular_name %>(:username => 'uniquename').save!
|
42
42
|
assert new_<%= user_singular_name %>(:username => 'uniquename').errors[:username]
|
43
43
|
end
|
44
|
-
|
44
|
+
|
45
45
|
should "not allow odd characters in username" do
|
46
46
|
assert new_<%= user_singular_name %>(:username => 'odd ^&(@)').errors[:username]
|
47
47
|
end
|
48
|
-
|
48
|
+
|
49
49
|
should "validate password is longer than 3 characters" do
|
50
50
|
assert new_<%= user_singular_name %>(:password => 'bad').errors[:password]
|
51
51
|
end
|
52
|
-
|
52
|
+
|
53
53
|
should "require matching password confirmation" do
|
54
54
|
assert new_<%= user_singular_name %>(:password_confirmation => 'nonmatching').errors[:password]
|
55
55
|
end
|
56
|
-
|
56
|
+
|
57
57
|
should "generate password hash and salt on create" do
|
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
|
should "authenticate by username" do
|
65
65
|
<%= user_singular_name %> = new_<%= user_singular_name %>(:username => 'foobar', :password => 'secret')
|
66
66
|
<%= user_singular_name %>.save!
|
67
67
|
assert_equal <%= user_singular_name %>, <%= user_class_name %>.authenticate('foobar', 'secret')
|
68
68
|
end
|
69
|
-
|
69
|
+
|
70
70
|
should "authenticate by email" do
|
71
71
|
<%= user_singular_name %> = new_<%= user_singular_name %>(:email => 'foo@bar.com', :password => 'secret')
|
72
72
|
<%= user_singular_name %>.save!
|
73
73
|
assert_equal <%= user_singular_name %>, <%= user_class_name %>.authenticate('foo@bar.com', 'secret')
|
74
74
|
end
|
75
|
-
|
75
|
+
|
76
76
|
should "not authenticate bad username" do
|
77
77
|
assert_nil <%= user_class_name %>.authenticate('nonexisting', 'secret')
|
78
78
|
end
|
79
|
-
|
79
|
+
|
80
80
|
should "not authenticate bad password" do
|
81
81
|
new_<%= user_singular_name %>(:username => 'foobar', :password => 'secret').save!
|
82
82
|
assert_nil <%= user_class_name %>.authenticate('foobar', 'badpassword')
|
@@ -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 "/"
|
@@ -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[:username]
|
25
25
|
end
|
26
|
-
|
26
|
+
|
27
27
|
def test_require_password
|
28
28
|
assert new_<%= user_singular_name %>(:password => '').errors[: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[: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[: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[: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[:username]
|
47
47
|
end
|
48
|
-
|
48
|
+
|
49
49
|
def test_validate_password_length
|
50
50
|
assert new_<%= user_singular_name %>(:password => 'bad').errors[: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[: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
|
|
@@ -4,14 +4,14 @@ module Nifty
|
|
4
4
|
module Generators
|
5
5
|
class ConfigGenerator < Base
|
6
6
|
argument :config_name, :type => :string, :default => 'app', :banner => 'config_name'
|
7
|
-
|
7
|
+
|
8
8
|
def create_config
|
9
9
|
template "load_config.rb", "config/initializers/load_#{file_name}_config.rb"
|
10
10
|
copy_file "config.yml", "config/#{file_name}_config.yml"
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
13
|
private
|
14
|
-
|
14
|
+
|
15
15
|
def file_name
|
16
16
|
config_name.underscore
|
17
17
|
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.
|
@@ -4,9 +4,9 @@ module Nifty
|
|
4
4
|
module Generators
|
5
5
|
class LayoutGenerator < Base
|
6
6
|
argument :layout_name, :type => :string, :default => 'application', :banner => 'layout_name'
|
7
|
-
|
7
|
+
|
8
8
|
class_option :haml, :desc => 'Generate HAML for view, and SASS for stylesheet.', :type => :boolean
|
9
|
-
|
9
|
+
|
10
10
|
def create_layout
|
11
11
|
if options.haml?
|
12
12
|
template 'layout.html.haml', "app/views/layouts/#{file_name}.html.haml"
|
@@ -18,9 +18,9 @@ module Nifty
|
|
18
18
|
copy_file 'layout_helper.rb', 'app/helpers/layout_helper.rb'
|
19
19
|
copy_file 'error_messages_helper.rb', 'app/helpers/error_messages_helper.rb'
|
20
20
|
end
|
21
|
-
|
21
|
+
|
22
22
|
private
|
23
|
-
|
23
|
+
|
24
24
|
def file_name
|
25
25
|
layout_name.underscore
|
26
26
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module ErrorMessagesHelper
|
2
2
|
# Render error messages for the given objects. The :message and :header_message options are allowed.
|
3
3
|
def error_messages_for(*objects)
|
4
|
-
options = objects.extract_options!
|
4
|
+
options = objects.extract_options!
|
5
5
|
options[:header_message] ||= "Invalid Fields"
|
6
6
|
options[:message] ||= "Correct the following errors and try again."
|
7
7
|
messages = objects.compact.map { |o| o.errors.full_messages }.flatten
|
@@ -12,7 +12,7 @@ module ErrorMessagesHelper
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
module FormBuilderAdditions
|
17
17
|
def error_messages(options = {})
|
18
18
|
@template.error_messages_for(@object, options)
|
@@ -1,7 +1,7 @@
|
|
1
1
|
<!DOCTYPE html>
|
2
2
|
<html>
|
3
3
|
<head>
|
4
|
-
<title><%%= yield(:title)
|
4
|
+
<title><%%= content_for?(:title) ? yield(:title) : "Untitled" %></title>
|
5
5
|
<%%= stylesheet_link_tag "<%= file_name %>" %>
|
6
6
|
<%%= javascript_include_tag :defaults %>
|
7
7
|
<%%= csrf_meta_tag %>
|