iain-pizza-generators 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (27) hide show
  1. data/Manifest +1 -0
  2. data/README.rdoc +2 -1
  3. data/Rakefile +1 -1
  4. data/pizza-generators.gemspec +5 -5
  5. data/rails_generators/pizza_authentication/templates/authentication.rb +41 -32
  6. data/rails_generators/pizza_authentication/templates/session.rb +0 -2
  7. data/rails_generators/pizza_authentication/templates/sessions_controller.rb +17 -8
  8. data/rails_generators/pizza_authentication/templates/user.rb +7 -8
  9. data/rails_generators/pizza_authentication/templates/users_controller.rb +8 -8
  10. data/rails_generators/pizza_authentication/templates/views/haml/edit.html.haml +7 -16
  11. data/rails_generators/pizza_authentication/templates/views/haml/login.html.haml +6 -9
  12. data/rails_generators/pizza_authentication/templates/views/haml/new.html.haml +7 -16
  13. data/rails_generators/pizza_authentication/templates/views/haml/show.html.haml +0 -2
  14. data/rails_generators/pizza_scaffold/pizza_scaffold_generator.rb +29 -24
  15. data/rails_generators/pizza_scaffold/templates/actions/create.rb +14 -1
  16. data/rails_generators/pizza_scaffold/templates/actions/destroy.rb +21 -3
  17. data/rails_generators/pizza_scaffold/templates/actions/index.rb +4 -0
  18. data/rails_generators/pizza_scaffold/templates/actions/new.rb +4 -0
  19. data/rails_generators/pizza_scaffold/templates/actions/show.rb +4 -0
  20. data/rails_generators/pizza_scaffold/templates/actions/update.rb +14 -1
  21. data/rails_generators/pizza_scaffold/templates/model.rb +0 -19
  22. data/rails_generators/pizza_scaffold/templates/views/haml/_form.html.haml +1 -0
  23. data/rails_generators/pizza_scaffold/templates/views/haml/edit.html.haml +2 -0
  24. data/rails_generators/pizza_scaffold/templates/views/haml/index.html.haml +2 -0
  25. data/rails_generators/pizza_scaffold/templates/views/haml/new.html.haml +2 -0
  26. data/rails_generators/pizza_scaffold/templates/views/haml/show.html.haml +2 -0
  27. metadata +5 -6
data/Manifest CHANGED
@@ -9,6 +9,7 @@ test/test_pizza_config_generator.rb
9
9
  test/test_pizza_layout_generator.rb
10
10
  test/test_pizza_scaffold_generator.rb
11
11
  CHANGELOG
12
+ pizza-generators.gemspec
12
13
  Rakefile
13
14
  tasks/deployment.rake
14
15
  rails_generators/pizza_scaffold/USAGE
