Class: HappySeed::Generators::DeviseGenerator

Inherits:
HappySeedGenerator
  • Object
show all
Defined in:
lib/generators/happy_seed/devise/devise_generator.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.fingerprintObject



10
11
12
# File 'lib/generators/happy_seed/devise/devise_generator.rb', line 10

def self.fingerprint
  gem_available? 'devise'
end

Instance Method Details

#install_deviseObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/generators/happy_seed/devise/devise_generator.rb', line 14

def install_devise
  return if already_installed

  require_generator BootstrapGenerator
  require_generator HtmlEmailGenerator

  gem 'devise', '~> 4.2'

  Bundler.with_clean_env do
    run "bundle install --without production"
  end

  run 'bin/spring stop'

  Bundler.with_clean_env do
    run 'rails generate devise:install'
    run 'rails generate devise User'
    run 'rails generate devise:views'
  end

  if gem_available?( "haml-rails" )
    remove_file 'app/views/devise/registrations/new.html.erb'
    remove_file 'app/views/devise/registrations/edit.html.erb'
    remove_file 'app/views/devise/sessions/new.html.erb'
    remove_file 'app/views/devise/passwords/edit.html.erb'
    remove_file 'app/views/devise/passwords/new.html.erb'
  end

  remove_file 'app/views/devise/mailer/reset_password_instructions.html.erb'
  remove_file 'app/views/devise/mailer/confirmation_instructions.html.erb'
  
  remove_file "spec/factories/users.rb"
  
  begin
    prepend_to_file 'spec/spec_helper.rb', "require 'devise'\n"
  rescue
    say_status :spec, "Unable to add devise helpers to spec_helper.rb", :red
  end

  directory 'app'
  directory 'docs'
  # directory 'test'
  directory 'spec'

  application(nil, env: "development") do
    "config.action_mailer.default_url_options = { host: 'localhost:3000' }"
  end

  application(nil, env: "test") do
    "config.action_mailer.default_url_options = { host: 'localhost:3000' }"
  end

  if File.exists?( File.join( destination_root, 'app/views/application/_header.html.haml' ) )
    gsub_file 'app/views/application/_header.html.haml', "/ USER NAV", '= render partial: "application/account_dropdown"'
  else
    say_status :gsub_file, "Can't find application/_header.html.haml, skipping"
  end

  gsub_file "config/initializers/devise.rb", "# config.parent_mailer = 'ActionMailer::Base'", "config.parent_mailer = 'ApplicationMailer'"

  gsub_file 'config/routes.rb', "devise_for :users", "devise_for :users, :controllers => { }"
end