devbootsrap 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +31 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/app/controllers/devise/confirmations_controller.rb +47 -0
- data/app/controllers/devise/omniauth_callbacks_controller.rb +30 -0
- data/app/controllers/devise/passwords_controller.rb +70 -0
- data/app/controllers/devise/registrations_controller.rb +137 -0
- data/app/controllers/devise/sessions_controller.rb +53 -0
- data/app/controllers/devise/unlocks_controller.rb +46 -0
- data/app/controllers/devise_controller.rb +176 -0
- data/app/helpers/devise_helper.rb +25 -0
- data/app/mailers/devise/mailer.rb +20 -0
- data/app/views/devise/confirmations/new.html.erb +12 -0
- data/app/views/devise/mailer/confirmation_instructions.html.erb +5 -0
- data/app/views/devise/mailer/reset_password_instructions.html.erb +8 -0
- data/app/views/devise/mailer/unlock_instructions.html.erb +7 -0
- data/app/views/devise/passwords/edit.html.erb +16 -0
- data/app/views/devise/passwords/new.html.erb +12 -0
- data/app/views/devise/registrations/edit.html.erb +29 -0
- data/app/views/devise/registrations/new.html.erb +18 -0
- data/app/views/devise/sessions/new.html.erb +17 -0
- data/app/views/devise/shared/_links.erb +25 -0
- data/app/views/devise/unlocks/new.html.erb +12 -0
- data/config/locales/en.yml +59 -0
- data/devbootsrap.gemspec +29 -0
- data/gemfiles/Gemfile.rails-3.2-stable +29 -0
- data/gemfiles/Gemfile.rails-4.0-stable +29 -0
- data/gemfiles/Gemfile.rails-head +29 -0
- data/lib/devbootsrap.rb +5 -0
- data/lib/devbootsrap/version.rb +3 -0
- data/lib/devise.rb +491 -0
- data/lib/devise/controllers/helpers.rb +213 -0
- data/lib/devise/controllers/rememberable.rb +47 -0
- data/lib/devise/controllers/scoped_views.rb +17 -0
- data/lib/devise/controllers/sign_in_out.rb +103 -0
- data/lib/devise/controllers/store_location.rb +50 -0
- data/lib/devise/controllers/url_helpers.rb +67 -0
- data/lib/devise/delegator.rb +16 -0
- data/lib/devise/failure_app.rb +205 -0
- data/lib/devise/hooks/activatable.rb +11 -0
- data/lib/devise/hooks/csrf_cleaner.rb +5 -0
- data/lib/devise/hooks/forgetable.rb +9 -0
- data/lib/devise/hooks/lockable.rb +7 -0
- data/lib/devise/hooks/proxy.rb +21 -0
- data/lib/devise/hooks/rememberable.rb +7 -0
- data/lib/devise/hooks/timeoutable.rb +28 -0
- data/lib/devise/hooks/trackable.rb +9 -0
- data/lib/devise/mailers/helpers.rb +90 -0
- data/lib/devise/mapping.rb +172 -0
- data/lib/devise/models.rb +119 -0
- data/lib/devise/models/authenticatable.rb +284 -0
- data/lib/devise/models/confirmable.rb +295 -0
- data/lib/devise/models/database_authenticatable.rb +164 -0
- data/lib/devise/models/lockable.rb +196 -0
- data/lib/devise/models/omniauthable.rb +27 -0
- data/lib/devise/models/recoverable.rb +131 -0
- data/lib/devise/models/registerable.rb +25 -0
- data/lib/devise/models/rememberable.rb +129 -0
- data/lib/devise/models/timeoutable.rb +49 -0
- data/lib/devise/models/trackable.rb +35 -0
- data/lib/devise/models/validatable.rb +66 -0
- data/lib/devise/modules.rb +28 -0
- data/lib/devise/omniauth.rb +28 -0
- data/lib/devise/omniauth/config.rb +45 -0
- data/lib/devise/omniauth/url_helpers.rb +18 -0
- data/lib/devise/orm/active_record.rb +3 -0
- data/lib/devise/orm/mongoid.rb +3 -0
- data/lib/devise/parameter_filter.rb +40 -0
- data/lib/devise/parameter_sanitizer.rb +99 -0
- data/lib/devise/rails.rb +56 -0
- data/lib/devise/rails/routes.rb +496 -0
- data/lib/devise/rails/warden_compat.rb +22 -0
- data/lib/devise/strategies/authenticatable.rb +167 -0
- data/lib/devise/strategies/base.rb +20 -0
- data/lib/devise/strategies/database_authenticatable.rb +23 -0
- data/lib/devise/strategies/rememberable.rb +55 -0
- data/lib/devise/test_helpers.rb +132 -0
- data/lib/devise/time_inflector.rb +14 -0
- data/lib/devise/token_generator.rb +70 -0
- data/lib/devise/version.rb +3 -0
- data/lib/generators/active_record/devise_generator.rb +73 -0
- data/lib/generators/active_record/templates/migration.rb +18 -0
- data/lib/generators/active_record/templates/migration_existing.rb +25 -0
- data/lib/generators/devise/devise_generator.rb +26 -0
- data/lib/generators/devise/install_generator.rb +29 -0
- data/lib/generators/devise/orm_helpers.rb +51 -0
- data/lib/generators/devise/views_generator.rb +135 -0
- data/lib/generators/mongoid/devise_generator.rb +55 -0
- data/lib/generators/templates/README +35 -0
- data/lib/generators/templates/devise.rb +260 -0
- data/lib/generators/templates/markerb/confirmation_instructions.markerb +5 -0
- data/lib/generators/templates/markerb/reset_password_instructions.markerb +8 -0
- data/lib/generators/templates/markerb/unlock_instructions.markerb +7 -0
- data/lib/generators/templates/simple_form_for/confirmations/new.html.erb +16 -0
- data/lib/generators/templates/simple_form_for/passwords/edit.html.erb +19 -0
- data/lib/generators/templates/simple_form_for/passwords/new.html.erb +15 -0
- data/lib/generators/templates/simple_form_for/registrations/edit.html.erb +27 -0
- data/lib/generators/templates/simple_form_for/registrations/new.html.erb +17 -0
- data/lib/generators/templates/simple_form_for/sessions/new.html.erb +15 -0
- data/lib/generators/templates/simple_form_for/unlocks/new.html.erb +16 -0
- data/test/controllers/custom_registrations_controller_test.rb +35 -0
- data/test/controllers/custom_strategy_test.rb +62 -0
- data/test/controllers/helpers_test.rb +276 -0
- data/test/controllers/internal_helpers_test.rb +123 -0
- data/test/controllers/passwords_controller_test.rb +31 -0
- data/test/controllers/sessions_controller_test.rb +103 -0
- data/test/controllers/url_helpers_test.rb +59 -0
- data/test/delegator_test.rb +19 -0
- data/test/devise_test.rb +94 -0
- data/test/failure_app_test.rb +232 -0
- data/test/generators/active_record_generator_test.rb +103 -0
- data/test/generators/devise_generator_test.rb +39 -0
- data/test/generators/install_generator_test.rb +13 -0
- data/test/generators/mongoid_generator_test.rb +23 -0
- data/test/generators/views_generator_test.rb +96 -0
- data/test/helpers/devise_helper_test.rb +51 -0
- data/test/integration/authenticatable_test.rb +713 -0
- data/test/integration/confirmable_test.rb +284 -0
- data/test/integration/database_authenticatable_test.rb +84 -0
- data/test/integration/http_authenticatable_test.rb +105 -0
- data/test/integration/lockable_test.rb +239 -0
- data/test/integration/omniauthable_test.rb +133 -0
- data/test/integration/recoverable_test.rb +334 -0
- data/test/integration/registerable_test.rb +349 -0
- data/test/integration/rememberable_test.rb +167 -0
- data/test/integration/timeoutable_test.rb +183 -0
- data/test/integration/trackable_test.rb +92 -0
- data/test/mailers/confirmation_instructions_test.rb +115 -0
- data/test/mailers/reset_password_instructions_test.rb +96 -0
- data/test/mailers/unlock_instructions_test.rb +91 -0
- data/test/mapping_test.rb +127 -0
- data/test/models/authenticatable_test.rb +13 -0
- data/test/models/confirmable_test.rb +454 -0
- data/test/models/database_authenticatable_test.rb +249 -0
- data/test/models/lockable_test.rb +316 -0
- data/test/models/omniauthable_test.rb +7 -0
- data/test/models/recoverable_test.rb +184 -0
- data/test/models/registerable_test.rb +7 -0
- data/test/models/rememberable_test.rb +183 -0
- data/test/models/serializable_test.rb +49 -0
- data/test/models/timeoutable_test.rb +51 -0
- data/test/models/trackable_test.rb +13 -0
- data/test/models/validatable_test.rb +127 -0
- data/test/models_test.rb +144 -0
- data/test/omniauth/config_test.rb +57 -0
- data/test/omniauth/url_helpers_test.rb +54 -0
- data/test/orm/active_record.rb +10 -0
- data/test/orm/mongoid.rb +13 -0
- data/test/parameter_sanitizer_test.rb +81 -0
- data/test/rails_app/Rakefile +6 -0
- data/test/rails_app/app/active_record/admin.rb +6 -0
- data/test/rails_app/app/active_record/shim.rb +2 -0
- data/test/rails_app/app/active_record/user.rb +6 -0
- data/test/rails_app/app/controllers/admins/sessions_controller.rb +6 -0
- data/test/rails_app/app/controllers/admins_controller.rb +11 -0
- data/test/rails_app/app/controllers/application_controller.rb +9 -0
- data/test/rails_app/app/controllers/custom/registrations_controller.rb +21 -0
- data/test/rails_app/app/controllers/home_controller.rb +25 -0
- data/test/rails_app/app/controllers/publisher/registrations_controller.rb +2 -0
- data/test/rails_app/app/controllers/publisher/sessions_controller.rb +2 -0
- data/test/rails_app/app/controllers/users/omniauth_callbacks_controller.rb +14 -0
- data/test/rails_app/app/controllers/users_controller.rb +31 -0
- data/test/rails_app/app/helpers/application_helper.rb +3 -0
- data/test/rails_app/app/mailers/users/mailer.rb +12 -0
- data/test/rails_app/app/mongoid/admin.rb +29 -0
- data/test/rails_app/app/mongoid/shim.rb +23 -0
- data/test/rails_app/app/mongoid/user.rb +39 -0
- data/test/rails_app/app/views/admins/index.html.erb +1 -0
- data/test/rails_app/app/views/admins/sessions/new.html.erb +2 -0
- data/test/rails_app/app/views/home/admin_dashboard.html.erb +1 -0
- data/test/rails_app/app/views/home/index.html.erb +1 -0
- data/test/rails_app/app/views/home/join.html.erb +1 -0
- data/test/rails_app/app/views/home/private.html.erb +1 -0
- data/test/rails_app/app/views/home/user_dashboard.html.erb +1 -0
- data/test/rails_app/app/views/layouts/application.html.erb +24 -0
- data/test/rails_app/app/views/users/edit_form.html.erb +1 -0
- data/test/rails_app/app/views/users/index.html.erb +1 -0
- data/test/rails_app/app/views/users/mailer/confirmation_instructions.erb +1 -0
- data/test/rails_app/app/views/users/sessions/new.html.erb +1 -0
- data/test/rails_app/bin/bundle +3 -0
- data/test/rails_app/bin/rails +4 -0
- data/test/rails_app/bin/rake +4 -0
- data/test/rails_app/config.ru +4 -0
- data/test/rails_app/config/application.rb +40 -0
- data/test/rails_app/config/boot.rb +14 -0
- data/test/rails_app/config/database.yml +18 -0
- data/test/rails_app/config/environment.rb +5 -0
- data/test/rails_app/config/environments/development.rb +30 -0
- data/test/rails_app/config/environments/production.rb +80 -0
- data/test/rails_app/config/environments/test.rb +36 -0
- data/test/rails_app/config/initializers/backtrace_silencers.rb +7 -0
- data/test/rails_app/config/initializers/devise.rb +181 -0
- data/test/rails_app/config/initializers/inflections.rb +2 -0
- data/test/rails_app/config/initializers/secret_token.rb +8 -0
- data/test/rails_app/config/initializers/session_store.rb +1 -0
- data/test/rails_app/config/routes.rb +108 -0
- data/test/rails_app/db/migrate/20100401102949_create_tables.rb +71 -0
- data/test/rails_app/db/schema.rb +55 -0
- data/test/rails_app/lib/shared_admin.rb +17 -0
- data/test/rails_app/lib/shared_user.rb +29 -0
- data/test/rails_app/public/404.html +26 -0
- data/test/rails_app/public/422.html +26 -0
- data/test/rails_app/public/500.html +26 -0
- data/test/rails_app/public/favicon.ico +0 -0
- data/test/routes_test.rb +262 -0
- data/test/support/action_controller/record_identifier.rb +10 -0
- data/test/support/assertions.rb +40 -0
- data/test/support/helpers.rb +70 -0
- data/test/support/integration.rb +92 -0
- data/test/support/locale/en.yml +8 -0
- data/test/support/mongoid.yml +6 -0
- data/test/support/webrat/integrations/rails.rb +24 -0
- data/test/test_helper.rb +27 -0
- data/test/test_helpers_test.rb +173 -0
- data/test/test_models.rb +33 -0
- metadata +480 -0
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'rails/generators/active_record'
|
2
|
+
require 'generators/devise/orm_helpers'
|
3
|
+
|
4
|
+
module ActiveRecord
|
5
|
+
module Generators
|
6
|
+
class DeviseGenerator < ActiveRecord::Generators::Base
|
7
|
+
argument :attributes, type: :array, default: [], banner: "field:type field:type"
|
8
|
+
|
9
|
+
include Devise::Generators::OrmHelpers
|
10
|
+
source_root File.expand_path("../templates", __FILE__)
|
11
|
+
|
12
|
+
def copy_devise_migration
|
13
|
+
if (behavior == :invoke && model_exists?) || (behavior == :revoke && migration_exists?(table_name))
|
14
|
+
migration_template "migration_existing.rb", "db/migrate/add_devise_to_#{table_name}.rb"
|
15
|
+
else
|
16
|
+
migration_template "migration.rb", "db/migrate/devise_create_#{table_name}.rb"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def generate_model
|
21
|
+
invoke "active_record:model", [name], migration: false unless model_exists? && behavior == :invoke
|
22
|
+
end
|
23
|
+
|
24
|
+
def inject_devise_content
|
25
|
+
content = model_contents
|
26
|
+
|
27
|
+
class_path = if namespaced?
|
28
|
+
class_name.to_s.split("::")
|
29
|
+
else
|
30
|
+
[class_name]
|
31
|
+
end
|
32
|
+
|
33
|
+
indent_depth = class_path.size - 1
|
34
|
+
content = content.split("\n").map { |line| " " * indent_depth + line } .join("\n") << "\n"
|
35
|
+
|
36
|
+
inject_into_class(model_path, class_path.last, content) if model_exists?
|
37
|
+
end
|
38
|
+
|
39
|
+
def migration_data
|
40
|
+
<<RUBY
|
41
|
+
## Database authenticatable
|
42
|
+
t.string :email, null: false, default: ""
|
43
|
+
t.string :encrypted_password, null: false, default: ""
|
44
|
+
|
45
|
+
## Recoverable
|
46
|
+
t.string :reset_password_token
|
47
|
+
t.datetime :reset_password_sent_at
|
48
|
+
|
49
|
+
## Rememberable
|
50
|
+
t.datetime :remember_created_at
|
51
|
+
|
52
|
+
## Trackable
|
53
|
+
t.integer :sign_in_count, default: 0, null: false
|
54
|
+
t.datetime :current_sign_in_at
|
55
|
+
t.datetime :last_sign_in_at
|
56
|
+
t.string :current_sign_in_ip
|
57
|
+
t.string :last_sign_in_ip
|
58
|
+
|
59
|
+
## Confirmable
|
60
|
+
# t.string :confirmation_token
|
61
|
+
# t.datetime :confirmed_at
|
62
|
+
# t.datetime :confirmation_sent_at
|
63
|
+
# t.string :unconfirmed_email # Only if using reconfirmable
|
64
|
+
|
65
|
+
## Lockable
|
66
|
+
# t.integer :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts
|
67
|
+
# t.string :unlock_token # Only if unlock strategy is :email or :both
|
68
|
+
# t.datetime :locked_at
|
69
|
+
RUBY
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class DeviseCreate<%= table_name.camelize %> < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table(:<%= table_name %>) do |t|
|
4
|
+
<%= migration_data -%>
|
5
|
+
|
6
|
+
<% attributes.each do |attribute| -%>
|
7
|
+
t.<%= attribute.type %> :<%= attribute.name %>
|
8
|
+
<% end -%>
|
9
|
+
|
10
|
+
t.timestamps
|
11
|
+
end
|
12
|
+
|
13
|
+
add_index :<%= table_name %>, :email, unique: true
|
14
|
+
add_index :<%= table_name %>, :reset_password_token, unique: true
|
15
|
+
# add_index :<%= table_name %>, :confirmation_token, unique: true
|
16
|
+
# add_index :<%= table_name %>, :unlock_token, unique: true
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
class AddDeviseTo<%= table_name.camelize %> < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
change_table(:<%= table_name %>) do |t|
|
4
|
+
<%= migration_data -%>
|
5
|
+
|
6
|
+
<% attributes.each do |attribute| -%>
|
7
|
+
t.<%= attribute.type %> :<%= attribute.name %>
|
8
|
+
<% end -%>
|
9
|
+
|
10
|
+
# Uncomment below if timestamps were not included in your original model.
|
11
|
+
# t.timestamps
|
12
|
+
end
|
13
|
+
|
14
|
+
add_index :<%= table_name %>, :email, unique: true
|
15
|
+
add_index :<%= table_name %>, :reset_password_token, unique: true
|
16
|
+
# add_index :<%= table_name %>, :confirmation_token, unique: true
|
17
|
+
# add_index :<%= table_name %>, :unlock_token, unique: true
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.down
|
21
|
+
# By default, we don't want to make any assumption about how to roll back a migration when your
|
22
|
+
# model already existed. Please edit below which fields you would like to remove in this migration.
|
23
|
+
raise ActiveRecord::IrreversibleMigration
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'rails/generators/named_base'
|
2
|
+
|
3
|
+
module Devise
|
4
|
+
module Generators
|
5
|
+
class DeviseGenerator < Rails::Generators::NamedBase
|
6
|
+
include Rails::Generators::ResourceHelpers
|
7
|
+
|
8
|
+
namespace "devise"
|
9
|
+
source_root File.expand_path("../templates", __FILE__)
|
10
|
+
|
11
|
+
desc "Generates a model with the given NAME (if one does not exist) with devise " <<
|
12
|
+
"configuration plus a migration file and devise routes."
|
13
|
+
|
14
|
+
hook_for :orm
|
15
|
+
|
16
|
+
class_option :routes, desc: "Generate routes", type: :boolean, default: true
|
17
|
+
|
18
|
+
def add_devise_routes
|
19
|
+
devise_route = "devise_for :#{plural_name}"
|
20
|
+
devise_route << %Q(, class_name: "#{class_name}") if class_name.include?("::")
|
21
|
+
devise_route << %Q(, skip: :all) unless options.routes?
|
22
|
+
route devise_route
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'rails/generators/base'
|
2
|
+
require 'securerandom'
|
3
|
+
|
4
|
+
module Devise
|
5
|
+
module Generators
|
6
|
+
class InstallGenerator < Rails::Generators::Base
|
7
|
+
source_root File.expand_path("../../templates", __FILE__)
|
8
|
+
|
9
|
+
desc "Creates a Devise initializer and copy locale files to your application."
|
10
|
+
class_option :orm
|
11
|
+
|
12
|
+
def copy_initializer
|
13
|
+
template "devise.rb", "config/initializers/devise.rb"
|
14
|
+
end
|
15
|
+
|
16
|
+
def copy_locale
|
17
|
+
copy_file "../../../config/locales/en.yml", "config/locales/devise.en.yml"
|
18
|
+
end
|
19
|
+
|
20
|
+
def show_readme
|
21
|
+
readme "README" if behavior == :invoke
|
22
|
+
end
|
23
|
+
|
24
|
+
def rails_4?
|
25
|
+
Rails::VERSION::MAJOR == 4
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module Devise
|
2
|
+
module Generators
|
3
|
+
module OrmHelpers
|
4
|
+
def model_contents
|
5
|
+
buffer = <<-CONTENT
|
6
|
+
# Include default devise modules. Others available are:
|
7
|
+
# :confirmable, :lockable, :timeoutable and :omniauthable
|
8
|
+
devise :database_authenticatable, :registerable,
|
9
|
+
:recoverable, :rememberable, :trackable, :validatable
|
10
|
+
|
11
|
+
CONTENT
|
12
|
+
buffer += <<-CONTENT if needs_attr_accessible?
|
13
|
+
# Setup accessible (or protected) attributes for your model
|
14
|
+
attr_accessible :email, :password, :password_confirmation, :remember_me
|
15
|
+
|
16
|
+
CONTENT
|
17
|
+
buffer
|
18
|
+
end
|
19
|
+
|
20
|
+
def needs_attr_accessible?
|
21
|
+
rails_3? && !strong_parameters_enabled?
|
22
|
+
end
|
23
|
+
|
24
|
+
def rails_3?
|
25
|
+
Rails::VERSION::MAJOR == 3
|
26
|
+
end
|
27
|
+
|
28
|
+
def strong_parameters_enabled?
|
29
|
+
defined?(ActionController::StrongParameters)
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def model_exists?
|
35
|
+
File.exists?(File.join(destination_root, model_path))
|
36
|
+
end
|
37
|
+
|
38
|
+
def migration_exists?(table_name)
|
39
|
+
Dir.glob("#{File.join(destination_root, migration_path)}/[0-9]*_*.rb").grep(/\d+_add_devise_to_#{table_name}.rb$/).first
|
40
|
+
end
|
41
|
+
|
42
|
+
def migration_path
|
43
|
+
@migration_path ||= File.join("db", "migrate")
|
44
|
+
end
|
45
|
+
|
46
|
+
def model_path
|
47
|
+
@model_path ||= File.join("app", "models", "#{file_path}.rb")
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,135 @@
|
|
1
|
+
require 'rails/generators/base'
|
2
|
+
|
3
|
+
module Devise
|
4
|
+
module Generators
|
5
|
+
# Include this module in your generator to generate Devise views.
|
6
|
+
# `copy_views` is the main method and by default copies all views
|
7
|
+
# with forms.
|
8
|
+
module ViewPathTemplates #:nodoc:
|
9
|
+
extend ActiveSupport::Concern
|
10
|
+
|
11
|
+
included do
|
12
|
+
argument :scope, required: false, default: nil,
|
13
|
+
desc: "The scope to copy views to"
|
14
|
+
|
15
|
+
# Le sigh, ensure Thor won't handle opts as args
|
16
|
+
# It should be fixed in future Rails releases
|
17
|
+
class_option :form_builder, aliases: "-b"
|
18
|
+
class_option :markerb
|
19
|
+
class_option :views, aliases: "-v", type: :array, desc: "Select specific view directories to generate (confirmations, passwords, registrations, sessions, unlocks, mailer)"
|
20
|
+
|
21
|
+
public_task :copy_views
|
22
|
+
end
|
23
|
+
|
24
|
+
# TODO: Add this to Rails itself
|
25
|
+
module ClassMethods
|
26
|
+
def hide!
|
27
|
+
Rails::Generators.hide_namespace self.namespace
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def copy_views
|
32
|
+
if options[:views]
|
33
|
+
options[:views].each do |directory|
|
34
|
+
view_directory directory.to_sym
|
35
|
+
end
|
36
|
+
else
|
37
|
+
view_directory :confirmations
|
38
|
+
view_directory :passwords
|
39
|
+
view_directory :registrations
|
40
|
+
view_directory :sessions
|
41
|
+
view_directory :unlocks
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
protected
|
46
|
+
|
47
|
+
def view_directory(name, _target_path = nil)
|
48
|
+
directory name.to_s, _target_path || "#{target_path}/#{name}" do |content|
|
49
|
+
if scope
|
50
|
+
content.gsub "devise/shared/links", "#{scope}/shared/links"
|
51
|
+
else
|
52
|
+
content
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def target_path
|
58
|
+
@target_path ||= "app/views/#{scope || :devise}"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
class SharedViewsGenerator < Rails::Generators::Base #:nodoc:
|
63
|
+
include ViewPathTemplates
|
64
|
+
source_root File.expand_path("../../../../app/views/devise", __FILE__)
|
65
|
+
desc "Copies shared Devise views to your application."
|
66
|
+
hide!
|
67
|
+
|
68
|
+
# Override copy_views to just copy mailer and shared.
|
69
|
+
def copy_views
|
70
|
+
view_directory :shared
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
class FormForGenerator < Rails::Generators::Base #:nodoc:
|
75
|
+
include ViewPathTemplates
|
76
|
+
source_root File.expand_path("../../../../app/views/devise", __FILE__)
|
77
|
+
desc "Copies default Devise views to your application."
|
78
|
+
hide!
|
79
|
+
end
|
80
|
+
|
81
|
+
class SimpleFormForGenerator < Rails::Generators::Base #:nodoc:
|
82
|
+
include ViewPathTemplates
|
83
|
+
source_root File.expand_path("../../templates/simple_form_for", __FILE__)
|
84
|
+
desc "Copies simple form enabled views to your application."
|
85
|
+
hide!
|
86
|
+
end
|
87
|
+
|
88
|
+
class ErbGenerator < Rails::Generators::Base #:nodoc:
|
89
|
+
include ViewPathTemplates
|
90
|
+
source_root File.expand_path("../../../../app/views/devise", __FILE__)
|
91
|
+
desc "Copies Devise mail erb views to your application."
|
92
|
+
hide!
|
93
|
+
|
94
|
+
def copy_views
|
95
|
+
if !options[:views] || options[:views].include?('mailer')
|
96
|
+
view_directory :mailer
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
class MarkerbGenerator < Rails::Generators::Base #:nodoc:
|
102
|
+
include ViewPathTemplates
|
103
|
+
source_root File.expand_path("../../templates", __FILE__)
|
104
|
+
desc "Copies Devise mail markerb views to your application."
|
105
|
+
hide!
|
106
|
+
|
107
|
+
def copy_views
|
108
|
+
if !options[:views] || options[:views].include?('mailer')
|
109
|
+
view_directory :markerb, target_path
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
def target_path
|
114
|
+
"app/views/#{scope || :devise}/mailer"
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
class ViewsGenerator < Rails::Generators::Base
|
119
|
+
desc "Copies Devise views to your application."
|
120
|
+
|
121
|
+
argument :scope, required: false, default: nil,
|
122
|
+
desc: "The scope to copy views to"
|
123
|
+
|
124
|
+
invoke SharedViewsGenerator
|
125
|
+
|
126
|
+
hook_for :form_builder, aliases: "-b",
|
127
|
+
desc: "Form builder to be used",
|
128
|
+
default: defined?(SimpleForm) ? "simple_form_for" : "form_for"
|
129
|
+
|
130
|
+
hook_for :markerb, desc: "Generate markerb instead of erb mail views",
|
131
|
+
default: defined?(Markerb) ? :markerb : :erb,
|
132
|
+
type: :boolean
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'rails/generators/named_base'
|
2
|
+
require 'generators/devise/orm_helpers'
|
3
|
+
|
4
|
+
module Mongoid
|
5
|
+
module Generators
|
6
|
+
class DeviseGenerator < Rails::Generators::NamedBase
|
7
|
+
include Devise::Generators::OrmHelpers
|
8
|
+
|
9
|
+
def generate_model
|
10
|
+
invoke "mongoid:model", [name] unless model_exists? && behavior == :invoke
|
11
|
+
end
|
12
|
+
|
13
|
+
def inject_field_types
|
14
|
+
inject_into_file model_path, migration_data, after: "include Mongoid::Document\n" if model_exists?
|
15
|
+
end
|
16
|
+
|
17
|
+
def inject_devise_content
|
18
|
+
inject_into_file model_path, model_contents, after: "include Mongoid::Document\n" if model_exists?
|
19
|
+
end
|
20
|
+
|
21
|
+
def migration_data
|
22
|
+
<<RUBY
|
23
|
+
## Database authenticatable
|
24
|
+
field :email, type: String, default: ""
|
25
|
+
field :encrypted_password, type: String, default: ""
|
26
|
+
|
27
|
+
## Recoverable
|
28
|
+
field :reset_password_token, type: String
|
29
|
+
field :reset_password_sent_at, type: Time
|
30
|
+
|
31
|
+
## Rememberable
|
32
|
+
field :remember_created_at, type: Time
|
33
|
+
|
34
|
+
## Trackable
|
35
|
+
field :sign_in_count, type: Integer, default: 0
|
36
|
+
field :current_sign_in_at, type: Time
|
37
|
+
field :last_sign_in_at, type: Time
|
38
|
+
field :current_sign_in_ip, type: String
|
39
|
+
field :last_sign_in_ip, type: String
|
40
|
+
|
41
|
+
## Confirmable
|
42
|
+
# field :confirmation_token, type: String
|
43
|
+
# field :confirmed_at, type: Time
|
44
|
+
# field :confirmation_sent_at, type: Time
|
45
|
+
# field :unconfirmed_email, type: String # Only if using reconfirmable
|
46
|
+
|
47
|
+
## Lockable
|
48
|
+
# field :failed_attempts, type: Integer, default: 0 # Only if lock strategy is :failed_attempts
|
49
|
+
# field :unlock_token, type: String # Only if unlock strategy is :email or :both
|
50
|
+
# field :locked_at, type: Time
|
51
|
+
RUBY
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
===============================================================================
|
2
|
+
|
3
|
+
Some setup you must do manually if you haven't yet:
|
4
|
+
|
5
|
+
1. Ensure you have defined default url options in your environments files. Here
|
6
|
+
is an example of default_url_options appropriate for a development environment
|
7
|
+
in config/environments/development.rb:
|
8
|
+
|
9
|
+
config.action_mailer.default_url_options = { host: 'localhost:3000' }
|
10
|
+
|
11
|
+
In production, :host should be set to the actual host of your application.
|
12
|
+
|
13
|
+
2. Ensure you have defined root_url to *something* in your config/routes.rb.
|
14
|
+
For example:
|
15
|
+
|
16
|
+
root to: "home#index"
|
17
|
+
|
18
|
+
3. Ensure you have flash messages in app/views/layouts/application.html.erb.
|
19
|
+
For example:
|
20
|
+
|
21
|
+
<p class="notice"><%= notice %></p>
|
22
|
+
<p class="alert"><%= alert %></p>
|
23
|
+
|
24
|
+
4. If you are deploying on Heroku with Rails 3.2 only, you may want to set:
|
25
|
+
|
26
|
+
config.assets.initialize_on_precompile = false
|
27
|
+
|
28
|
+
On config/application.rb forcing your application to not access the DB
|
29
|
+
or load models when precompiling your assets.
|
30
|
+
|
31
|
+
5. You can copy Devise views (for customization) to your app by running:
|
32
|
+
|
33
|
+
rails g devise:views
|
34
|
+
|
35
|
+
===============================================================================
|