data/README.rdoc CHANGED
@@ -29,7 +29,8 @@ Here is what is Pizza compared to Nifty:
29
29
  * table_for (from http://github.com/iain/model_based_html)
30
30
  * Rails i18n and supposes Mr. T (from http://github.com/iain/mr.-t)
31
31
  * WillPaginate (from http://github.com/mislav/will_paginate)
32
- * Some validations for models automaticly entered and some belongs_to stuff too
32
+ * Turn of XML respond to blocks by using the <tt>--no-xml</tt> option
33
+ * Scaffolded RSpec actions are Heckle proof. A lot of tests, using the Shoulda matchers.
33
34
 
34
35
  ===== pizza_layout
35
36
 
data/Rakefile CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
  require 'rake'
3
3
  require 'echoe'
4
4
 
5
- Echoe.new('pizza-generators', '0.1.3') do |p|
5
+ Echoe.new('pizza-generators', '0.1.4') do |p|
6
6
  p.project = "pizzagenerators"
7
7
  p.description = "A collection of useful generator scripts for Rails."
8
8
  p.url = "http://github.com/iain/pizza-generators"
@@ -2,15 +2,15 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{pizza-generators}
5
- s.version = "0.1.3"
5
+ s.version = "0.1.4"
6
6
 
7
- s.required_rubygems_version = Gem::Requirement.new(">= 1.3") if s.respond_to? :required_rubygems_version=
8
- s.authors = ["Ryan Bates", "Iain Hecker"]
9
- s.date = %q{2009-04-17}
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Ryan Bates, Iain Hecker"]
9
+ s.date = %q{2009-04-21}
10
10
  s.description = %q{A collection of useful generator scripts for Rails.}
11
11
  s.email = %q{iain@iain.nl}
12
12
  s.extra_rdoc_files = ["README.rdoc", "lib/pizza_generators.rb", "TODO", "LICENSE", "CHANGELOG", "tasks/deployment.rake"]
13
- s.files = ["README.rdoc", "Manifest", "lib/pizza_generators.rb", "TODO", "LICENSE", "test/test_helper.rb", "test/test_pizza_authentication_generator.rb", "test/test_pizza_config_generator.rb", "test/test_pizza_layout_generator.rb", "test/test_pizza_scaffold_generator.rb", "CHANGELOG", "Rakefile", "tasks/deployment.rake", "rails_generators/pizza_scaffold/USAGE", "rails_generators/pizza_scaffold/templates/helper.rb", "rails_generators/pizza_scaffold/templates/fixtures.yml", "rails_generators/pizza_scaffold/templates/actions/edit.rb", "rails_generators/pizza_scaffold/templates/actions/index.rb", "rails_generators/pizza_scaffold/templates/actions/update.rb", "rails_generators/pizza_scaffold/templates/actions/show.rb", "rails_generators/pizza_scaffold/templates/actions/destroy.rb", "rails_generators/pizza_scaffold/templates/actions/create.rb", "rails_generators/pizza_scaffold/templates/actions/new.rb", "rails_generators/pizza_scaffold/templates/migration.rb", "rails_generators/pizza_scaffold/templates/controller.rb", "rails_generators/pizza_scaffold/templates/views/erb/edit.html.erb", "rails_generators/pizza_scaffold/templates/views/erb/index.html.erb", "rails_generators/pizza_scaffold/templates/views/erb/new.html.erb", "rails_generators/pizza_scaffold/templates/views/erb/_form.html.erb", "rails_generators/pizza_scaffold/templates/views/erb/show.html.erb", "rails_generators/pizza_scaffold/templates/views/haml/new.html.haml", "rails_generators/pizza_scaffold/templates/views/haml/_form.html.haml", "rails_generators/pizza_scaffold/templates/views/haml/edit.html.haml", "rails_generators/pizza_scaffold/templates/views/haml/show.html.haml", "rails_generators/pizza_scaffold/templates/views/haml/index.html.haml", "rails_generators/pizza_scaffold/templates/model.rb", "rails_generators/pizza_scaffold/templates/tests/shoulda/actions/edit.rb", "rails_generators/pizza_scaffold/templates/tests/shoulda/actions/index.rb", "rails_generators/pizza_scaffold/templates/tests/shoulda/actions/update.rb", "rails_generators/pizza_scaffold/templates/tests/shoulda/actions/show.rb", "rails_generators/pizza_scaffold/templates/tests/shoulda/actions/destroy.rb", "rails_generators/pizza_scaffold/templates/tests/shoulda/actions/create.rb", "rails_generators/pizza_scaffold/templates/tests/shoulda/actions/new.rb", "rails_generators/pizza_scaffold/templates/tests/shoulda/controller.rb", "rails_generators/pizza_scaffold/templates/tests/shoulda/model.rb", "rails_generators/pizza_scaffold/templates/tests/rspec/actions/edit.rb", "rails_generators/pizza_scaffold/templates/tests/rspec/actions/index.rb", "rails_generators/pizza_scaffold/templates/tests/rspec/actions/update.rb", "rails_generators/pizza_scaffold/templates/tests/rspec/actions/show.rb", "rails_generators/pizza_scaffold/templates/tests/rspec/actions/destroy.rb", "rails_generators/pizza_scaffold/templates/tests/rspec/actions/create.rb", "rails_generators/pizza_scaffold/templates/tests/rspec/actions/new.rb", "rails_generators/pizza_scaffold/templates/tests/rspec/controller.rb", "rails_generators/pizza_scaffold/templates/tests/rspec/model.rb", "rails_generators/pizza_scaffold/templates/tests/testunit/actions/edit.rb", "rails_generators/pizza_scaffold/templates/tests/testunit/actions/index.rb", "rails_generators/pizza_scaffold/templates/tests/testunit/actions/update.rb", "rails_generators/pizza_scaffold/templates/tests/testunit/actions/show.rb", "rails_generators/pizza_scaffold/templates/tests/testunit/actions/destroy.rb", "rails_generators/pizza_scaffold/templates/tests/testunit/actions/create.rb", "rails_generators/pizza_scaffold/templates/tests/testunit/actions/new.rb", "rails_generators/pizza_scaffold/templates/tests/testunit/controller.rb", "rails_generators/pizza_scaffold/templates/tests/testunit/model.rb", "rails_generators/pizza_scaffold/pizza_scaffold_generator.rb", "rails_generators/pizza_layout/USAGE", "rails_generators/pizza_layout/templates/helper.rb", "rails_generators/pizza_layout/templates/stylesheet.css", "rails_generators/pizza_layout/templates/will_paginate.rb", "rails_generators/pizza_layout/templates/layout.html.erb", "rails_generators/pizza_layout/templates/application.sass", "rails_generators/pizza_layout/templates/layout.sass", "rails_generators/pizza_layout/templates/_menu.html.haml", "rails_generators/pizza_layout/templates/required.png", "rails_generators/pizza_layout/templates/layout.html.haml", "rails_generators/pizza_layout/templates/reset.sass", "rails_generators/pizza_layout/templates/tables.sass", "rails_generators/pizza_layout/templates/forms.sass", "rails_generators/pizza_layout/templates/definition_lists.sass", "rails_generators/pizza_layout/pizza_layout_generator.rb", "rails_generators/pizza_authentication/lib/insert_commands.rb", "rails_generators/pizza_authentication/USAGE", "rails_generators/pizza_authentication/templates/authentication.rb", "rails_generators/pizza_authentication/templates/fixtures.yml", "rails_generators/pizza_authentication/templates/users_controller.rb", "rails_generators/pizza_authentication/templates/session.rb", "rails_generators/pizza_authentication/templates/migration.rb", "rails_generators/pizza_authentication/templates/users_helper.rb", "rails_generators/pizza_authentication/templates/views/erb/login.html.erb", "rails_generators/pizza_authentication/templates/views/erb/signup.html.erb", "rails_generators/pizza_authentication/templates/views/haml/new.html.haml", "rails_generators/pizza_authentication/templates/views/haml/signup.html.haml", "rails_generators/pizza_authentication/templates/views/haml/login.html.haml", "rails_generators/pizza_authentication/templates/views/haml/edit.html.haml", "rails_generators/pizza_authentication/templates/views/haml/show.html.haml", "rails_generators/pizza_authentication/templates/user.rb", "rails_generators/pizza_authentication/templates/sessions_controller.rb", "rails_generators/pizza_authentication/templates/initializer.rb", "rails_generators/pizza_authentication/templates/factories.rb", "rails_generators/pizza_authentication/templates/sessions_helper.rb", "rails_generators/pizza_authentication/templates/tests/shoulda/users_controller.rb", "rails_generators/pizza_authentication/templates/tests/shoulda/user.rb", "rails_generators/pizza_authentication/templates/tests/shoulda/sessions_controller.rb", "rails_generators/pizza_authentication/templates/tests/rspec/users_controller.rb", "rails_generators/pizza_authentication/templates/tests/rspec/user.rb", "rails_generators/pizza_authentication/templates/tests/rspec/sessions_controller.rb", "rails_generators/pizza_authentication/templates/tests/testunit/users_controller.rb", "rails_generators/pizza_authentication/templates/tests/testunit/user.rb", "rails_generators/pizza_authentication/templates/tests/testunit/sessions_controller.rb", "rails_generators/pizza_authentication/pizza_authentication_generator.rb", "rails_generators/pizza_config/USAGE", "rails_generators/pizza_config/templates/config.yml", "rails_generators/pizza_config/templates/load_config.rb", "rails_generators/pizza_config/pizza_config_generator.rb", "pizza-generators.gemspec"]
13
+ s.files = ["README.rdoc", "Manifest", "lib/pizza_generators.rb", "TODO", "LICENSE", "test/test_helper.rb", "test/test_pizza_authentication_generator.rb", "test/test_pizza_config_generator.rb", "test/test_pizza_layout_generator.rb", "test/test_pizza_scaffold_generator.rb", "CHANGELOG", "pizza-generators.gemspec", "Rakefile", "tasks/deployment.rake", "rails_generators/pizza_scaffold/USAGE", "rails_generators/pizza_scaffold/templates/helper.rb", "rails_generators/pizza_scaffold/templates/fixtures.yml", "rails_generators/pizza_scaffold/templates/actions/edit.rb", "rails_generators/pizza_scaffold/templates/actions/index.rb", "rails_generators/pizza_scaffold/templates/actions/update.rb", "rails_generators/pizza_scaffold/templates/actions/show.rb", "rails_generators/pizza_scaffold/templates/actions/destroy.rb", "rails_generators/pizza_scaffold/templates/actions/create.rb", "rails_generators/pizza_scaffold/templates/actions/new.rb", "rails_generators/pizza_scaffold/templates/migration.rb", "rails_generators/pizza_scaffold/templates/controller.rb", "rails_generators/pizza_scaffold/templates/views/erb/edit.html.erb", "rails_generators/pizza_scaffold/templates/views/erb/index.html.erb", "rails_generators/pizza_scaffold/templates/views/erb/new.html.erb", "rails_generators/pizza_scaffold/templates/views/erb/_form.html.erb", "rails_generators/pizza_scaffold/templates/views/erb/show.html.erb", "rails_generators/pizza_scaffold/templates/views/haml/new.html.haml", "rails_generators/pizza_scaffold/templates/views/haml/_form.html.haml", "rails_generators/pizza_scaffold/templates/views/haml/edit.html.haml", "rails_generators/pizza_scaffold/templates/views/haml/show.html.haml", "rails_generators/pizza_scaffold/templates/views/haml/index.html.haml", "rails_generators/pizza_scaffold/templates/model.rb", "rails_generators/pizza_scaffold/templates/tests/shoulda/actions/edit.rb", "rails_generators/pizza_scaffold/templates/tests/shoulda/actions/index.rb", "rails_generators/pizza_scaffold/templates/tests/shoulda/actions/update.rb", "rails_generators/pizza_scaffold/templates/tests/shoulda/actions/show.rb", "rails_generators/pizza_scaffold/templates/tests/shoulda/actions/destroy.rb", "rails_generators/pizza_scaffold/templates/tests/shoulda/actions/create.rb", "rails_generators/pizza_scaffold/templates/tests/shoulda/actions/new.rb", "rails_generators/pizza_scaffold/templates/tests/shoulda/controller.rb", "rails_generators/pizza_scaffold/templates/tests/shoulda/model.rb", "rails_generators/pizza_scaffold/templates/tests/rspec/actions/edit.rb", "rails_generators/pizza_scaffold/templates/tests/rspec/actions/index.rb", "rails_generators/pizza_scaffold/templates/tests/rspec/actions/update.rb", "rails_generators/pizza_scaffold/templates/tests/rspec/actions/show.rb", "rails_generators/pizza_scaffold/templates/tests/rspec/actions/destroy.rb", "rails_generators/pizza_scaffold/templates/tests/rspec/actions/create.rb", "rails_generators/pizza_scaffold/templates/tests/rspec/actions/new.rb", "rails_generators/pizza_scaffold/templates/tests/rspec/controller.rb", "rails_generators/pizza_scaffold/templates/tests/rspec/model.rb", "rails_generators/pizza_scaffold/templates/tests/testunit/actions/edit.rb", "rails_generators/pizza_scaffold/templates/tests/testunit/actions/index.rb", "rails_generators/pizza_scaffold/templates/tests/testunit/actions/update.rb", "rails_generators/pizza_scaffold/templates/tests/testunit/actions/show.rb", "rails_generators/pizza_scaffold/templates/tests/testunit/actions/destroy.rb", "rails_generators/pizza_scaffold/templates/tests/testunit/actions/create.rb", "rails_generators/pizza_scaffold/templates/tests/testunit/actions/new.rb", "rails_generators/pizza_scaffold/templates/tests/testunit/controller.rb", "rails_generators/pizza_scaffold/templates/tests/testunit/model.rb", "rails_generators/pizza_scaffold/pizza_scaffold_generator.rb", "rails_generators/pizza_layout/USAGE", "rails_generators/pizza_layout/templates/helper.rb", "rails_generators/pizza_layout/templates/stylesheet.css", "rails_generators/pizza_layout/templates/will_paginate.rb", "rails_generators/pizza_layout/templates/layout.html.erb", "rails_generators/pizza_layout/templates/application.sass", "rails_generators/pizza_layout/templates/layout.sass", "rails_generators/pizza_layout/templates/_menu.html.haml", "rails_generators/pizza_layout/templates/required.png", "rails_generators/pizza_layout/templates/layout.html.haml", "rails_generators/pizza_layout/templates/reset.sass", "rails_generators/pizza_layout/templates/tables.sass", "rails_generators/pizza_layout/templates/forms.sass", "rails_generators/pizza_layout/templates/definition_lists.sass", "rails_generators/pizza_layout/pizza_layout_generator.rb", "rails_generators/pizza_authentication/lib/insert_commands.rb", "rails_generators/pizza_authentication/USAGE", "rails_generators/pizza_authentication/templates/authentication.rb", "rails_generators/pizza_authentication/templates/fixtures.yml", "rails_generators/pizza_authentication/templates/users_controller.rb", "rails_generators/pizza_authentication/templates/session.rb", "rails_generators/pizza_authentication/templates/migration.rb", "rails_generators/pizza_authentication/templates/users_helper.rb", "rails_generators/pizza_authentication/templates/views/erb/login.html.erb", "rails_generators/pizza_authentication/templates/views/erb/signup.html.erb", "rails_generators/pizza_authentication/templates/views/haml/new.html.haml", "rails_generators/pizza_authentication/templates/views/haml/signup.html.haml", "rails_generators/pizza_authentication/templates/views/haml/login.html.haml", "rails_generators/pizza_authentication/templates/views/haml/edit.html.haml", "rails_generators/pizza_authentication/templates/views/haml/show.html.haml", "rails_generators/pizza_authentication/templates/user.rb", "rails_generators/pizza_authentication/templates/sessions_controller.rb", "rails_generators/pizza_authentication/templates/initializer.rb", "rails_generators/pizza_authentication/templates/factories.rb", "rails_generators/pizza_authentication/templates/sessions_helper.rb", "rails_generators/pizza_authentication/templates/tests/shoulda/users_controller.rb", "rails_generators/pizza_authentication/templates/tests/shoulda/user.rb", "rails_generators/pizza_authentication/templates/tests/shoulda/sessions_controller.rb", "rails_generators/pizza_authentication/templates/tests/rspec/users_controller.rb", "rails_generators/pizza_authentication/templates/tests/rspec/user.rb", "rails_generators/pizza_authentication/templates/tests/rspec/sessions_controller.rb", "rails_generators/pizza_authentication/templates/tests/testunit/users_controller.rb", "rails_generators/pizza_authentication/templates/tests/testunit/user.rb", "rails_generators/pizza_authentication/templates/tests/testunit/sessions_controller.rb", "rails_generators/pizza_authentication/pizza_authentication_generator.rb", "rails_generators/pizza_config/USAGE", "rails_generators/pizza_config/templates/config.yml", "rails_generators/pizza_config/templates/load_config.rb", "rails_generators/pizza_config/pizza_config_generator.rb"]
14
14
  s.has_rdoc = true
15
15
  s.homepage = %q{http://github.com/iain/pizza-generators}
16
16
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Pizza-generators", "--main", "README.rdoc"]
@@ -4,66 +4,75 @@
4
4
  #
5
5
  # <%% if logged_in? %>
6
6
  # Welcome <%%= current_<%= user_singular_name %>.login %>! Not you?
7
- # <%%= link_to "Log out", logout_path %>
7
+ # <%%= link_to "Sign out", signout_path %>
8
8
  # <%% else %>
9
9
  # <%%= link_to "Sign up", signup_path %> or
10
- # <%%= link_to "log in", login_path %>.
10
+ # <%%= link_to "Sign in", signin_path %>.
11
11
  # <%% end %>
12
12
  #
13
13
  # You can also restrict unregistered users from accessing a controller using
14
14
  # a before filter. For example.
15
15
  #
16
- # before_filter :login_required, :except => [:index, :show]
16
+ # before_filter :require_<%= user_singular_name %>, :except => [:index, :show]
17
17
  module Authentication
18
18
 
19
- def self.included(controller)
20
- controller.send :helper_method, :current_<%= user_singular_name %>, :logged_in?, :current_<%= user_session_singular_name %>
21
- controller.send :before_filter, :activate_authlogic
22
- controller.send :before_filter, :load_<%= user_session_singular_name %>
23
- end
19
+ private
24
20
 
25
- def load_<%= user_session_singular_name %>
26
- @<%= user_session_singular_name %> = <%= user_session_class_name %>.find
27
- @current_<%= user_singular_name %> = @<%= user_session_singular_name %> && @<%= user_session_singular_name %>.<%= user_singular_name %>
21
+ def self.included(controller)
22
+ controller.before_filter :require_<%= user_singular_name %>
23
+ controller.filter_parameter_logging :password, :password_confirmation
24
+ controller.helper_method :current_<%= user_session_singular_name %>, :current_<%= user_singular_name %>, :signed_in?
28
25
  end
29
26
 
30
27
  def current_<%= user_session_singular_name %>
31
- @<%= user_session_singular_name %>
28
+ return @current_<%= user_session_singular_name %> if defined?(@current_<%= user_session_singular_name %>)
29
+ @current_<%= user_session_singular_name %> = <%= user_session_class_name %>.find
32
30
  end
33
31
 
34
32
  def current_<%= user_singular_name %>
35
- @current_<%= user_singular_name %>
33
+ return @current_<%= user_singular_name %> if defined?(@current_<%= user_singular_name %>)
34
+ @current_<%= user_singular_name %> = current_<%= user_session_singular_name %> && current_<%= user_session_singular_name %>.<%= user_singular_name %>
36
35
  end
37
36
 
38
- def logged_in?
37
+ def signed_in?
39
38
  !!current_<%= user_singular_name %>
40
39
  end
41
40
 
42
- def login_required
43
- unless logged_in?
44
- flash[:error] = I18n.t("<%= user_session_plural_name %>.login_required")
45
- redirect_to login_url
41
+ def require_<%= user_singular_name %>
42
+ unless current_<%= user_singular_name %>
43
+ store_location
44
+ set_require_<%= user_singular_name %>_flash
45
+ redirect_to signin_url
46
+ return false
46
47
  end
47
48
  end
48
49
 
49
- def logout_required
50
- if logged_in?
51
- flash[:error] = I18n.t("<%= user_session_plural_name %>.logout_required")
52
- redirect_to root_url
50
+ def require_no_<%= user_singular_name %>
51
+ if current_<%= user_singular_name %>
52
+ store_location
53
+ flash[:warn] = t(:require_no_<%= user_singular_name %>)
54
+ redirect_to <%= user_singular_name %>_url
55
+ return false
53
56
  end
54
57
  end
55
58
 
56
- def activate_authlogic
57
- Authlogic::Session::Base.controller = Authlogic::ControllerAdapters::RailsAdapter.new(self)
59
+ def store_location
60
+ session[:return_to] = request.request_uri
58
61
  end
59
62
 
60
- # Uncomment this method when you have an admin and want to filter for it.
61
- # def admin_required
62
- # return login_required unless logged_in?
63
- # unless current_<%= user_singular_name %>.admin?
64
- # flash[:error] = I18n.t("<%= user_session_plural_name %>.admin_required")
65
- # redirect_to root_url
66
- # end
67
- # end
63
+ # Only to be used by UserSessionsController and UsersController
64
+ def redirect_back_or_default(default)
65
+ redirect_to(session[:return_to] || default)
66
+ session[:return_to] = nil
67
+ end
68
+
69
+ # Only when there are no other flash messages to be set
70
+ def set_require_<%= user_singular_name %>_flash
71
+ if flash.now.instance_variable_get(:@flash).blank?
72
+ flash[:info] = t(:require_<%= user_singular_name %>)
73
+ else
74
+ flash.keep
75
+ end
76
+ end
68
77
 
69
78
  end
@@ -1,4 +1,2 @@
1
1
  class <%= user_session_class_name %> < Authlogic::Session::Base
2
- extend ActsAsTranslatableModel
3
- authenticate_with <%= user_class_name %>
4
2
  end
@@ -1,7 +1,8 @@
1
- class <%= user_session_plural_class_name %>Controller < ApplicationController
1
+ class <%= user_session_plural_class_name %> < ApplicationController
2
2
 
3
- before_filter :login_required, :only => :destroy
4
- before_filter :logout_required, :except => :destroy
3
+ skip_before_filter :require_<%= user_singular_name %>, :only => [:new, :create]
4
+ before_filter :require_no_<%= user_singular_name %>, :only => [:new, :create]
5
+ before_filter :require_<%= user_singular_name %>, :only => :destroy
5
6
 
6
7
  def new
7
8
  @<%= user_session_singular_name %> = <%= user_session_class_name %>.new
@@ -10,17 +11,25 @@ class <%= user_session_plural_class_name %>Controller < ApplicationController
10
11
  def create
11
12
  @<%= user_session_singular_name %> = <%= user_session_class_name %>.new(params[:<%= user_session_singular_name %>])
12
13
  if @<%= user_session_singular_name %>.save
13
- flash[:notice] = t(:success)
14
- redirect_to root_url
14
+ set_flash
15
+ redirect_back_or_default root_url
15
16
  else
16
- render :action => 'new'
17
+ failed_sign_in_flash
18
+ render :new
17
19
  end
18
20
  end
19
21
 
20
22
  def destroy
21
23
  current_<%= user_session_singular_name %>.destroy
22
- flash[:notice] = t(:success)
23
- redirect_to root_url
24
+ set_flash
25
+ redirect_back_or_default root_url
26
+ end
27
+
28
+ private
29
+
30
+ def failed_sign_in_flash
31
+ @<%= user_session_singular_name %>.errors.clear
32
+ set_flash_now :error, :failed
24
33
  end
25
34
 
26
35
  end
@@ -1,18 +1,17 @@
1
1
  class <%= user_class_name %> < ActiveRecord::Base
2
- acts_as_authentic :session_class => "<%= user_session_class_name %>"
3
2
 
4
- attr_accessible :login, :email, :password, :password_confirmation, :old_password
3
+ acts_as_authentic
5
4
 
6
- validate_on_update :old_password_entered
5
+ attr_accessor :current_password
6
+ attr_accessible :login, :email, :password, :password_confirmation, :current_password
7
7
 
8
- def login=(str)
9
- write_attribute(:login, str) if new_record?
10
- end
8
+ validate_on_update :require_current_password
11
9
 
12
10
  private
13
11
 
14
- def old_password_entered
15
-
12
+ def require_current_password
13
+ us = <%= user_session_class_name %>.new(:login => login, :password => current_password)
14
+ errors.add(:current_password) unless us.valid?
16
15
  end
17
16
 
18
17
  end
@@ -1,7 +1,7 @@
1
1
  class <%= user_plural_class_name %>Controller < ApplicationController
2
2
 
3
- before_filter :logout_required, :only => [ :new, :create ]
4
- before_filter :login_required, :only => [ :show, :edit, :update ]
3
+ before_filter :require_no_<%= user_singular_name %>, :only => [:new, :create]
4
+ before_filter :require_<%= user_singular_name %>, :only => [:show, :edit, :update]
5
5
 
6
6
  def new
7
7
  @<%= user_singular_name %> = <%= user_class_name %>.new
@@ -10,15 +10,15 @@ class <%= user_plural_class_name %>Controller < ApplicationController
10
10
  def create
11
11
  @<%= user_singular_name %> = <%= user_class_name %>.new(params[:<%= user_singular_name %>])
12
12
  if @<%= user_singular_name %>.save
13
- flash[:notice] = t(:success)
14
- redirect_to <%= user_singular_name %>_url
13
+ set_flash
14
+ redirect_back_or_default <%= user_singular_name %>_url
15
15
  else
16
- render :action => 'new'
16
+ render :new
17
17
  end
18
18
  end
19
19
 
20
20
  def show
21
- @<%= user_singular_name %> = current_<%= user_singular_name %>
21
+ edit and render :edit
22
22
  end
23
23
 
24
24
  def edit
@@ -28,10 +28,10 @@ class <%= user_plural_class_name %>Controller < ApplicationController
28
28
  def update
29
29
  @<%= user_singular_name %> = current_<%= user_singular_name %>
30
30
  if @<%= user_singular_name %>.update_attributes(params[:<%= user_singular_name %>])
31
- flash[:notice] = t(:success)
31
+ set_flash
32
32
  redirect_to <%= user_singular_name %>_url
33
33
  else
34
- render :action => 'new'
34
+ render :edit
35
35
  end
36
36
  end
37
37
 
@@ -1,21 +1,12 @@
1
- - title t(:title)
2
1
 
3
2
  - form_for @<%= user_singular_name %> do |f|
4
- = f.error_messages
5
- - f.fieldset do
6
- - f.required_field :email
7
- - f.field do
8
- = f.required :old_password
9
- = f.password_field :old_password
10
- - f.field do
11
- = f.label :password
12
- = f.password_field :password
13
- - f.field do
14
- = f.label :password_confirmation
15
- = f.password_field :password_confirmation
3
+
4
+ = f.fieldset do
5
+ - f.field :login
6
+ - f.field :email
7
+ - f.field :current_password
8
+ - f.field :password
9
+ - f.field :password_confirmation
16
10
  - f.field do
17
11
  %label &nbsp;
18
12
  = f.submit t(:submit)
19
-
20
- %ol.actions
21
- %li.show= link_to t(:show), <%= user_singular_name %>_path
@@ -1,15 +1,12 @@
1
1
  - title t(:title)
2
2
 
3
3
  - form_for @<%= user_session_singular_name %>, :url => <%= user_session_singular_name %>_path do |f|
4
- = f.error_messages
5
- - f.fieldset do
6
- - f.required_field :login
7
- - f.field do
8
- = f.required :password
9
- = f.password_field :password
4
+
5
+ = f.fieldset do
6
+ - f.field :login
7
+ - f.field :password
10
8
  - f.field do
11
9
  %label &nbsp;
12
10
  = f.submit t(:submit)
13
-
14
- %ol.actions
15
- %li.signup= link_to t(:signup), signup_path
11
+ &nbsp;
12
+ = link_to title(:new, :users), new_user_path
@@ -1,19 +1,10 @@
1
- - title t(:title)
2
-
3
1
  - form_for @<%= user_singular_name %> do |f|
4
- = f.error_messages
5
- - f.fieldset do
6
- - f.required_field :login
7
- - f.required_field :email
8
- - f.field do
9
- = f.required :password
10
- = f.password_field :password
11
- - f.field do
12
- = f.required :password_confirmation
13
- = f.password_field :password_confirmation
2
+
3
+ = f.fieldset do
4
+ - f.field :login
5
+ - f.field :email
6
+ - f.field :password
7
+ - f.field :password_confirmation
14
8
  - f.field do
15
9
  %label &nbsp;
16
- = f.submit t(:submit)
17
-
18
- %ol.actions
19
- %li.login= link_to t(:login), login_path
10
+ = f.submit t(:signup)
@@ -1,5 +1,3 @@
1
- - title t(:title)
2
-
3
1
  - definition_list_for @<%= user_singular_name %> do |dl|
4
2
  - dl.show_h :login
5
3
  - dl.show_h :email
@@ -39,7 +39,7 @@ class PizzaScaffoldGenerator < 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 PizzaScaffoldGenerator < 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 PizzaScaffoldGenerator < 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,11 +92,11 @@ class PizzaScaffoldGenerator < 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
@@ -104,27 +104,27 @@ class PizzaScaffoldGenerator < Rails::Generator::Base
104
104
  def not_used_actions
105
105
  all_actions - controller_actions.map(&:to_s)
106
106
  end
107
-
107
+
108
108
  def action?(name)
109
109
  controller_actions.include? name.to_s
110
110
  end
111
-
111
+
112
112
  def actions?(*names)
113
113
  names.all? { |n| action? n.to_s }
114
114
  end
115
-
115
+
116
116
  def singular_name
117
117
  name.underscore
118
118
  end
119
-
119
+
120
120
  def plural_name
121
121
  name.underscore.pluralize
122
122
  end
123
-
123
+
124
124
  def class_name
125
125
  name.camelize
126
126
  end
127
-
127
+
128
128
  def plural_class_name
129
129
  plural_name.camelize
130
130
  end
@@ -132,13 +132,13 @@ class PizzaScaffoldGenerator < Rails::Generator::Base
132
132
  def table_link_count
133
133
  (controller_actions - %w[new index update create]).size
134
134
  end
135
-
135
+
136
136
  def controller_methods(dir_name)
137
137
  controller_actions.map do |action|
138
138
  read_template("#{dir_name}/#{action}.rb")
139
139
  end.join("\n").strip
140
140
  end
141
-
141
+
142
142
  def render_form
143
143
  if form_partial?
144
144
  if options[:erb]
@@ -150,7 +150,7 @@ class PizzaScaffoldGenerator < Rails::Generator::Base
150
150
  read_template("views/#{view_language}/_form.html.#{view_language}")
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 PizzaScaffoldGenerator < Rails::Generator::Base
158
158
  "#{plural_name}_#{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 PizzaScaffoldGenerator < Rails::Generator::Base
166
166
  "#{plural_name}_#{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,17 +174,21 @@ class PizzaScaffoldGenerator < Rails::Generator::Base
174
174
  "#{plural_name}_#{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
+ def xml?
189
+ !options[:no_xml]
190
+ end
191
+
188
192
  protected
189
193
 
190
194
  def view_language
@@ -211,6 +215,7 @@ protected
211
215
  opt.on("--testunit", "Use test/unit for test files.") { options[:test_framework] = :testunit }
212
216
  opt.on("--rspec", "Use RSpec for test files.") { options[:test_framework] = :rspec }
213
217
  opt.on("--shoulda", "Use Shoulda for test files.") { options[:test_framework] = :shoulda }
218
+ opt.on("--no-xml", "Don't generate XML responses in actions.") { |v| options[:no_xml] = v }
214
219
  end
215
220
 
216
221
  # is there a better way to do this? Perhaps with const_defined?
@@ -1,16 +1,29 @@
1
1
  # POST /<%= plural_name %>
2
+ <%- if xml? -%>
2
3
  # POST /<%= plural_name %>.xml
4
+ <%- end -%>
3
5
  def create
4
6
  @<%= singular_name %> = <%= class_name %>.new(params[:<%= singular_name %>])
5
7
 
8
+ <%- if xml? -%>
6
9
  respond_to do |format|
7
10
  if @<%= singular_name %>.save
8
- flash[:notice] = '<%= class_name.titleize %> was successfully created.'
11
+ set_flash
9
12
  format.html { redirect_to(<%= item_path('url') %>) }
10
13
  format.xml { render :xml => @<%= singular_name %>, :status => :created, :location => @<%= singular_name %> }
11
14
  else
15
+ set_flash_now :error, :failed
12
16
  format.html { render :new }
13
17
  format.xml { render :xml => @<%= singular_name %>.errors, :status => :unprocessable_entity }
14
18
  end
15
19
  end
20
+ <%- else -%>
21
+ if @<%= singular_name %>.save
22
+ set_flash
23
+ redirect_to(<%= item_path('url') %>)
24
+ else
25
+ set_flash_now :error, :failed
26
+ render :new
27
+ end
28
+ <%- end -%>
16
29
  end
@@ -1,11 +1,29 @@
1
1
  # DELETE /<%= plural_name %>/1
2
+ <%- if xml? -%>
2
3
  # DELETE /<%= plural_name %>/1.xml
4
+ <%- end -%>
3
5
  def destroy
4
6
  @<%= singular_name %> = <%= class_name %>.find(params[:id])
5
- @<%= singular_name %>.destroy
6
7
 
8
+ <%- if xml? -%>
7
9
  respond_to do |format|
8
- format.html { redirect_to(<%= plural_name %>_url) }
9
- format.xml { head :ok }
10
+ if @<%= singular_name %>.destroy
11
+ set_flash
12
+ format.html { redirect_to <%= plural_name %>_url }
13
+ format.xml { head :ok }
14
+ else
15
+ set_flash :error, :failed
16
+ format.html { redirect_to :back }
17
+ format.xml { head :ok }
18
+ end
10
19
  end
20
+ <%- else -%>
21
+ if @<%= singular_name %>.destroy
22
+ set_flash
23
+ redirect_to <%= plural_name %>_url
24
+ else
25
+ set_flash :error, :failed
26
+ redirect_to :back
27
+ end
28
+ <%- end -%>
11
29
  end
@@ -1,10 +1,14 @@
1
1
  # GET /<%= plural_name %>
2
+ <%- if xml? -%>
2
3
  # GET /<%= plural_name %>.xml
4
+ <%- end -%>
3
5
  def index
4
6
  @<%= plural_name %> = <%= class_name %>.paginate(:page => params[:page])
7
+ <%- if xml? -%>
5
8
 
6
9
  respond_to do |format|
7
10
  format.html # index.html.<%= view_language %>
8
11
  format.xml { render :xml => @<%= plural_name %> }
9
12
  end
13
+ <%- end -%>
10
14
  end
@@ -1,10 +1,14 @@
1
1
  # GET /<%= plural_name %>/new
2
+ <%- if xml? -%>
2
3
  # GET /<%= plural_name %>/new.xml
4
+ <%- end -%>
3
5
  def new
4
6
  @<%= singular_name %> = <%= class_name %>.new
7
+ <%- if xml? -%>
5
8
 
6
9
  respond_to do |format|
7
10
  format.html # new.html.<%= view_language %>
8
11
  format.xml { render :xml => @<%= singular_name %> }
9
12
  end
13
+ <%- end -%>
10
14
  end
@@ -1,10 +1,14 @@
1
1
  # GET /<%= plural_name %>/1
2
+ <%- if xml? -%>
2
3
  # GET /<%= plural_name %>/1.xml
4
+ <%- end -%>
3
5
  def show
4
6
  @<%= singular_name %> = <%= class_name %>.find(params[:id])
7
+ <%- if xml? -%>
5
8
 
6
9
  respond_to do |format|
7
10
  format.html # show.html.<%= view_language %>
8
11
  format.xml { render :xml => @<%= singular_name %> }
9
12
  end
13
+ <%- end -%>
10
14
  end
@@ -1,16 +1,29 @@
1
1
  # PUT /<%= plural_name %>/1
2
+ <%- if xml? -%>
2
3
  # PUT /<%= plural_name %>/1.xml
4
+ <%- end -%>
3
5
  def update
4
6
  @<%= singular_name %> = <%= class_name %>.find(params[:id])
5
7
 
8
+ <%- if xml? -%>
6
9
  respond_to do |format|
7
10
  if @<%= singular_name %>.update_attributes(params[:<%= singular_name %>])
8
- flash[:notice] = '<%= class_name.titleize %> was successfully updated.'
11
+ set_flash
9
12
  format.html { redirect_to(<%= item_path('url') %>) }
10
13
  format.xml { head :ok }
11
14
  else
15
+ set_flash_now :error, :failed
12
16
  format.html { render :edit }
13
17
  format.xml { render :xml => @<%= singular_name %>.errors, :status => :unprocessable_entity }
14
18
  end
15
19
  end
20
+ <%- else -%>
21
+ if @<%= singular_name %>.update_attributes(params[:<%= singular_name %>])
22
+ set_flash
23
+ redirect_to <%= item_path('url') %>
24
+ else
25
+ set_flash_now :error, :failed
26
+ render :edit
27
+ end
28
+ <%- end -%>
16
29
  end
@@ -1,21 +1,2 @@
1
1
  class <%= class_name %> < ActiveRecord::Base
2
-
3
- # Default validations:
4
- exclude_validations = %w{id created_at updated_at}
5
- columns.each do |column|
6
- unless exclude_validations.include?(column.name)
7
- validates_presence_of column.name unless column.null
8
- validates_numericality_of column.name, :allow_blank => column.null if column.number?
9
- validates_length_of column.name, :maximum => column.limit, :allow_blank => column.null if column.limit
10
- end
11
- end
12
-
13
- <%- (attrs = attributes.select{|it|it.name =~ /_id$/}).each_with_index do |a, index| -%>
14
- <%- if index == 0 -%>
15
- # Only belongs_to can be guessed, uncomment if correct and don't forget to
16
- # define has_many on the other side of the relation.
17
- <%- end -%>
18
- # belongs_to :<%= a.name.sub(/_id$/,'') %><%= ", :polymorphic => true" unless attributes.select{|it|it.name==a.name.sub(/_id$/, '_type')}.empty? %><%= ", :counter_cache => true" unless attributes.select{|it|it.name==a.name.sub(/_id$/, '_count')}.empty? %>
19
- <%- end -%>
20
-
21
2
  end
@@ -6,4 +6,5 @@
6
6
  - f.field :<%= attribute.name %>
7
7
  <%- end -%>
8
8
  - f.field do
9
+ = empty_label
9
10
  = f.submit t(:submit)
@@ -1,3 +1,5 @@
1
+ %h2= title
2
+
1
3
  <%= render_form %>
2
4
 
3
5
  <%- if actions? :show, :index -%>
@@ -1,3 +1,5 @@
1
+ %h2= title
2
+
1
3
  - table_for @<%= plural_name %> do |t|
2
4
 
3
5
  - t.head do
@@ -1,3 +1,5 @@
1
+ %h2= title
2
+
1
3
  <%= render_form %>
2
4
 
3
5
  <%- if action? :index -%>
@@ -1,3 +1,5 @@
1
+ %h2= title
2
+
1
3
  - definition_list_for @<%= singular_name %> do |dl|
2
4
  <%- for attribute in attributes -%>
3
5
  - dl.show_h :<%= attribute.name %>
metadata CHANGED
@@ -1,16 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iain-pizza-generators
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
- - Ryan Bates
8
- - Iain Hecker
7
+ - Ryan Bates, Iain Hecker
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
11
 
13
- date: 2009-04-17 00:00:00 -07:00
12
+ date: 2009-04-21 00:00:00 -07:00
14
13
  default_executable:
15
14
  dependencies:
16
15
  - !ruby/object:Gem::Dependency
@@ -118,6 +117,7 @@ files:
118
117
  - test/test_pizza_layout_generator.rb
119
118
  - test/test_pizza_scaffold_generator.rb
120
119
  - CHANGELOG
120
+ - pizza-generators.gemspec
121
121
  - Rakefile
122
122
  - tasks/deployment.rake
123
123
  - rails_generators/pizza_scaffold/USAGE
@@ -220,7 +220,6 @@ files:
220
220
  - rails_generators/pizza_config/templates/config.yml
221
221
  - rails_generators/pizza_config/templates/load_config.rb
222
222
  - rails_generators/pizza_config/pizza_config_generator.rb
223
- - pizza-generators.gemspec
224
223
  has_rdoc: true
225
224
  homepage: http://github.com/iain/pizza-generators
226
225
  post_install_message:
@@ -243,7 +242,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
243
242
  requirements:
244
243
  - - ">="
245
244
  - !ruby/object:Gem::Version
246
- version: "1.3"
245
+ version: "1.2"
247
246
  version:
248
247
  requirements: []
249
248