devise 1.1.rc1 → 1.1.rc2
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of devise might be problematic. Click here for more details.
- data/CHANGELOG.rdoc +63 -27
- data/Gemfile +15 -13
- data/README.rdoc +63 -51
- data/Rakefile +3 -2
- data/TODO +1 -0
- data/app/controllers/devise/registrations_controller.rb +1 -1
- data/app/mailers/devise/mailer.rb +43 -43
- data/app/views/devise/confirmations/new.html.erb +2 -2
- data/app/views/devise/passwords/edit.html.erb +4 -4
- data/app/views/devise/passwords/new.html.erb +2 -2
- data/app/views/devise/registrations/edit.html.erb +8 -8
- data/app/views/devise/registrations/new.html.erb +6 -6
- data/app/views/devise/sessions/new.html.erb +4 -4
- data/app/views/devise/unlocks/new.html.erb +2 -2
- data/config/locales/en.yml +7 -4
- data/lib/devise.rb +33 -6
- data/lib/devise/controllers/helpers.rb +38 -2
- data/lib/devise/encryptors/authlogic_sha512.rb +0 -2
- data/lib/devise/encryptors/bcrypt.rb +0 -2
- data/lib/devise/encryptors/clearance_sha1.rb +0 -2
- data/lib/devise/encryptors/sha1.rb +6 -8
- data/lib/devise/encryptors/sha512.rb +6 -8
- data/lib/devise/failure_app.rb +3 -2
- data/lib/devise/hooks/activatable.rb +4 -1
- data/lib/devise/hooks/forgetable.rb +4 -3
- data/lib/devise/hooks/rememberable.rb +6 -2
- data/lib/devise/hooks/timeoutable.rb +6 -2
- data/lib/devise/mapping.rb +7 -8
- data/lib/devise/models.rb +0 -34
- data/lib/devise/models/authenticatable.rb +29 -3
- data/lib/devise/models/confirmable.rb +3 -2
- data/lib/devise/models/database_authenticatable.rb +4 -2
- data/lib/devise/models/lockable.rb +1 -1
- data/lib/devise/models/recoverable.rb +1 -1
- data/lib/devise/models/rememberable.rb +9 -1
- data/lib/devise/orm/active_record.rb +4 -6
- data/lib/devise/orm/data_mapper.rb +5 -7
- data/lib/devise/orm/mongoid.rb +2 -13
- data/lib/devise/path_checker.rb +13 -0
- data/lib/devise/rails.rb +45 -18
- data/lib/devise/rails/routes.rb +24 -7
- data/lib/devise/schema.rb +23 -19
- data/lib/devise/strategies/authenticatable.rb +20 -4
- data/lib/devise/strategies/database_authenticatable.rb +1 -1
- data/lib/devise/strategies/token_authenticatable.rb +2 -2
- data/lib/devise/test_helpers.rb +2 -1
- data/lib/devise/version.rb +1 -1
- data/lib/generators/devise/devise/devise_generator.rb +86 -0
- data/lib/generators/devise/{templates → devise/templates}/migration.rb +2 -2
- data/lib/generators/devise/install/install_generator.rb +24 -0
- data/lib/generators/{devise_install → devise/install}/templates/README +1 -1
- data/lib/generators/{devise_install → devise/install}/templates/devise.rb +37 -18
- data/lib/generators/devise/views/views_generator.rb +63 -0
- data/lib/generators/devise_generator.rb +2 -0
- data/lib/generators/devise_install_generator.rb +4 -0
- data/lib/generators/devise_views_generator.rb +4 -0
- data/test/controllers/helpers_test.rb +15 -0
- data/test/devise_test.rb +1 -0
- data/test/failure_app_test.rb +25 -10
- data/test/integration/authenticatable_test.rb +279 -0
- data/test/integration/database_authenticatable_test.rb +2 -262
- data/test/integration/http_authenticatable_test.rb +7 -9
- data/test/integration/registerable_test.rb +14 -2
- data/test/integration/rememberable_test.rb +15 -3
- data/test/integration/timeoutable_test.rb +12 -0
- data/test/integration/token_authenticatable_test.rb +2 -3
- data/test/mailers/confirmation_instructions_test.rb +2 -2
- data/test/mailers/reset_password_instructions_test.rb +2 -2
- data/test/mailers/unlock_instructions_test.rb +3 -3
- data/test/models/confirmable_test.rb +16 -0
- data/test/models/database_authenticatable_test.rb +20 -20
- data/test/models/lockable_test.rb +1 -1
- data/test/models/rememberable_test.rb +4 -4
- data/test/orm/data_mapper.rb +9 -0
- data/test/rails_app/app/active_record/shim.rb +2 -0
- data/test/rails_app/app/controllers/application_controller.rb +1 -0
- data/test/rails_app/app/controllers/home_controller.rb +3 -0
- data/test/rails_app/app/controllers/users_controller.rb +2 -0
- data/test/rails_app/app/data_mapper/shim.rb +2 -0
- data/test/rails_app/app/data_mapper/user.rb +4 -5
- data/test/rails_app/app/mongoid/admin.rb +1 -10
- data/test/rails_app/app/mongoid/shim.rb +16 -0
- data/test/rails_app/app/mongoid/user.rb +1 -12
- data/test/rails_app/config/application.rb +2 -0
- data/test/rails_app/config/initializers/devise.rb +2 -2
- data/test/rails_app/config/routes.rb +6 -1
- data/test/routes_test.rb +2 -2
- data/test/test_helper.rb +0 -4
- data/test/test_helpers_test.rb +1 -0
- metadata +113 -12
- data/lib/generators/devise/devise_generator.rb +0 -67
- data/lib/generators/devise_install/devise_install_generator.rb +0 -25
- data/lib/generators/devise_views/devise_views_generator.rb +0 -62
@@ -5,7 +5,7 @@ Devise.setup do |config|
|
|
5
5
|
# the encrypted password. By default no pepper is used.
|
6
6
|
# config.pepper = "rake secret output"
|
7
7
|
|
8
|
-
# Configure how many times you want the password
|
8
|
+
# Configure how many times you want the password re-encrypted. Default is 10.
|
9
9
|
# config.stretches = 10
|
10
10
|
|
11
11
|
# Define which will be the encryption algorithm. Supported algorithms are :sha1
|
@@ -49,7 +49,7 @@ Devise.setup do |config|
|
|
49
49
|
|
50
50
|
# Defines which strategy will be used to unlock an account.
|
51
51
|
# :email = Sends an unlock link to the user email
|
52
|
-
# :time =
|
52
|
+
# :time = Re-enables login after a certain amount of time (see :unlock_in below)
|
53
53
|
# :both = enables both strategies
|
54
54
|
# config.unlock_strategy = :both
|
55
55
|
|
@@ -11,7 +11,8 @@ Rails::Application.routes.draw do
|
|
11
11
|
:class_name => "User", :path_names => {
|
12
12
|
:sign_in => "login", :sign_out => "logout",
|
13
13
|
:password => "secret", :confirmation => "verification",
|
14
|
-
:unlock => "unblock", :sign_up => "register"
|
14
|
+
:unlock => "unblock", :sign_up => "register",
|
15
|
+
:registration => "management"
|
15
16
|
}
|
16
17
|
|
17
18
|
match "/admin_area/home", :to => "admins#index", :as => :admin_root
|
@@ -21,4 +22,8 @@ Rails::Application.routes.draw do
|
|
21
22
|
match "/anywhere", :to => "foo#bar", :as => :new_admin_password
|
22
23
|
|
23
24
|
root :to => "home#index"
|
25
|
+
|
26
|
+
authenticate(:admin) do
|
27
|
+
match "/private", :to => "home#private", :as => :private
|
28
|
+
end
|
24
29
|
end
|
data/test/routes_test.rb
CHANGED
@@ -74,7 +74,7 @@ class MapRoutingTest < ActionController::TestCase
|
|
74
74
|
assert_recognizes({:controller => 'devise/registrations', :action => 'destroy'}, {:path => 'users', :method => :delete})
|
75
75
|
end
|
76
76
|
|
77
|
-
test 'map admin with :
|
77
|
+
test 'map admin with :path option' do
|
78
78
|
assert_recognizes({:controller => 'devise/registrations', :action => 'new'}, {:path => 'admin_area/sign_up', :method => :get})
|
79
79
|
end
|
80
80
|
|
@@ -109,6 +109,6 @@ class MapRoutingTest < ActionController::TestCase
|
|
109
109
|
end
|
110
110
|
|
111
111
|
test 'map account with custom path name for registration' do
|
112
|
-
assert_recognizes({:controller => 'devise/registrations', :action => 'new', :locale => 'en'}, '/en/accounts/register')
|
112
|
+
assert_recognizes({:controller => 'devise/registrations', :action => 'new', :locale => 'en'}, '/en/accounts/management/register')
|
113
113
|
end
|
114
114
|
end
|
data/test/test_helper.rb
CHANGED
@@ -11,10 +11,6 @@ require "orm/#{DEVISE_ORM}"
|
|
11
11
|
I18n.load_path << File.expand_path("../support/locale/en.yml", __FILE__)
|
12
12
|
require 'mocha'
|
13
13
|
|
14
|
-
ActionMailer::Base.delivery_method = :test
|
15
|
-
ActionMailer::Base.perform_deliveries = true
|
16
|
-
ActionMailer::Base.default_url_options[:host] = 'test.com'
|
17
|
-
|
18
14
|
Webrat.configure do |config|
|
19
15
|
config.mode = :rails
|
20
16
|
config.open_error_files = false
|
data/test/test_helpers_test.rb
CHANGED
@@ -7,6 +7,7 @@ class TestHelpersTest < ActionController::TestCase
|
|
7
7
|
test "redirects if attempting to access a page unauthenticated" do
|
8
8
|
get :index
|
9
9
|
assert_redirected_to new_user_session_path
|
10
|
+
assert_equal "You need to sign in or sign up before continuing.", flash[:alert]
|
10
11
|
end
|
11
12
|
|
12
13
|
test "redirects if attempting to access a page with a unconfirmed account" do
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: devise
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 977940499
|
4
5
|
prerelease: true
|
5
6
|
segments:
|
6
7
|
- 1
|
7
8
|
- 1
|
8
|
-
-
|
9
|
-
version: 1.1.
|
9
|
+
- rc2
|
10
|
+
version: 1.1.rc2
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- "Jos\xC3\xA9 Valim"
|
@@ -15,23 +16,41 @@ autorequire:
|
|
15
16
|
bindir: bin
|
16
17
|
cert_chain: []
|
17
18
|
|
18
|
-
date: 2010-
|
19
|
+
date: 2010-06-23 00:00:00 +02:00
|
19
20
|
default_executable:
|
20
21
|
dependencies:
|
21
22
|
- !ruby/object:Gem::Dependency
|
22
23
|
name: warden
|
23
24
|
prerelease: false
|
24
25
|
requirement: &id001 !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
25
27
|
requirements:
|
26
28
|
- - ~>
|
27
29
|
- !ruby/object:Gem::Version
|
30
|
+
hash: 57
|
28
31
|
segments:
|
29
32
|
- 0
|
30
33
|
- 10
|
31
|
-
-
|
32
|
-
version: 0.10.
|
34
|
+
- 7
|
35
|
+
version: 0.10.7
|
33
36
|
type: :runtime
|
34
37
|
version_requirements: *id001
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: bcrypt-ruby
|
40
|
+
prerelease: false
|
41
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ~>
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
hash: 15
|
47
|
+
segments:
|
48
|
+
- 2
|
49
|
+
- 1
|
50
|
+
- 2
|
51
|
+
version: 2.1.2
|
52
|
+
type: :runtime
|
53
|
+
version_requirements: *id002
|
35
54
|
description: Flexible authentication solution for Rails with Warden
|
36
55
|
email: contact@plataformatec.com.br
|
37
56
|
executables: []
|
@@ -104,6 +123,7 @@ files:
|
|
104
123
|
- lib/devise/orm/active_record.rb
|
105
124
|
- lib/devise/orm/data_mapper.rb
|
106
125
|
- lib/devise/orm/mongoid.rb
|
126
|
+
- lib/devise/path_checker.rb
|
107
127
|
- lib/devise/rails.rb
|
108
128
|
- lib/devise/rails/routes.rb
|
109
129
|
- lib/devise/rails/warden_compat.rb
|
@@ -115,12 +135,85 @@ files:
|
|
115
135
|
- lib/devise/strategies/token_authenticatable.rb
|
116
136
|
- lib/devise/test_helpers.rb
|
117
137
|
- lib/devise/version.rb
|
118
|
-
- lib/generators/devise/devise_generator.rb
|
119
|
-
- lib/generators/devise/templates/migration.rb
|
120
|
-
- lib/generators/
|
121
|
-
- lib/generators/
|
122
|
-
- lib/generators/
|
123
|
-
- lib/generators/
|
138
|
+
- lib/generators/devise/devise/devise_generator.rb
|
139
|
+
- lib/generators/devise/devise/templates/migration.rb
|
140
|
+
- lib/generators/devise/install/install_generator.rb
|
141
|
+
- lib/generators/devise/install/templates/README
|
142
|
+
- lib/generators/devise/install/templates/devise.rb
|
143
|
+
- lib/generators/devise/views/views_generator.rb
|
144
|
+
- lib/generators/devise_generator.rb
|
145
|
+
- lib/generators/devise_install_generator.rb
|
146
|
+
- lib/generators/devise_views_generator.rb
|
147
|
+
- test/controllers/helpers_test.rb
|
148
|
+
- test/controllers/internal_helpers_test.rb
|
149
|
+
- test/controllers/url_helpers_test.rb
|
150
|
+
- test/devise_test.rb
|
151
|
+
- test/encryptors_test.rb
|
152
|
+
- test/failure_app_test.rb
|
153
|
+
- test/integration/authenticatable_test.rb
|
154
|
+
- test/integration/confirmable_test.rb
|
155
|
+
- test/integration/database_authenticatable_test.rb
|
156
|
+
- test/integration/http_authenticatable_test.rb
|
157
|
+
- test/integration/lockable_test.rb
|
158
|
+
- test/integration/recoverable_test.rb
|
159
|
+
- test/integration/registerable_test.rb
|
160
|
+
- test/integration/rememberable_test.rb
|
161
|
+
- test/integration/timeoutable_test.rb
|
162
|
+
- test/integration/token_authenticatable_test.rb
|
163
|
+
- test/integration/trackable_test.rb
|
164
|
+
- test/mailers/confirmation_instructions_test.rb
|
165
|
+
- test/mailers/reset_password_instructions_test.rb
|
166
|
+
- test/mailers/unlock_instructions_test.rb
|
167
|
+
- test/mapping_test.rb
|
168
|
+
- test/models/confirmable_test.rb
|
169
|
+
- test/models/database_authenticatable_test.rb
|
170
|
+
- test/models/lockable_test.rb
|
171
|
+
- test/models/recoverable_test.rb
|
172
|
+
- test/models/rememberable_test.rb
|
173
|
+
- test/models/timeoutable_test.rb
|
174
|
+
- test/models/token_authenticatable_test.rb
|
175
|
+
- test/models/trackable_test.rb
|
176
|
+
- test/models/validatable_test.rb
|
177
|
+
- test/models_test.rb
|
178
|
+
- test/orm/active_record.rb
|
179
|
+
- test/orm/data_mapper.rb
|
180
|
+
- test/orm/mongoid.rb
|
181
|
+
- test/rails_app/app/active_record/admin.rb
|
182
|
+
- test/rails_app/app/active_record/shim.rb
|
183
|
+
- test/rails_app/app/active_record/user.rb
|
184
|
+
- test/rails_app/app/controllers/admins_controller.rb
|
185
|
+
- test/rails_app/app/controllers/application_controller.rb
|
186
|
+
- test/rails_app/app/controllers/home_controller.rb
|
187
|
+
- test/rails_app/app/controllers/sessions_controller.rb
|
188
|
+
- test/rails_app/app/controllers/users_controller.rb
|
189
|
+
- test/rails_app/app/data_mapper/admin.rb
|
190
|
+
- test/rails_app/app/data_mapper/shim.rb
|
191
|
+
- test/rails_app/app/data_mapper/user.rb
|
192
|
+
- test/rails_app/app/helpers/application_helper.rb
|
193
|
+
- test/rails_app/app/mongoid/admin.rb
|
194
|
+
- test/rails_app/app/mongoid/shim.rb
|
195
|
+
- test/rails_app/app/mongoid/user.rb
|
196
|
+
- test/rails_app/config/application.rb
|
197
|
+
- test/rails_app/config/boot.rb
|
198
|
+
- test/rails_app/config/environment.rb
|
199
|
+
- test/rails_app/config/environments/development.rb
|
200
|
+
- test/rails_app/config/environments/production.rb
|
201
|
+
- test/rails_app/config/environments/test.rb
|
202
|
+
- test/rails_app/config/initializers/backtrace_silencers.rb
|
203
|
+
- test/rails_app/config/initializers/devise.rb
|
204
|
+
- test/rails_app/config/initializers/inflections.rb
|
205
|
+
- test/rails_app/config/initializers/secret_token.rb
|
206
|
+
- test/rails_app/config/routes.rb
|
207
|
+
- test/rails_app/db/migrate/20100401102949_create_tables.rb
|
208
|
+
- test/rails_app/db/schema.rb
|
209
|
+
- test/routes_test.rb
|
210
|
+
- test/support/assertions.rb
|
211
|
+
- test/support/helpers.rb
|
212
|
+
- test/support/integration.rb
|
213
|
+
- test/support/test_silencer.rb
|
214
|
+
- test/support/webrat/integrations/rails.rb
|
215
|
+
- test/test_helper.rb
|
216
|
+
- test/test_helpers_test.rb
|
124
217
|
has_rdoc: true
|
125
218
|
homepage: http://github.com/plataformatec/devise
|
126
219
|
licenses: []
|
@@ -131,16 +224,20 @@ rdoc_options:
|
|
131
224
|
require_paths:
|
132
225
|
- lib
|
133
226
|
required_ruby_version: !ruby/object:Gem::Requirement
|
227
|
+
none: false
|
134
228
|
requirements:
|
135
229
|
- - ">="
|
136
230
|
- !ruby/object:Gem::Version
|
231
|
+
hash: 3
|
137
232
|
segments:
|
138
233
|
- 0
|
139
234
|
version: "0"
|
140
235
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
236
|
+
none: false
|
141
237
|
requirements:
|
142
238
|
- - ">"
|
143
239
|
- !ruby/object:Gem::Version
|
240
|
+
hash: 25
|
144
241
|
segments:
|
145
242
|
- 1
|
146
243
|
- 3
|
@@ -149,7 +246,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
149
246
|
requirements: []
|
150
247
|
|
151
248
|
rubyforge_project:
|
152
|
-
rubygems_version: 1.3.
|
249
|
+
rubygems_version: 1.3.7
|
153
250
|
signing_key:
|
154
251
|
specification_version: 3
|
155
252
|
summary: Flexible authentication solution for Rails with Warden
|
@@ -160,6 +257,7 @@ test_files:
|
|
160
257
|
- test/devise_test.rb
|
161
258
|
- test/encryptors_test.rb
|
162
259
|
- test/failure_app_test.rb
|
260
|
+
- test/integration/authenticatable_test.rb
|
163
261
|
- test/integration/confirmable_test.rb
|
164
262
|
- test/integration/database_authenticatable_test.rb
|
165
263
|
- test/integration/http_authenticatable_test.rb
|
@@ -188,6 +286,7 @@ test_files:
|
|
188
286
|
- test/orm/data_mapper.rb
|
189
287
|
- test/orm/mongoid.rb
|
190
288
|
- test/rails_app/app/active_record/admin.rb
|
289
|
+
- test/rails_app/app/active_record/shim.rb
|
191
290
|
- test/rails_app/app/active_record/user.rb
|
192
291
|
- test/rails_app/app/controllers/admins_controller.rb
|
193
292
|
- test/rails_app/app/controllers/application_controller.rb
|
@@ -195,9 +294,11 @@ test_files:
|
|
195
294
|
- test/rails_app/app/controllers/sessions_controller.rb
|
196
295
|
- test/rails_app/app/controllers/users_controller.rb
|
197
296
|
- test/rails_app/app/data_mapper/admin.rb
|
297
|
+
- test/rails_app/app/data_mapper/shim.rb
|
198
298
|
- test/rails_app/app/data_mapper/user.rb
|
199
299
|
- test/rails_app/app/helpers/application_helper.rb
|
200
300
|
- test/rails_app/app/mongoid/admin.rb
|
301
|
+
- test/rails_app/app/mongoid/shim.rb
|
201
302
|
- test/rails_app/app/mongoid/user.rb
|
202
303
|
- test/rails_app/config/application.rb
|
203
304
|
- test/rails_app/config/boot.rb
|
@@ -1,67 +0,0 @@
|
|
1
|
-
require 'rails/generators/migration'
|
2
|
-
|
3
|
-
class DeviseGenerator < Rails::Generators::NamedBase
|
4
|
-
include Rails::Generators::Migration
|
5
|
-
|
6
|
-
desc "Generates a model with the given NAME (if one does not exist) with devise " <<
|
7
|
-
"configuration plus a migration file and devise routes."
|
8
|
-
|
9
|
-
def self.source_root
|
10
|
-
@_devise_source_root ||= File.expand_path("../templates", __FILE__)
|
11
|
-
end
|
12
|
-
|
13
|
-
def self.orm_has_migration?
|
14
|
-
Rails::Generators.options[:rails][:orm] == :active_record
|
15
|
-
end
|
16
|
-
|
17
|
-
def self.next_migration_number(path)
|
18
|
-
Time.now.utc.strftime("%Y%m%d%H%M%S")
|
19
|
-
end
|
20
|
-
|
21
|
-
class_option :orm
|
22
|
-
class_option :migration, :type => :boolean, :default => orm_has_migration?
|
23
|
-
|
24
|
-
def invoke_orm_model
|
25
|
-
if model_exists?
|
26
|
-
say "* Model already exists. Adding Devise behavior."
|
27
|
-
else
|
28
|
-
invoke "model", [name], :migration => false, :orm => options[:orm]
|
29
|
-
|
30
|
-
unless model_exists?
|
31
|
-
abort "Tried to invoke the model generator for '#{options[:orm]}' but could not find it.\n" <<
|
32
|
-
"Please create your model by hand before calling `rails g devise #{name}`."
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
def inject_devise_config_into_model
|
38
|
-
inject_into_class model_path, class_name, <<-CONTENT
|
39
|
-
# Include default devise modules. Others available are:
|
40
|
-
# :token_authenticatable, :lockable and :timeoutable
|
41
|
-
devise :database_authenticatable, :registerable, :confirmable,
|
42
|
-
:recoverable, :rememberable, :trackable, :validatable
|
43
|
-
|
44
|
-
# Setup accessible (or protected) attributes for your model
|
45
|
-
attr_accessible :email, :password, :password_confirmation
|
46
|
-
CONTENT
|
47
|
-
end
|
48
|
-
|
49
|
-
def copy_migration_template
|
50
|
-
return unless options.migration?
|
51
|
-
migration_template "migration.rb", "db/migrate/devise_create_#{table_name}"
|
52
|
-
end
|
53
|
-
|
54
|
-
def add_devise_routes
|
55
|
-
route "devise_for :#{table_name}"
|
56
|
-
end
|
57
|
-
|
58
|
-
protected
|
59
|
-
|
60
|
-
def model_exists?
|
61
|
-
File.exists?(File.join(destination_root, model_path))
|
62
|
-
end
|
63
|
-
|
64
|
-
def model_path
|
65
|
-
@model_path ||= File.join("app", "models", "#{file_path}.rb")
|
66
|
-
end
|
67
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
class DeviseInstallGenerator < Rails::Generators::Base
|
2
|
-
desc "Creates a Devise initializer and copy locale files to your application."
|
3
|
-
|
4
|
-
def self.source_root
|
5
|
-
@_devise_source_root ||= File.expand_path("../templates", __FILE__)
|
6
|
-
end
|
7
|
-
|
8
|
-
def copy_initializer
|
9
|
-
template "devise.rb", "config/initializers/devise.rb"
|
10
|
-
end
|
11
|
-
|
12
|
-
def copy_locale
|
13
|
-
copy_file "../../../../config/locales/en.yml", "config/locales/devise.en.yml"
|
14
|
-
end
|
15
|
-
|
16
|
-
def show_readme
|
17
|
-
readme "README"
|
18
|
-
end
|
19
|
-
|
20
|
-
protected
|
21
|
-
|
22
|
-
def readme(path)
|
23
|
-
say File.read(File.expand_path(path, self.class.source_root))
|
24
|
-
end
|
25
|
-
end
|
@@ -1,62 +0,0 @@
|
|
1
|
-
class DeviseViewsGenerator < Rails::Generators::Base
|
2
|
-
desc "Copies all Devise views to your application."
|
3
|
-
|
4
|
-
argument :scope, :required => false, :default => nil,
|
5
|
-
:desc => "The scope to copy views to"
|
6
|
-
|
7
|
-
class_option :template_engine, :type => :string, :aliases => "-t", :default => "erb",
|
8
|
-
:desc => "Template engine for the views. Available options are 'erb' and 'haml'."
|
9
|
-
|
10
|
-
def self.source_root
|
11
|
-
@_devise_source_root ||= File.expand_path("../../../../app/views", __FILE__)
|
12
|
-
end
|
13
|
-
|
14
|
-
def copy_views
|
15
|
-
case options[:template_engine]
|
16
|
-
when "haml"
|
17
|
-
verify_haml_existence
|
18
|
-
verify_haml_version
|
19
|
-
create_and_copy_haml_views
|
20
|
-
else
|
21
|
-
directory "devise", "app/views/#{scope || 'devise'}"
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
protected
|
26
|
-
|
27
|
-
def verify_haml_existence
|
28
|
-
begin
|
29
|
-
require 'haml'
|
30
|
-
rescue LoadError
|
31
|
-
say "HAML is not installed, or it is not specified in your Gemfile."
|
32
|
-
exit
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def verify_haml_version
|
37
|
-
unless Haml.version[:major] == 2 and Haml.version[:minor] >= 3 or Haml.version[:major] >= 3
|
38
|
-
say "To generate HAML templates, you need to install HAML 2.3 or above."
|
39
|
-
exit
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
def create_and_copy_haml_views
|
44
|
-
require 'tmpdir'
|
45
|
-
html_root = "#{self.class.source_root}/devise"
|
46
|
-
|
47
|
-
Dir.mktmpdir("devise-haml.") do |haml_root|
|
48
|
-
Dir["#{html_root}/**/*"].each do |path|
|
49
|
-
relative_path = path.sub(html_root, "")
|
50
|
-
source_path = (haml_root + relative_path).sub(/erb$/, "haml")
|
51
|
-
|
52
|
-
if File.directory?(path)
|
53
|
-
FileUtils.mkdir_p(source_path)
|
54
|
-
else
|
55
|
-
`html2haml -r #{path} #{source_path}`
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
directory haml_root, "app/views/#{scope || 'devise'}"
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|