nifty-generators 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (98) hide show
  1. data/CHANGELOG +9 -0
  2. data/LICENSE +1 -1
  3. data/README.rdoc +16 -24
  4. data/Rakefile +0 -13
  5. data/test/test_helper.rb +4 -2
  6. data/test/test_nifty_authentication_generator.rb +39 -1
  7. metadata +18 -114
  8. data/Manifest +0 -100
  9. data/TODO +0 -7
  10. data/nifty-generators.gemspec +0 -169
  11. data/rails_generators/nifty_authentication/USAGE +0 -50
  12. data/rails_generators/nifty_authentication/lib/insert_commands.rb +0 -74
  13. data/rails_generators/nifty_authentication/nifty_authentication_generator.rb +0 -128
  14. data/rails_generators/nifty_authentication/templates/authentication.rb +0 -61
  15. data/rails_generators/nifty_authentication/templates/authlogic_session.rb +0 -2
  16. data/rails_generators/nifty_authentication/templates/fixtures.yml +0 -24
  17. data/rails_generators/nifty_authentication/templates/migration.rb +0 -20
  18. data/rails_generators/nifty_authentication/templates/sessions_controller.rb +0 -45
  19. data/rails_generators/nifty_authentication/templates/sessions_helper.rb +0 -2
  20. data/rails_generators/nifty_authentication/templates/tests/rspec/sessions_controller.rb +0 -39
  21. data/rails_generators/nifty_authentication/templates/tests/rspec/user.rb +0 -83
  22. data/rails_generators/nifty_authentication/templates/tests/rspec/users_controller.rb +0 -26
  23. data/rails_generators/nifty_authentication/templates/tests/shoulda/sessions_controller.rb +0 -40
  24. data/rails_generators/nifty_authentication/templates/tests/shoulda/user.rb +0 -85
  25. data/rails_generators/nifty_authentication/templates/tests/shoulda/users_controller.rb +0 -27
  26. data/rails_generators/nifty_authentication/templates/tests/testunit/sessions_controller.rb +0 -36
  27. data/rails_generators/nifty_authentication/templates/tests/testunit/user.rb +0 -88
  28. data/rails_generators/nifty_authentication/templates/tests/testunit/users_controller.rb +0 -23
  29. data/rails_generators/nifty_authentication/templates/user.rb +0 -42
  30. data/rails_generators/nifty_authentication/templates/users_controller.rb +0 -18
  31. data/rails_generators/nifty_authentication/templates/users_helper.rb +0 -2
  32. data/rails_generators/nifty_authentication/templates/views/erb/login.html.erb +0 -30
  33. data/rails_generators/nifty_authentication/templates/views/erb/signup.html.erb +0 -24
  34. data/rails_generators/nifty_authentication/templates/views/haml/login.html.haml +0 -30
  35. data/rails_generators/nifty_authentication/templates/views/haml/signup.html.haml +0 -24
  36. data/rails_generators/nifty_config/USAGE +0 -23
  37. data/rails_generators/nifty_config/nifty_config_generator.rb +0 -32
  38. data/rails_generators/nifty_config/templates/config.yml +0 -8
  39. data/rails_generators/nifty_config/templates/load_config.rb +0 -2
  40. data/rails_generators/nifty_layout/USAGE +0 -25
  41. data/rails_generators/nifty_layout/nifty_layout_generator.rb +0 -44
  42. data/rails_generators/nifty_layout/templates/helper.rb +0 -22
  43. data/rails_generators/nifty_layout/templates/layout.html.erb +0 -22
  44. data/rails_generators/nifty_layout/templates/layout.html.haml +0 -19
  45. data/rails_generators/nifty_layout/templates/stylesheet.css +0 -81
  46. data/rails_generators/nifty_layout/templates/stylesheet.sass +0 -67
  47. data/rails_generators/nifty_scaffold/USAGE +0 -51
  48. data/rails_generators/nifty_scaffold/nifty_scaffold_generator.rb +0 -232
  49. data/rails_generators/nifty_scaffold/templates/actions/create.rb +0 -9
  50. data/rails_generators/nifty_scaffold/templates/actions/destroy.rb +0 -6
  51. data/rails_generators/nifty_scaffold/templates/actions/edit.rb +0 -3
  52. data/rails_generators/nifty_scaffold/templates/actions/index.rb +0 -3
  53. data/rails_generators/nifty_scaffold/templates/actions/new.rb +0 -3
  54. data/rails_generators/nifty_scaffold/templates/actions/show.rb +0 -3
  55. data/rails_generators/nifty_scaffold/templates/actions/update.rb +0 -9
  56. data/rails_generators/nifty_scaffold/templates/controller.rb +0 -3
  57. data/rails_generators/nifty_scaffold/templates/fixtures.yml +0 -9
  58. data/rails_generators/nifty_scaffold/templates/helper.rb +0 -2
  59. data/rails_generators/nifty_scaffold/templates/migration.rb +0 -16
  60. data/rails_generators/nifty_scaffold/templates/model.rb +0 -3
  61. data/rails_generators/nifty_scaffold/templates/tests/rspec/actions/create.rb +0 -11
  62. data/rails_generators/nifty_scaffold/templates/tests/rspec/actions/destroy.rb +0 -6
  63. data/rails_generators/nifty_scaffold/templates/tests/rspec/actions/edit.rb +0 -4
  64. data/rails_generators/nifty_scaffold/templates/tests/rspec/actions/index.rb +0 -4
  65. data/rails_generators/nifty_scaffold/templates/tests/rspec/actions/new.rb +0 -4
  66. data/rails_generators/nifty_scaffold/templates/tests/rspec/actions/show.rb +0 -4
  67. data/rails_generators/nifty_scaffold/templates/tests/rspec/actions/update.rb +0 -11
  68. data/rails_generators/nifty_scaffold/templates/tests/rspec/controller.rb +0 -8
  69. data/rails_generators/nifty_scaffold/templates/tests/rspec/model.rb +0 -7
  70. data/rails_generators/nifty_scaffold/templates/tests/shoulda/actions/create.rb +0 -13
  71. data/rails_generators/nifty_scaffold/templates/tests/shoulda/actions/destroy.rb +0 -8
  72. data/rails_generators/nifty_scaffold/templates/tests/shoulda/actions/edit.rb +0 -6
  73. data/rails_generators/nifty_scaffold/templates/tests/shoulda/actions/index.rb +0 -6
  74. data/rails_generators/nifty_scaffold/templates/tests/shoulda/actions/new.rb +0 -6
  75. data/rails_generators/nifty_scaffold/templates/tests/shoulda/actions/show.rb +0 -6
  76. data/rails_generators/nifty_scaffold/templates/tests/shoulda/actions/update.rb +0 -13
  77. data/rails_generators/nifty_scaffold/templates/tests/shoulda/controller.rb +0 -5
  78. data/rails_generators/nifty_scaffold/templates/tests/shoulda/model.rb +0 -7
  79. data/rails_generators/nifty_scaffold/templates/tests/testunit/actions/create.rb +0 -11
  80. data/rails_generators/nifty_scaffold/templates/tests/testunit/actions/destroy.rb +0 -6
  81. data/rails_generators/nifty_scaffold/templates/tests/testunit/actions/edit.rb +0 -4
  82. data/rails_generators/nifty_scaffold/templates/tests/testunit/actions/index.rb +0 -4
  83. data/rails_generators/nifty_scaffold/templates/tests/testunit/actions/new.rb +0 -4
  84. data/rails_generators/nifty_scaffold/templates/tests/testunit/actions/show.rb +0 -4
  85. data/rails_generators/nifty_scaffold/templates/tests/testunit/actions/update.rb +0 -11
  86. data/rails_generators/nifty_scaffold/templates/tests/testunit/controller.rb +0 -5
  87. data/rails_generators/nifty_scaffold/templates/tests/testunit/model.rb +0 -7
  88. data/rails_generators/nifty_scaffold/templates/views/erb/_form.html.erb +0 -10
  89. data/rails_generators/nifty_scaffold/templates/views/erb/edit.html.erb +0 -14
  90. data/rails_generators/nifty_scaffold/templates/views/erb/index.html.erb +0 -29
  91. data/rails_generators/nifty_scaffold/templates/views/erb/new.html.erb +0 -7
  92. data/rails_generators/nifty_scaffold/templates/views/erb/show.html.erb +0 -20
  93. data/rails_generators/nifty_scaffold/templates/views/haml/_form.html.haml +0 -10
  94. data/rails_generators/nifty_scaffold/templates/views/haml/edit.html.haml +0 -14
  95. data/rails_generators/nifty_scaffold/templates/views/haml/index.html.haml +0 -25
  96. data/rails_generators/nifty_scaffold/templates/views/haml/new.html.haml +0 -7
  97. data/rails_generators/nifty_scaffold/templates/views/haml/show.html.haml +0 -20
  98. data/tasks/deployment.rake +0 -2
