dust-generators 0.0.1.pre2 → 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +11 -10
- data/lib/generators/dust/authentication/USAGE +50 -0
- data/lib/generators/dust/authentication/authentication_generator.rb +154 -0
- data/lib/generators/dust/authentication/templates/authlogic_session.rb +2 -0
- data/lib/generators/dust/authentication/templates/controller_authentication.rb +61 -0
- data/lib/generators/dust/authentication/templates/fixtures.yml +24 -0
- data/lib/generators/dust/authentication/templates/migration.rb +20 -0
- data/lib/generators/dust/authentication/templates/sessions_controller.rb +45 -0
- data/lib/generators/dust/authentication/templates/sessions_helper.rb +2 -0
- data/lib/generators/dust/authentication/templates/tests/rspec/sessions_controller.rb +39 -0
- data/lib/generators/dust/authentication/templates/tests/rspec/user.rb +83 -0
- data/lib/generators/dust/authentication/templates/tests/rspec/users_controller.rb +56 -0
- data/lib/generators/dust/authentication/templates/tests/shoulda/sessions_controller.rb +40 -0
- data/lib/generators/dust/authentication/templates/tests/shoulda/user.rb +85 -0
- data/lib/generators/dust/authentication/templates/tests/shoulda/users_controller.rb +61 -0
- data/lib/generators/dust/authentication/templates/tests/testunit/sessions_controller.rb +36 -0
- data/lib/generators/dust/authentication/templates/tests/testunit/user.rb +88 -0
- data/lib/generators/dust/authentication/templates/tests/testunit/users_controller.rb +53 -0
- data/lib/generators/dust/authentication/templates/user.rb +42 -0
- data/lib/generators/dust/authentication/templates/users_controller.rb +34 -0
- data/lib/generators/dust/authentication/templates/users_helper.rb +2 -0
- data/lib/generators/dust/authentication/templates/views/erb/_form.html.erb +20 -0
- data/lib/generators/dust/authentication/templates/views/erb/edit.html.erb +3 -0
- data/lib/generators/dust/authentication/templates/views/erb/login.html.erb +30 -0
- data/lib/generators/dust/authentication/templates/views/erb/signup.html.erb +5 -0
- data/lib/generators/dust/authentication/templates/views/haml/_form.html.haml +20 -0
- data/lib/generators/dust/authentication/templates/views/haml/edit.html.haml +3 -0
- data/lib/generators/dust/authentication/templates/views/haml/login.html.haml +30 -0
- data/lib/generators/dust/authentication/templates/views/haml/signup.html.haml +5 -0
- data/lib/generators/dust/config/config_generator.rb +1 -1
- data/lib/generators/dust/layout/USAGE +25 -0
- data/lib/generators/dust/layout/layout_generator.rb +29 -0
- data/lib/generators/dust/layout/templates/error_messages_helper.rb +23 -0
- data/lib/generators/dust/layout/templates/layout.html.erb +19 -0
- data/lib/generators/dust/layout/templates/layout.html.haml +21 -0
- data/lib/generators/dust/layout/templates/layout_helper.rb +22 -0
- data/lib/generators/dust/layout/templates/stylesheet.css +75 -0
- data/lib/generators/dust/layout/templates/stylesheet.sass +66 -0
- data/lib/generators/dust/scaffold/scaffold_generator.rb +1 -3
- data/lib/generators/dust/scaffold/templates/actions/index.rb +1 -1
- data/lib/generators/dust/scaffold/templates/model.rb +0 -12
- data/lib/generators/dust/scaffold/templates/views/erb/_form.html.erb +4 -10
- data/lib/generators/dust/scaffold/templates/views/erb/edit.html.erb +12 -2
- data/lib/generators/dust/scaffold/templates/views/erb/index.html.erb +26 -21
- data/lib/generators/dust/scaffold/templates/views/erb/new.html.erb +3 -1
- data/lib/generators/dust/scaffold/templates/views/erb/show.html.erb +18 -20
- metadata +43 -12
- data/lib/dust/version.rb +0 -10
- data/lib/generators/dust/scaffold/templates/views/erb/_search.html.erb +0 -6
@@ -0,0 +1,85 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class <%= user_class_name %>Test < ActiveSupport::TestCase
|
4
|
+
<%- unless options[:authlogic] -%>
|
5
|
+
def new_<%= user_singular_name %>(attributes = {})
|
6
|
+
attributes[:username] ||= 'foo'
|
7
|
+
attributes[:email] ||= 'foo@example.com'
|
8
|
+
attributes[:password] ||= 'abc123'
|
9
|
+
attributes[:password_confirmation] ||= attributes[:password]
|
10
|
+
<%= user_singular_name %> = <%= user_class_name %>.new(attributes)
|
11
|
+
<%= user_singular_name %>.valid? # run validations
|
12
|
+
<%= user_singular_name %>
|
13
|
+
end
|
14
|
+
|
15
|
+
def setup
|
16
|
+
<%= user_class_name %>.delete_all
|
17
|
+
end
|
18
|
+
|
19
|
+
should "be valid" do
|
20
|
+
assert new_<%= user_singular_name %>.valid?
|
21
|
+
end
|
22
|
+
|
23
|
+
should "require username" do
|
24
|
+
assert new_<%= user_singular_name %>(:username => '').errors[:username]
|
25
|
+
end
|
26
|
+
|
27
|
+
should "require password" do
|
28
|
+
assert new_<%= user_singular_name %>(:password => '').errors[:password]
|
29
|
+
end
|
30
|
+
|
31
|
+
should "require well formed email" do
|
32
|
+
assert new_<%= user_singular_name %>(:email => 'foo@bar@example.com').errors[:email]
|
33
|
+
end
|
34
|
+
|
35
|
+
should "validate uniqueness of email" do
|
36
|
+
new_<%= user_singular_name %>(:email => 'bar@example.com').save!
|
37
|
+
assert new_<%= user_singular_name %>(:email => 'bar@example.com').errors[:email]
|
38
|
+
end
|
39
|
+
|
40
|
+
should "validate uniqueness of username" do
|
41
|
+
new_<%= user_singular_name %>(:username => 'uniquename').save!
|
42
|
+
assert new_<%= user_singular_name %>(:username => 'uniquename').errors[:username]
|
43
|
+
end
|
44
|
+
|
45
|
+
should "not allow odd characters in username" do
|
46
|
+
assert new_<%= user_singular_name %>(:username => 'odd ^&(@)').errors[:username]
|
47
|
+
end
|
48
|
+
|
49
|
+
should "validate password is longer than 3 characters" do
|
50
|
+
assert new_<%= user_singular_name %>(:password => 'bad').errors[:password]
|
51
|
+
end
|
52
|
+
|
53
|
+
should "require matching password confirmation" do
|
54
|
+
assert new_<%= user_singular_name %>(:password_confirmation => 'nonmatching').errors[:password]
|
55
|
+
end
|
56
|
+
|
57
|
+
should "generate password hash and salt on create" do
|
58
|
+
<%= user_singular_name %> = new_<%= user_singular_name %>
|
59
|
+
<%= user_singular_name %>.save!
|
60
|
+
assert <%= user_singular_name %>.password_hash
|
61
|
+
assert <%= user_singular_name %>.password_salt
|
62
|
+
end
|
63
|
+
|
64
|
+
should "authenticate by username" do
|
65
|
+
<%= user_singular_name %> = new_<%= user_singular_name %>(:username => 'foobar', :password => 'secret')
|
66
|
+
<%= user_singular_name %>.save!
|
67
|
+
assert_equal <%= user_singular_name %>, <%= user_class_name %>.authenticate('foobar', 'secret')
|
68
|
+
end
|
69
|
+
|
70
|
+
should "authenticate by email" do
|
71
|
+
<%= user_singular_name %> = new_<%= user_singular_name %>(:email => 'foo@bar.com', :password => 'secret')
|
72
|
+
<%= user_singular_name %>.save!
|
73
|
+
assert_equal <%= user_singular_name %>, <%= user_class_name %>.authenticate('foo@bar.com', 'secret')
|
74
|
+
end
|
75
|
+
|
76
|
+
should "not authenticate bad username" do
|
77
|
+
assert_nil <%= user_class_name %>.authenticate('nonexisting', 'secret')
|
78
|
+
end
|
79
|
+
|
80
|
+
should "not authenticate bad password" do
|
81
|
+
new_<%= user_singular_name %>(:username => 'foobar', :password => 'secret').save!
|
82
|
+
assert_nil <%= user_class_name %>.authenticate('foobar', 'badpassword')
|
83
|
+
end
|
84
|
+
<%- end -%>
|
85
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class <%= user_plural_class_name %>ControllerTest < ActionController::TestCase
|
4
|
+
context "new action" do
|
5
|
+
should "render new template" do
|
6
|
+
get :new
|
7
|
+
assert_template 'new'
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
context "create action" do
|
12
|
+
should "render new template when <%= user_singular_name %> is invalid" do
|
13
|
+
<%= user_class_name %>.any_instance.stubs(:valid?).returns(false)
|
14
|
+
post :create
|
15
|
+
assert_template 'new'
|
16
|
+
end
|
17
|
+
|
18
|
+
should "redirect when <%= user_singular_name %> is valid" do
|
19
|
+
<%= user_class_name %>.any_instance.stubs(:valid?).returns(true)
|
20
|
+
post :create
|
21
|
+
assert_redirected_to "/"
|
22
|
+
<%- unless options[:authlogic] -%>
|
23
|
+
assert_equal assigns['<%= user_singular_name %>'].id, session['<%= user_singular_name %>_id']
|
24
|
+
<%- end -%>
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
context "edit action" do
|
29
|
+
should "redirect when not logged in" do
|
30
|
+
get :edit, :id => "ignored"
|
31
|
+
assert_redirected_to login_url
|
32
|
+
end
|
33
|
+
|
34
|
+
should "render edit template" do
|
35
|
+
@controller.stubs(:current_<%= user_singular_name %>).returns(<%= user_class_name %>.first)
|
36
|
+
get :edit, :id => "ignored"
|
37
|
+
assert_template 'edit'
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context "update action" do
|
42
|
+
should "redirect when not logged in" do
|
43
|
+
put :update, :id => "ignored"
|
44
|
+
assert_redirected_to login_url
|
45
|
+
end
|
46
|
+
|
47
|
+
should "render edit template when <%= user_singular_name %> is invalid" do
|
48
|
+
@controller.stubs(:current_<%= user_singular_name %>).returns(<%= user_class_name %>.first)
|
49
|
+
<%= user_class_name %>.any_instance.stubs(:valid?).returns(false)
|
50
|
+
put :update, :id => "ignored"
|
51
|
+
assert_template 'edit'
|
52
|
+
end
|
53
|
+
|
54
|
+
should "redirect when <%= user_singular_name %> is valid" do
|
55
|
+
@controller.stubs(:current_<%= user_singular_name %>).returns(<%= user_class_name %>.first)
|
56
|
+
<%= user_class_name %>.any_instance.stubs(:valid?).returns(true)
|
57
|
+
put :update, :id => "ignored"
|
58
|
+
assert_redirected_to "/"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class <%= session_plural_class_name %>ControllerTest < ActionController::TestCase
|
4
|
+
def test_new
|
5
|
+
get :new
|
6
|
+
assert_template 'new'
|
7
|
+
end
|
8
|
+
|
9
|
+
<%- if options[:authlogic] -%>
|
10
|
+
def test_create_invalid
|
11
|
+
post :create, :<%= session_singular_name %> => { :username => "foo", :password => "badpassword" }
|
12
|
+
assert_template 'new'
|
13
|
+
assert_nil <%= session_class_name %>.find
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_create_valid
|
17
|
+
post :create, :<%= session_singular_name %> => { :username => "foo", :password => "secret" }
|
18
|
+
assert_redirected_to "/"
|
19
|
+
assert_equal <%= user_plural_name %>(:foo), <%= session_class_name %>.find.<%= user_singular_name %>
|
20
|
+
end
|
21
|
+
<%- else -%>
|
22
|
+
def test_create_invalid
|
23
|
+
<%= user_class_name %>.stubs(:authenticate).returns(nil)
|
24
|
+
post :create
|
25
|
+
assert_template 'new'
|
26
|
+
assert_nil session['<%= user_singular_name %>_id']
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_create_valid
|
30
|
+
<%= user_class_name %>.stubs(:authenticate).returns(<%= user_class_name %>.first)
|
31
|
+
post :create
|
32
|
+
assert_redirected_to "/"
|
33
|
+
assert_equal <%= user_class_name %>.first.id, session['<%= user_singular_name %>_id']
|
34
|
+
end
|
35
|
+
<%- end -%>
|
36
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class <%= user_class_name %>Test < ActiveSupport::TestCase
|
4
|
+
<%- unless options[:authlogic] -%>
|
5
|
+
def new_<%= user_singular_name %>(attributes = {})
|
6
|
+
attributes[:username] ||= 'foo'
|
7
|
+
attributes[:email] ||= 'foo@example.com'
|
8
|
+
attributes[:password] ||= 'abc123'
|
9
|
+
attributes[:password_confirmation] ||= attributes[:password]
|
10
|
+
<%= user_singular_name %> = <%= user_class_name %>.new(attributes)
|
11
|
+
<%= user_singular_name %>.valid? # run validations
|
12
|
+
<%= user_singular_name %>
|
13
|
+
end
|
14
|
+
|
15
|
+
def setup
|
16
|
+
<%= user_class_name %>.delete_all
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_valid
|
20
|
+
assert new_<%= user_singular_name %>.valid?
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_require_username
|
24
|
+
assert new_<%= user_singular_name %>(:username => '').errors[:username]
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_require_password
|
28
|
+
assert new_<%= user_singular_name %>(:password => '').errors[:password]
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_require_well_formed_email
|
32
|
+
assert new_<%= user_singular_name %>(:email => 'foo@bar@example.com').errors[:email]
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_validate_uniqueness_of_email
|
36
|
+
new_<%= user_singular_name %>(:email => 'bar@example.com').save!
|
37
|
+
assert new_<%= user_singular_name %>(:email => 'bar@example.com').errors[:email]
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_validate_uniqueness_of_username
|
41
|
+
new_<%= user_singular_name %>(:username => 'uniquename').save!
|
42
|
+
assert new_<%= user_singular_name %>(:username => 'uniquename').errors[:username]
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_validate_odd_characters_in_username
|
46
|
+
assert new_<%= user_singular_name %>(:username => 'odd ^&(@)').errors[:username]
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_validate_password_length
|
50
|
+
assert new_<%= user_singular_name %>(:password => 'bad').errors[:password]
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_require_matching_password_confirmation
|
54
|
+
assert new_<%= user_singular_name %>(:password_confirmation => 'nonmatching').errors[:password]
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_generate_password_hash_and_salt_on_create
|
58
|
+
<%= user_singular_name %> = new_<%= user_singular_name %>
|
59
|
+
<%= user_singular_name %>.save!
|
60
|
+
assert <%= user_singular_name %>.password_hash
|
61
|
+
assert <%= user_singular_name %>.password_salt
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_authenticate_by_username
|
65
|
+
<%= user_class_name %>.delete_all
|
66
|
+
<%= user_singular_name %> = new_<%= user_singular_name %>(:username => 'foobar', :password => 'secret')
|
67
|
+
<%= user_singular_name %>.save!
|
68
|
+
assert_equal <%= user_singular_name %>, <%= user_class_name %>.authenticate('foobar', 'secret')
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_authenticate_by_email
|
72
|
+
<%= user_class_name %>.delete_all
|
73
|
+
<%= user_singular_name %> = new_<%= user_singular_name %>(:email => 'foo@bar.com', :password => 'secret')
|
74
|
+
<%= user_singular_name %>.save!
|
75
|
+
assert_equal <%= user_singular_name %>, <%= user_class_name %>.authenticate('foo@bar.com', 'secret')
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_authenticate_bad_username
|
79
|
+
assert_nil <%= user_class_name %>.authenticate('nonexisting', 'secret')
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_authenticate_bad_password
|
83
|
+
<%= user_class_name %>.delete_all
|
84
|
+
new_<%= user_singular_name %>(:username => 'foobar', :password => 'secret').save!
|
85
|
+
assert_nil <%= user_class_name %>.authenticate('foobar', 'badpassword')
|
86
|
+
end
|
87
|
+
<%- end -%>
|
88
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class <%= user_plural_class_name %>ControllerTest < ActionController::TestCase
|
4
|
+
def test_new
|
5
|
+
get :new
|
6
|
+
assert_template 'new'
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_create_invalid
|
10
|
+
<%= user_class_name %>.any_instance.stubs(:valid?).returns(false)
|
11
|
+
post :create
|
12
|
+
assert_template 'new'
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_create_valid
|
16
|
+
<%= user_class_name %>.any_instance.stubs(:valid?).returns(true)
|
17
|
+
post :create
|
18
|
+
assert_redirected_to "/"
|
19
|
+
<%- unless options[:authlogic] -%>
|
20
|
+
assert_equal assigns['<%= user_singular_name %>'].id, session['<%= user_singular_name %>_id']
|
21
|
+
<%- end -%>
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_edit_without_user
|
25
|
+
get :edit, :id => "ignored"
|
26
|
+
assert_redirected_to login_url
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_edit
|
30
|
+
@controller.stubs(:current_<%= user_singular_name %>).returns(<%= user_class_name %>.first)
|
31
|
+
get :edit, :id => "ignored"
|
32
|
+
assert_template 'edit'
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_update_without_user
|
36
|
+
put :update, :id => "ignored"
|
37
|
+
assert_redirected_to login_url
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_update_invalid
|
41
|
+
@controller.stubs(:current_<%= user_singular_name %>).returns(<%= user_class_name %>.first)
|
42
|
+
<%= user_class_name %>.any_instance.stubs(:valid?).returns(false)
|
43
|
+
put :update, :id => "ignored"
|
44
|
+
assert_template 'edit'
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_update_valid
|
48
|
+
@controller.stubs(:current_<%= user_singular_name %>).returns(<%= user_class_name %>.first)
|
49
|
+
<%= user_class_name %>.any_instance.stubs(:valid?).returns(true)
|
50
|
+
put :update, :id => "ignored"
|
51
|
+
assert_redirected_to "/"
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
class <%= user_class_name %> < ActiveRecord::Base
|
2
|
+
<%- if options[:authlogic] -%>
|
3
|
+
acts_as_authentic
|
4
|
+
<%- else -%>
|
5
|
+
# new columns need to be added here to be writable through mass assignment
|
6
|
+
attr_accessible :username, :email, :password, :password_confirmation
|
7
|
+
|
8
|
+
attr_accessor :password
|
9
|
+
before_save :prepare_password
|
10
|
+
|
11
|
+
validates_presence_of :username
|
12
|
+
validates_uniqueness_of :username, :email, :allow_blank => true
|
13
|
+
validates_format_of :username, :with => /^[-\w\._@]+$/i, :allow_blank => true, :message => "should only contain letters, numbers, or .-_@"
|
14
|
+
validates_format_of :email, :with => /^[-a-z0-9_+\.]+\@([-a-z0-9]+\.)+[a-z0-9]{2,4}$/i
|
15
|
+
validates_presence_of :password, :on => :create
|
16
|
+
validates_confirmation_of :password
|
17
|
+
validates_length_of :password, :minimum => 4, :allow_blank => true
|
18
|
+
|
19
|
+
# login can be either username or email address
|
20
|
+
def self.authenticate(login, pass)
|
21
|
+
<%= user_singular_name %> = find_by_username(login) || find_by_email(login)
|
22
|
+
return <%= user_singular_name %> if <%= user_singular_name %> && <%= user_singular_name %>.matching_password?(pass)
|
23
|
+
end
|
24
|
+
|
25
|
+
def matching_password?(pass)
|
26
|
+
self.password_hash == encrypt_password(pass)
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def prepare_password
|
32
|
+
unless password.blank?
|
33
|
+
self.password_salt = BCrypt::Engine.generate_salt
|
34
|
+
self.password_hash = encrypt_password(password)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def encrypt_password(pass)
|
39
|
+
BCrypt::Engine.hash_secret(pass, password_salt)
|
40
|
+
end
|
41
|
+
<%- end -%>
|
42
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
class <%= user_plural_class_name %>Controller < ApplicationController
|
2
|
+
before_filter :login_required, :except => [:new, :create]
|
3
|
+
|
4
|
+
def new
|
5
|
+
@<%= user_singular_name %> = <%= user_class_name %>.new
|
6
|
+
end
|
7
|
+
|
8
|
+
def create
|
9
|
+
@<%= user_singular_name %> = <%= user_class_name %>.new(params[:<%= user_singular_name %>])
|
10
|
+
if @<%= user_singular_name %>.save
|
11
|
+
<%- unless options[:authlogic] -%>
|
12
|
+
session[:<%= user_singular_name %>_id] = @<%= user_singular_name %>.id
|
13
|
+
<%- end -%>
|
14
|
+
flash[:notice] = "Thank you for signing up! You are now logged in."
|
15
|
+
redirect_to "/"
|
16
|
+
else
|
17
|
+
render :action => 'new'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def edit
|
22
|
+
@<%= user_singular_name %> = current_<%= user_singular_name %>
|
23
|
+
end
|
24
|
+
|
25
|
+
def update
|
26
|
+
@<%= user_singular_name %> = current_<%= user_singular_name %>
|
27
|
+
if @<%= user_singular_name %>.update_attributes(params[:<%= user_singular_name %>])
|
28
|
+
flash[:notice] = "Your profile has been updated."
|
29
|
+
redirect_to "/"
|
30
|
+
else
|
31
|
+
render :action => 'edit'
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
<%%= form_for @<%= user_singular_name %> do |f| %>
|
2
|
+
<%%= f.error_messages %>
|
3
|
+
<p>
|
4
|
+
<%%= f.label :username %><br />
|
5
|
+
<%%= f.text_field :username %>
|
6
|
+
</p>
|
7
|
+
<p>
|
8
|
+
<%%= f.label :email, "Email Address" %><br />
|
9
|
+
<%%= f.text_field :email %>
|
10
|
+
</p>
|
11
|
+
<p>
|
12
|
+
<%%= f.label :password %><br />
|
13
|
+
<%%= f.password_field :password %>
|
14
|
+
</p>
|
15
|
+
<p>
|
16
|
+
<%%= f.label :password_confirmation, "Confirm Password" %><br />
|
17
|
+
<%%= f.password_field :password_confirmation %>
|
18
|
+
</p>
|
19
|
+
<p><%%= f.submit (@<%= user_singular_name %>.new_record? ? "Sign up" : "Update") %></p>
|
20
|
+
<%% end %>
|
@@ -0,0 +1,30 @@
|
|
1
|
+
<%% title "Log in" %>
|
2
|
+
|
3
|
+
<p>Don't have an account? <%%= link_to "Sign up!", signup_path %></p>
|
4
|
+
|
5
|
+
<%- if options[:authlogic] -%>
|
6
|
+
<%%= form_for @<%= session_singular_name %> do |f| %>
|
7
|
+
<%%= f.error_messages %>
|
8
|
+
<p>
|
9
|
+
<%%= f.label :username %><br />
|
10
|
+
<%%= f.text_field :username %>
|
11
|
+
</p>
|
12
|
+
<p>
|
13
|
+
<%%= f.label :password %><br />
|
14
|
+
<%%= f.password_field :password %>
|
15
|
+
</p>
|
16
|
+
<p><%%= f.submit "Log in" %></p>
|
17
|
+
<%% end %>
|
18
|
+
<%- else -%>
|
19
|
+
<%%= form_tag <%= session_plural_name %>_path do %>
|
20
|
+
<p>
|
21
|
+
<%%= label_tag :login, "Username or Email Address" %><br />
|
22
|
+
<%%= text_field_tag :login, params[:login] %>
|
23
|
+
</p>
|
24
|
+
<p>
|
25
|
+
<%%= label_tag :password %><br />
|
26
|
+
<%%= password_field_tag :password %>
|
27
|
+
</p>
|
28
|
+
<p><%%= submit_tag "Log in" %></p>
|
29
|
+
<%% end %>
|
30
|
+
<%- end -%>
|
@@ -0,0 +1,20 @@
|
|
1
|
+
- form_for @<%= user_singular_name %> do |f|
|
2
|
+
= f.error_messages
|
3
|
+
%p
|
4
|
+
= f.label :username
|
5
|
+
%br
|
6
|
+
= f.text_field :username
|
7
|
+
%p
|
8
|
+
= f.label :email, "Email Address"
|
9
|
+
%br
|
10
|
+
= f.text_field :email
|
11
|
+
%p
|
12
|
+
= f.label :password
|
13
|
+
%br
|
14
|
+
= f.password_field :password
|
15
|
+
%p
|
16
|
+
= f.label :password_confirmation, "Confirm Password"
|
17
|
+
%br
|
18
|
+
= f.password_field :password_confirmation
|
19
|
+
%p
|
20
|
+
= f.submit (@<%= user_singular_name %>.new_record? ? "Sign up" : "Update")
|
@@ -0,0 +1,30 @@
|
|
1
|
+
- title "Log in"
|
2
|
+
|
3
|
+
%p== Don't have an account? #{link_to "Sign up!", signup_path}
|
4
|
+
|
5
|
+
<%- if options[:authlogic] -%>
|
6
|
+
- form_for @<%= session_singular_name %> do |f|
|
7
|
+
= f.error_messages
|
8
|
+
%p
|
9
|
+
= f.label :username
|
10
|
+
%br
|
11
|
+
= f.text_field :username
|
12
|
+
%p
|
13
|
+
= f.label :password
|
14
|
+
%br
|
15
|
+
= f.password_field :password
|
16
|
+
%p
|
17
|
+
= f.submit "Log in"
|
18
|
+
<%- else -%>
|
19
|
+
- form_tag <%= session_plural_name %>_path do
|
20
|
+
%p
|
21
|
+
= label_tag :login, "Username or Email Address"
|
22
|
+
%br
|
23
|
+
= text_field_tag :login, params[:login]
|
24
|
+
%p
|
25
|
+
= label_tag :password
|
26
|
+
%br
|
27
|
+
= password_field_tag :password
|
28
|
+
%p
|
29
|
+
= submit_tag "Log in"
|
30
|
+
<%- end -%>
|
@@ -0,0 +1,25 @@
|
|
1
|
+
Description:
|
2
|
+
The dust_layout generator creates a basic layout, stylesheet and
|
3
|
+
helper which will give some structure to a starting Rails app.
|
4
|
+
|
5
|
+
The generator takes one argument which will be the name of the
|
6
|
+
layout and stylesheet files. If no argument is passed then it defaults
|
7
|
+
to "application".
|
8
|
+
|
9
|
+
The helper module includes some methods which can be called in any
|
10
|
+
template or partial to set variables to be used in the layout, such as
|
11
|
+
page title and javascript/stylesheet includes.
|
12
|
+
|
13
|
+
Examples:
|
14
|
+
rails generate dust:layout
|
15
|
+
|
16
|
+
Layout: app/views/layouts/application.html.erb
|
17
|
+
Stylesheet: public/stylesheets/application.css
|
18
|
+
Helper: app/helpers/layout_helper.rb
|
19
|
+
|
20
|
+
|
21
|
+
rails generate dust:layout admin
|
22
|
+
|
23
|
+
Layout: app/views/layouts/admin.html.erb
|
24
|
+
Stylesheet: public/stylesheets/admin.css
|
25
|
+
Helper: app/helpers/layout_helper.rb
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'generators/dust'
|
2
|
+
|
3
|
+
module Dust
|
4
|
+
module Generators
|
5
|
+
class LayoutGenerator < Base
|
6
|
+
argument :layout_name, :type => :string, :default => 'application', :banner => 'layout_name'
|
7
|
+
|
8
|
+
class_option :haml, :desc => 'Generate HAML for view, and SASS for stylesheet.', :type => :boolean
|
9
|
+
|
10
|
+
def create_layout
|
11
|
+
if options.haml?
|
12
|
+
template 'layout.html.haml', "app/views/layouts/#{file_name}.html.haml"
|
13
|
+
copy_file 'stylesheet.sass', "public/stylesheets/sass/#{file_name}.sass"
|
14
|
+
else
|
15
|
+
template 'layout.html.erb', "app/views/layouts/#{file_name}.html.erb"
|
16
|
+
copy_file 'stylesheet.css', "public/stylesheets/#{file_name}.css"
|
17
|
+
end
|
18
|
+
copy_file 'layout_helper.rb', 'app/helpers/layout_helper.rb'
|
19
|
+
copy_file 'error_messages_helper.rb', 'app/helpers/error_messages_helper.rb'
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def file_name
|
25
|
+
layout_name.underscore
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module ErrorMessagesHelper
|
2
|
+
# Render error messages for the given objects. The :message and :header_message options are allowed.
|
3
|
+
def error_messages_for(*objects)
|
4
|
+
options = objects.extract_options!
|
5
|
+
options[:header_message] ||= "Invalid Fields"
|
6
|
+
options[:message] ||= "Correct the following errors and try again."
|
7
|
+
messages = objects.compact.map { |o| o.errors.full_messages }.flatten
|
8
|
+
unless messages.empty?
|
9
|
+
content_tag(:div, :class => "error_messages") do
|
10
|
+
list_items = messages.map { |msg| content_tag(:li, msg) }
|
11
|
+
content_tag(:h2, options[:header_message]) + content_tag(:p, options[:message]) + content_tag(:ul, list_items.join.html_safe)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
module FormBuilderAdditions
|
17
|
+
def error_messages(options = {})
|
18
|
+
@template.error_messages_for(@object, options)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
ActionView::Helpers::FormBuilder.send(:include, ErrorMessagesHelper::FormBuilderAdditions)
|
@@ -0,0 +1,19 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title><%%= content_for?(:title) ? yield(:title) : "Untitled" %></title>
|
5
|
+
<%%= stylesheet_link_tag "<%= file_name %>" %>
|
6
|
+
<%%= javascript_include_tag :defaults %>
|
7
|
+
<%%= csrf_meta_tag %>
|
8
|
+
<%%= yield(:head) %>
|
9
|
+
</head>
|
10
|
+
<body>
|
11
|
+
<div id="container">
|
12
|
+
<%% flash.each do |name, msg| %>
|
13
|
+
<%%= content_tag :div, msg, :id => "flash_#{name}" %>
|
14
|
+
<%% end %>
|
15
|
+
<%%= content_tag :h1, yield(:title) if show_title? %>
|
16
|
+
<%%= yield %>
|
17
|
+
</div>
|
18
|
+
</body>
|
19
|
+
</html>
|
@@ -0,0 +1,21 @@
|
|
1
|
+
!!!
|
2
|
+
%html
|
3
|
+
|
4
|
+
%head
|
5
|
+
%title
|
6
|
+
= yield(:title) || "Untitled"
|
7
|
+
%meta{"http-equiv"=>"Content-Type", :content=>"text/html; charset=utf-8"}/
|
8
|
+
= stylesheet_link_tag "<%= file_name %>"
|
9
|
+
= javascript_include_tag :defaults
|
10
|
+
= csrf_meta_tag
|
11
|
+
= yield(:head)
|
12
|
+
|
13
|
+
%body
|
14
|
+
#container
|
15
|
+
- flash.each do |name, msg|
|
16
|
+
= content_tag :div, msg, :id => "flash_#{name}"
|
17
|
+
|
18
|
+
- if show_title?
|
19
|
+
%h1= yield(:title)
|
20
|
+
|
21
|
+
= yield
|