forked from heartcombo/devise
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update generators to use Rails 3 syntax, i.e devise:install instead o…
…f devise_install.
- Loading branch information
Showing
14 changed files
with
181 additions
and
175 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
require 'rails/generators/migration' | ||
|
||
module Devise | ||
module Generators | ||
class DeviseGenerator < Rails::Generators::NamedBase | ||
include Rails::Generators::Migration | ||
|
||
source_root File.expand_path("../templates", __FILE__) | ||
|
||
desc "Generates a model with the given NAME (if one does not exist) with devise " << | ||
"configuration plus a migration file and devise routes." | ||
|
||
def self.orm_has_migration? | ||
Rails::Generators.options[:rails][:orm] == :active_record | ||
end | ||
|
||
def self.next_migration_number(path) | ||
Time.now.utc.strftime("%Y%m%d%H%M%S") | ||
end | ||
|
||
class_option :orm | ||
class_option :migration, :type => :boolean, :default => orm_has_migration? | ||
|
||
def invoke_orm_model | ||
if model_exists? | ||
say "* Model already exists. Adding Devise behavior." | ||
elsif options[:orm].present? | ||
invoke "model", [name], :migration => false, :orm => options[:orm] | ||
|
||
unless model_exists? | ||
abort "Tried to invoke the model generator for '#{options[:orm]}' but could not find it.\n" << | ||
"Please create your model by hand before calling `rails g devise #{name}`." | ||
end | ||
else | ||
abort "Cannot create a devise model because config.generators.orm is blank.\n" << | ||
"Please create your model by hand or configure your generators orm before calling `rails g devise #{name}`." | ||
end | ||
end | ||
|
||
def inject_devise_config_into_model | ||
devise_class_setup = <<-CONTENT | ||
# Include default devise modules. Others available are: | ||
# :token_authenticatable, :confirmable, :lockable and :timeoutable | ||
devise :database_authenticatable, :registerable, | ||
:recoverable, :rememberable, :trackable, :validatable | ||
CONTENT | ||
|
||
case options[:orm].to_s | ||
when "mongoid" | ||
inject_into_file model_path, devise_class_setup, :after => "include Mongoid::Document\n" | ||
when "data_mapper" | ||
inject_into_file model_path, devise_class_setup, :after => "include DataMapper::Resource\n" | ||
when "active_record" | ||
inject_into_class model_path, class_name, devise_class_setup + <<-CONTENT | ||
# Setup accessible (or protected) attributes for your model | ||
attr_accessible :email, :password, :password_confirmation | ||
CONTENT | ||
end | ||
end | ||
|
||
def copy_migration_template | ||
return unless options.migration? | ||
migration_template "migration.rb", "db/migrate/devise_create_#{table_name}" | ||
end | ||
|
||
def add_devise_routes | ||
route "devise_for :#{table_name}" | ||
end | ||
|
||
protected | ||
|
||
def model_exists? | ||
File.exists?(File.join(destination_root, model_path)) | ||
end | ||
|
||
def model_path | ||
@model_path ||= File.join("app", "models", "#{file_path}.rb") | ||
end | ||
end | ||
end | ||
end |
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
require 'active_support/secure_random' | ||
|
||
module Devise | ||
module Generators | ||
class InstallGenerator < Rails::Generators::Base | ||
source_root File.expand_path("../templates", __FILE__) | ||
|
||
desc "Creates a Devise initializer and copy locale files to your application." | ||
class_option :orm | ||
|
||
def copy_initializer | ||
template "devise.rb", "config/initializers/devise.rb" | ||
end | ||
|
||
def copy_locale | ||
copy_file "../../../../../config/locales/en.yml", "config/locales/devise.en.yml" | ||
end | ||
|
||
def show_readme | ||
readme "README" | ||
end | ||
end | ||
end | ||
end |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
module Devise | ||
module Generators | ||
class ViewsGenerator < Rails::Generators::Base | ||
source_root File.expand_path("../../../../../app/views", __FILE__) | ||
desc "Copies all Devise views to your application." | ||
|
||
argument :scope, :required => false, :default => nil, | ||
:desc => "The scope to copy views to" | ||
|
||
class_option :template_engine, :type => :string, :aliases => "-t", :default => "erb", | ||
:desc => "Template engine for the views. Available options are 'erb' and 'haml'." | ||
|
||
def copy_views | ||
case options[:template_engine] | ||
when "haml" | ||
verify_haml_existence | ||
verify_haml_version | ||
create_and_copy_haml_views | ||
else | ||
directory "devise", "app/views/#{scope || :devise}" | ||
end | ||
end | ||
|
||
protected | ||
|
||
def verify_haml_existence | ||
begin | ||
require 'haml' | ||
rescue LoadError | ||
say "HAML is not installed, or it is not specified in your Gemfile." | ||
exit | ||
end | ||
end | ||
|
||
def verify_haml_version | ||
unless Haml.version[:major] == 2 and Haml.version[:minor] >= 3 or Haml.version[:major] >= 3 | ||
say "To generate HAML templates, you need to install HAML 2.3 or above." | ||
exit | ||
end | ||
end | ||
|
||
def create_and_copy_haml_views | ||
require 'tmpdir' | ||
html_root = "#{self.class.source_root}/devise" | ||
|
||
Dir.mktmpdir("devise-haml.") do |haml_root| | ||
Dir["#{html_root}/**/*"].each do |path| | ||
relative_path = path.sub(html_root, "") | ||
source_path = (haml_root + relative_path).sub(/erb$/, "haml") | ||
|
||
if File.directory?(path) | ||
FileUtils.mkdir_p(source_path) | ||
else | ||
`html2haml -r #{path} #{source_path}` | ||
end | ||
end | ||
|
||
directory haml_root, "app/views/#{scope || :devise}" | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Remove this file on next rails release | ||
require "generators/devise/devise/devise_generator" |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Remove this file after deprecation | ||
warn "[WARNING] `rails g devise_install` is deprecated, please use `rails g devise:install` instead." |
Oops, something went wrong.