data/TODO DELETED
@@ -1,7 +0,0 @@
1
-
2
- Nifty Scaffold
3
- - add some validation for attributes/action names
4
- - refactor out long methods in scaffold generator
5
-
6
- Nifty Config
7
- - make it easier to specify non environment specific configs
@@ -1,169 +0,0 @@
1
-
2
- # Gem::Specification for Nifty-generators-0.3.0
3
- # Originally generated by Echoe
4
-
5
- --- !ruby/object:Gem::Specification
6
- name: nifty-generators
7
- version: !ruby/object:Gem::Version
8
- version: 0.3.0
9
- platform: ruby
10
- authors:
11
- - Ryan Bates
12
- autorequire:
13
- bindir: bin
14
-
15
- date: 2009-08-15 00:00:00 -07:00
16
- default_executable:
17
- dependencies: []
18
-
19
- description: A collection of useful generator scripts for Rails.
20
- email: ryan (at) railscasts (dot) com
21
- executables: []
22
-
23
- extensions: []
24
-
25
- extra_rdoc_files:
26
- - CHANGELOG
27
- - lib/nifty_generators.rb
28
- - LICENSE
29
- - README.rdoc
30
- - tasks/deployment.rake
31
- - TODO
32
- files:
33
- - CHANGELOG
34
- - lib/nifty_generators.rb
35
- - LICENSE
36
- - Manifest
37
- - rails_generators/nifty_authentication/lib/insert_commands.rb
38
- - rails_generators/nifty_authentication/nifty_authentication_generator.rb
39
- - rails_generators/nifty_authentication/templates/authentication.rb
40
- - rails_generators/nifty_authentication/templates/authlogic_session.rb
41
- - rails_generators/nifty_authentication/templates/fixtures.yml
42
- - rails_generators/nifty_authentication/templates/migration.rb
43
- - rails_generators/nifty_authentication/templates/sessions_controller.rb
44
- - rails_generators/nifty_authentication/templates/sessions_helper.rb
45
- - rails_generators/nifty_authentication/templates/tests/rspec/sessions_controller.rb
46
- - rails_generators/nifty_authentication/templates/tests/rspec/user.rb
47
- - rails_generators/nifty_authentication/templates/tests/rspec/users_controller.rb
48
- - rails_generators/nifty_authentication/templates/tests/shoulda/sessions_controller.rb
49
- - rails_generators/nifty_authentication/templates/tests/shoulda/user.rb
50
- - rails_generators/nifty_authentication/templates/tests/shoulda/users_controller.rb
51
- - rails_generators/nifty_authentication/templates/tests/testunit/sessions_controller.rb
52
- - rails_generators/nifty_authentication/templates/tests/testunit/user.rb
53
- - rails_generators/nifty_authentication/templates/tests/testunit/users_controller.rb
54
- - rails_generators/nifty_authentication/templates/user.rb
55
- - rails_generators/nifty_authentication/templates/users_controller.rb
56
- - rails_generators/nifty_authentication/templates/users_helper.rb
57
- - rails_generators/nifty_authentication/templates/views/erb/login.html.erb
58
- - rails_generators/nifty_authentication/templates/views/erb/signup.html.erb
59
- - rails_generators/nifty_authentication/templates/views/haml/login.html.haml
60
- - rails_generators/nifty_authentication/templates/views/haml/signup.html.haml
61
- - rails_generators/nifty_authentication/USAGE
62
- - rails_generators/nifty_config/nifty_config_generator.rb
63
- - rails_generators/nifty_config/templates/config.yml
64
- - rails_generators/nifty_config/templates/load_config.rb
65
- - rails_generators/nifty_config/USAGE
66
- - rails_generators/nifty_layout/nifty_layout_generator.rb
67
- - rails_generators/nifty_layout/templates/helper.rb
68
- - rails_generators/nifty_layout/templates/layout.html.erb
69
- - rails_generators/nifty_layout/templates/layout.html.haml
70
- - rails_generators/nifty_layout/templates/stylesheet.css
71
- - rails_generators/nifty_layout/templates/stylesheet.sass
72
- - rails_generators/nifty_layout/USAGE
73
- - rails_generators/nifty_scaffold/nifty_scaffold_generator.rb
74
- - rails_generators/nifty_scaffold/templates/actions/create.rb
75
- - rails_generators/nifty_scaffold/templates/actions/destroy.rb
76
- - rails_generators/nifty_scaffold/templates/actions/edit.rb
77
- - rails_generators/nifty_scaffold/templates/actions/index.rb
78
- - rails_generators/nifty_scaffold/templates/actions/new.rb
79
- - rails_generators/nifty_scaffold/templates/actions/show.rb
80
- - rails_generators/nifty_scaffold/templates/actions/update.rb
81
- - rails_generators/nifty_scaffold/templates/controller.rb
82
- - rails_generators/nifty_scaffold/templates/fixtures.yml
83
- - rails_generators/nifty_scaffold/templates/helper.rb
84
- - rails_generators/nifty_scaffold/templates/migration.rb
85
- - rails_generators/nifty_scaffold/templates/model.rb
86
- - rails_generators/nifty_scaffold/templates/tests/rspec/actions/create.rb
87
- - rails_generators/nifty_scaffold/templates/tests/rspec/actions/destroy.rb
88
- - rails_generators/nifty_scaffold/templates/tests/rspec/actions/edit.rb
89
- - rails_generators/nifty_scaffold/templates/tests/rspec/actions/index.rb
90
- - rails_generators/nifty_scaffold/templates/tests/rspec/actions/new.rb
91
- - rails_generators/nifty_scaffold/templates/tests/rspec/actions/show.rb
92
- - rails_generators/nifty_scaffold/templates/tests/rspec/actions/update.rb
93
- - rails_generators/nifty_scaffold/templates/tests/rspec/controller.rb
94
- - rails_generators/nifty_scaffold/templates/tests/rspec/model.rb
95
- - rails_generators/nifty_scaffold/templates/tests/shoulda/actions/create.rb
96
- - rails_generators/nifty_scaffold/templates/tests/shoulda/actions/destroy.rb
97
- - rails_generators/nifty_scaffold/templates/tests/shoulda/actions/edit.rb
98
- - rails_generators/nifty_scaffold/templates/tests/shoulda/actions/index.rb
99
- - rails_generators/nifty_scaffold/templates/tests/shoulda/actions/new.rb
100
- - rails_generators/nifty_scaffold/templates/tests/shoulda/actions/show.rb
101
- - rails_generators/nifty_scaffold/templates/tests/shoulda/actions/update.rb
102
- - rails_generators/nifty_scaffold/templates/tests/shoulda/controller.rb
103
- - rails_generators/nifty_scaffold/templates/tests/shoulda/model.rb
104
- - rails_generators/nifty_scaffold/templates/tests/testunit/actions/create.rb
105
- - rails_generators/nifty_scaffold/templates/tests/testunit/actions/destroy.rb
106
- - rails_generators/nifty_scaffold/templates/tests/testunit/actions/edit.rb
107
- - rails_generators/nifty_scaffold/templates/tests/testunit/actions/index.rb
108
- - rails_generators/nifty_scaffold/templates/tests/testunit/actions/new.rb
109
- - rails_generators/nifty_scaffold/templates/tests/testunit/actions/show.rb
110
- - rails_generators/nifty_scaffold/templates/tests/testunit/actions/update.rb
111
- - rails_generators/nifty_scaffold/templates/tests/testunit/controller.rb
112
- - rails_generators/nifty_scaffold/templates/tests/testunit/model.rb
113
- - rails_generators/nifty_scaffold/templates/views/erb/_form.html.erb
114
- - rails_generators/nifty_scaffold/templates/views/erb/edit.html.erb
115
- - rails_generators/nifty_scaffold/templates/views/erb/index.html.erb
116
- - rails_generators/nifty_scaffold/templates/views/erb/new.html.erb
117
- - rails_generators/nifty_scaffold/templates/views/erb/show.html.erb
118
- - rails_generators/nifty_scaffold/templates/views/haml/_form.html.haml
119
- - rails_generators/nifty_scaffold/templates/views/haml/edit.html.haml
120
- - rails_generators/nifty_scaffold/templates/views/haml/index.html.haml
121
- - rails_generators/nifty_scaffold/templates/views/haml/new.html.haml
122
- - rails_generators/nifty_scaffold/templates/views/haml/show.html.haml
123
- - rails_generators/nifty_scaffold/USAGE
124
- - Rakefile
125
- - README.rdoc
126
- - tasks/deployment.rake
127
- - test/test_helper.rb
128
- - test/test_nifty_authentication_generator.rb
129
- - test/test_nifty_config_generator.rb
130
- - test/test_nifty_layout_generator.rb
131
- - test/test_nifty_scaffold_generator.rb
132
- - TODO
133
- - nifty-generators.gemspec
134
- has_rdoc: true
135
- homepage: http://github.com/ryanb/nifty-generators
136
- post_install_message:
137
- rdoc_options:
138
- - --line-numbers
139
- - --inline-source
140
- - --title
141
- - Nifty-generators
142
- - --main
143
- - README.rdoc
144
- require_paths:
145
- - lib
146
- required_ruby_version: !ruby/object:Gem::Requirement
147
- requirements:
148
- - - ">="
149
- - !ruby/object:Gem::Version
150
- version: "0"
151
- version:
152
- required_rubygems_version: !ruby/object:Gem::Requirement
153
- requirements:
154
- - - ">="
155
- - !ruby/object:Gem::Version
156
- version: "1.2"
157
- version:
158
- requirements: []
159
-
160
- rubyforge_project: niftygenerators
161
- rubygems_version: 1.3.1
162
- specification_version: 2
163
- summary: A collection of useful generator scripts for Rails.
164
- test_files:
165
- - test/test_helper.rb
166
- - test/test_nifty_authentication_generator.rb
167
- - test/test_nifty_config_generator.rb
168
- - test/test_nifty_layout_generator.rb
169
- - test/test_nifty_scaffold_generator.rb
@@ -1,50 +0,0 @@
1
- Description:
2
- Generates a user model, users controller, and sessions controller. The
3
- users controller handles the registration and the sessions controller
4
- handles authentication. This is similar to restful_authentication, but
5
- simpler.
6
-
7
- IMPORTANT: This generator uses the "title" helper method which is generated
8
- by the nifty_layout generator. You may want to run that generator first.
9
-
10
- Usage:
11
- If you do not pass any arguments, the model name will default to "user", and
12
- the authentication controller will default to "session". You can override
13
- each of these respectively by passing one or two arguments. Either name can
14
- be CamelCased or under_scored.
15
-
16
- Make sure to setup the authlogic gem if you are using that option.
17
-
18
- config.gem "authlogic"
19
-
20
- Examples:
21
- script/generate nifty_authentication
22
-
23
- Creates user model, users_controller, and sessions_controller.
24
-
25
- script/generate nifty_authentication account
26
-
27
- Creates account model, accounts_controller, and sessions_controller.
28
-
29
- script/generate nifty_authentication Account UserSession
30
-
31
- Creates account model, accounts_controller, and user_sessions_controller.
32
-
33
- Methods:
34
- There are several methods generated which you can use in your application.
35
- Here's a common example of what you might add to your layout.
36
-
37
- <% if logged_in? %>
38
- Welcome <%= current_user.username %>! Not you?
39
- <%= link_to "Log out", logout_path %>
40
- <% else %>
41
- <%= link_to "Sign up", signup_path %> or
42
- <%= link_to "log in", login_path %>.
43
- <% end %>
44
-
45
- You can also restrict unregistered users from accessing a controller using
46
- a before filter. For example.
47
-
48
- before_filter :login_required, :except => [:index, :show]
49
-
50
- See the generated file lib/authentication.rb for details.
@@ -1,74 +0,0 @@
1
- Rails::Generator::Commands::Create.class_eval do
2
- def route_resource(*resources)
3
- resource_list = resources.map { |r| r.to_sym.inspect }.join(', ')
4
- sentinel = 'ActionController::Routing::Routes.draw do |map|'
5
-
6
- logger.route "map.resource #{resource_list}"
7
- unless options[:pretend]
8
- gsub_file 'config/routes.rb', /(#{Regexp.escape(sentinel)})/mi do |match|
9
- "#{match}\n map.resource #{resource_list}\n"
10
- end
11
- end
12
- end
13
-
14
- def route_name(name, path, route_options = {})
15
- sentinel = 'ActionController::Routing::Routes.draw do |map|'
16
-
17
- logger.route "map.#{name} '#{path}', :controller => '#{route_options[:controller]}', :action => '#{route_options[:action]}'"
18
- unless options[:pretend]
19
- gsub_file 'config/routes.rb', /(#{Regexp.escape(sentinel)})/mi do |match|
20
- "#{match}\n map.#{name} '#{path}', :controller => '#{route_options[:controller]}', :action => '#{route_options[:action]}'"
21
- end
22
- end
23
- end
24
-
25
- def insert_into(file, line)
26
- logger.insert "#{line} into #{file}"
27
- unless options[:pretend]
28
- gsub_file file, /^(class|module) .+$/ do |match|
29
- "#{match}\n #{line}"
30
- end
31
- end
32
- end
33
- end
34
-
35
- Rails::Generator::Commands::Destroy.class_eval do
36
- def route_resource(*resources)
37
- resource_list = resources.map { |r| r.to_sym.inspect }.join(', ')
38
- look_for = "\n map.resource #{resource_list}\n"
39
- logger.route "map.resource #{resource_list}"
40
- unless options[:pretend]
41
- gsub_file 'config/routes.rb', /(#{look_for})/mi, ''
42
- end
43
- end
44
-
45
- def route_name(name, path, route_options = {})
46
- look_for = "\n map.#{name} '#{path}', :controller => '#{route_options[:controller]}', :action => '#{route_options[:action]}'"
47
- logger.route "map.#{name} '#{path}', :controller => '#{route_options[:controller]}', :action => '#{route_options[:action]}'"
48
- unless options[:pretend]
49
- gsub_file 'config/routes.rb', /(#{look_for})/mi, ''
50
- end
51
- end
52
-
53
- def insert_into(file, line)
54
- logger.remove "#{line} from #{file}"
55
- unless options[:pretend]
56
- gsub_file file, "\n #{line}", ''
57
- end
58
- end
59
- end
60
-
61
- Rails::Generator::Commands::List.class_eval do
62
- def route_resource(*resources)
63
- resource_list = resources.map { |r| r.to_sym.inspect }.join(', ')
64
- logger.route "map.resource #{resource_list}"
65
- end
66
-
67
- def route_name(name, path, options = {})
68
- logger.route "map.#{name} '#{path}', :controller => '{options[:controller]}', :action => '#{options[:action]}'"
69
- end
70
-
71
- def insert_into(file, line)
72
- logger.insert "#{line} into #{file}"
73
- end
74
- end
@@ -1,128 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + "/lib/insert_commands.rb")
2
- class NiftyAuthenticationGenerator < Rails::Generator::Base
3
- attr_accessor :user_name, :session_name
4
-
5
- def initialize(runtime_args, runtime_options = {})
6
- super
7
-
8
- @user_name = @args[0] || 'user'
9
- @session_name = @args[1] || (options[:authlogic] ? @user_name + '_session' : 'session')
10
- end
11
-
12
- def manifest
13
- record do |m|
14
- m.directory "app/models"
15
- m.directory "app/controllers"
16
- m.directory "app/helpers"
17
- m.directory "app/views"
18
- m.directory "lib"
19
-
20
- m.directory "app/views/#{user_plural_name}"
21
- m.template "user.rb", "app/models/#{user_singular_name}.rb"
22
- m.template "authlogic_session.rb", "app/models/#{user_singular_name}_session.rb" if options[:authlogic]
23
- m.template "users_controller.rb", "app/controllers/#{user_plural_name}_controller.rb"
24
- m.template "users_helper.rb", "app/helpers/#{user_plural_name}_helper.rb"
25
- m.template "views/#{view_language}/signup.html.#{view_language}", "app/views/#{user_plural_name}/new.html.#{view_language}"
26
-
27
- m.directory "app/views/#{session_plural_name}"
28
- m.template "sessions_controller.rb", "app/controllers/#{session_plural_name}_controller.rb"
29
- m.template "sessions_helper.rb", "app/helpers/#{session_plural_name}_helper.rb"
30
- m.template "views/#{view_language}/login.html.#{view_language}", "app/views/#{session_plural_name}/new.html.#{view_language}"
31
-
32
- m.template "authentication.rb", "lib/authentication.rb"
33
- m.migration_template "migration.rb", "db/migrate", :migration_file_name => "create_#{user_plural_name}"
34
-
35
- m.route_resources user_plural_name
36
- m.route_resources session_plural_name
37
- m.route_name :login, 'login', :controller => session_plural_name, :action => 'new'
38
- m.route_name :logout, 'logout', :controller => session_plural_name, :action => 'destroy'
39
- m.route_name :signup, 'signup', :controller => user_plural_name, :action => 'new'
40
-
41
- m.insert_into "app/controllers/#{application_controller_name}.rb", 'include Authentication'
42
-
43
- if test_framework == :rspec
44
- m.directory "spec"
45
- m.directory "spec/fixtures"
46
- m.directory "spec/controllers"
47
- m.directory "spec/models"
48
- m.template "fixtures.yml", "spec/fixtures/#{user_plural_name}.yml"
49
- m.template "tests/rspec/user.rb", "spec/models/#{user_singular_name}_spec.rb"
50
- m.template "tests/rspec/users_controller.rb", "spec/controllers/#{user_plural_name}_controller_spec.rb"
51
- m.template "tests/rspec/sessions_controller.rb", "spec/controllers/#{session_plural_name}_controller_spec.rb"
52
- else
53
- m.directory "test"
54
- m.directory "test/fixtures"
55
- m.directory "test/functional"
56
- m.directory "test/unit"
57
- m.template "fixtures.yml", "test/fixtures/#{user_plural_name}.yml"
58
- m.template "tests/#{test_framework}/user.rb", "test/unit/#{user_singular_name}_test.rb"
59
- m.template "tests/#{test_framework}/users_controller.rb", "test/functional/#{user_plural_name}_controller_test.rb"
60
- m.template "tests/#{test_framework}/sessions_controller.rb", "test/functional/#{session_plural_name}_controller_test.rb"
61
- end
62
- end
63
- end
64
-
65
- def user_singular_name
66
- user_name.underscore
67
- end
68
-
69
- def user_plural_name
70
- user_singular_name.pluralize
71
- end
72
-
73
- def user_class_name
74
- user_name.camelize
75
- end
76
-
77
- def user_plural_class_name
78
- user_plural_name.camelize
79
- end
80
-
81
- def session_singular_name
82
- session_name.underscore
83
- end
84
-
85
- def session_plural_name
86
- session_singular_name.pluralize
87
- end
88
-
89
- def session_class_name
90
- session_name.camelize
91
- end
92
-
93
- def session_plural_class_name
94
- session_plural_name.camelize
95
- end
96
-
97
- def application_controller_name
98
- Rails.version >= '2.3.0' ? 'application_controller' : 'application'
99
- end
100
-
101
- protected
102
-
103
- def view_language
104
- options[:haml] ? 'haml' : 'erb'
105
- end
106
-
107
- def test_framework
108
- options[:test_framework] ||= File.exist?(destination_path("spec")) ? :rspec : :testunit
109
- end
110
-
111
- def add_options!(opt)
112
- opt.separator ''
113
- opt.separator 'Options:'
114
- opt.on("--testunit", "Use test/unit for test files.") { options[:test_framework] = :testunit }
115
- opt.on("--rspec", "Use RSpec for test files.") { options[:test_framework] = :rspec }
116
- opt.on("--shoulda", "Use Shoulda for test files.") { options[:test_framework] = :shoulda }
117
- opt.on("--haml", "Generate HAML views instead of ERB.") { |v| options[:haml] = true }
118
- opt.on("--authlogic", "Use Authlogic for authentication.") { |v| options[:authlogic] = true }
119
- end
120
-
121
- def banner
122
- <<-EOS
123
- Creates user model and controllers to handle registration and authentication.
124
-
125
- USAGE: #{$0} #{spec.name} [user_name] [sessions_controller_name]
126
- EOS
127
- end
128
- end
@@ -1,61 +0,0 @@
1
- # This module is included in your application controller which makes
2
- # several methods available to all controllers and views. Here's a
3
- # common example you might add to your application layout file.
4
- #
5
- # <%% if logged_in? %>
6
- # Welcome <%%=h current_<%= user_singular_name %>.username %>! Not you?
7
- # <%%= link_to "Log out", logout_path %>
8
- # <%% else %>
9
- # <%%= link_to "Sign up", signup_path %> or
10
- # <%%= link_to "log in", login_path %>.
11
- # <%% end %>
12
- #
13
- # You can also restrict unregistered users from accessing a controller using
14
- # a before filter. For example.
15
- #
16
- # before_filter :login_required, :except => [:index, :show]
17
- module Authentication
18
- def self.included(controller)
19
- controller.send :helper_method, :current_<%= user_singular_name %>, :logged_in?, :redirect_to_target_or_default
20
- controller.filter_parameter_logging :password
21
- end
22
-
23
- <%- if options[:authlogic] -%>
24
- def current_<%= session_singular_name %>
25
- return @current_<%= session_singular_name %> if defined?(@current_<%= session_singular_name %>)
26
- @current_<%= session_singular_name %> = <%= session_class_name %>.find
27
- end
28
-
29
- def current_<%= user_singular_name %>
30
- return @current_<%= user_singular_name %> if defined?(@current_<%= user_singular_name %>)
31
- @current_<%= user_singular_name %> = current_<%= session_singular_name %> && current_<%= session_singular_name %>.record
32
- end
33
- <%- else -%>
34
- def current_<%= user_singular_name %>
35
- @current_<%= user_singular_name %> ||= <%= user_class_name %>.find(session[:<%= user_singular_name %>_id]) if session[:<%= user_singular_name %>_id]
36
- end
37
- <%- end -%>
38
-
39
- def logged_in?
40
- current_<%= user_singular_name %>
41
- end
42
-
43
- def login_required
44
- unless logged_in?
45
- flash[:error] = "You must first log in or sign up before accessing this page."
46
- store_target_location
47
- redirect_to login_url
48
- end
49
- end
50
-
51
- def redirect_to_target_or_default(default)
52
- redirect_to(session[:return_to] || default)
53
- session[:return_to] = nil
54
- end
55
-
56
- private
57
-
58
- def store_target_location
59
- session[:return_to] = request.request_uri
60
- end
61
- end