Class: Locomotive::InstallGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/locomotive/install/install_generator.rb

Instance Method Summary collapse

Instance Method Details

#copy_initializersObject


8
9
10
11
12
13
14
15
16
# File 'lib/generators/locomotive/install/install_generator.rb', line 8

def copy_initializers
  @source_paths = nil # reset it for the find_in_source_paths method

  Locomotive::InstallGenerator.source_root(File.expand_path('../templates', __FILE__))

  template 'locomotive.rb', 'config/initializers/locomotive.rb'

  template 'dragonfly.rb', 'config/initializers/dragonfly.rb'
end

#enable_herokuObject


53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/generators/locomotive/install/install_generator.rb', line 53

def enable_heroku
  if options.heroku?
    inject_into_file 'Gemfile', after: "source 'https://rubygems.org'\n" do <<-'RUBY'

if ENV['HEROKU_APP_NAME']
  ruby '2.6.2'
end
    RUBY
    end

    template 'heroku.rb', 'config/initializers/heroku.rb'
    template 'mongoid_heroku.yml', 'config/mongoid.yml', force: true

    inject_into_file 'config/environments/production.rb', after: "  # config.action_mailer.raise_delivery_errors = false\n" do <<-'RUBY'
  config.action_mailer.raise_delivery_errors  = true
  config.action_mailer.delivery_method        = :smtp
  config.action_mailer.smtp_settings          = {
:address        => 'smtp.sendgrid.net',
:port           => 25,
:authentication => :plain,
:user_name      => ENV['SENDGRID_USERNAME'],
:password       => ENV['SENDGRID_PASSWORD'],
:domain         => ENV['SENDGRID_DOMAIN']
}
    RUBY
    end

    gem 'platform-api', '~> 2.2.0'
  end
end

#insert_engine_routesObject


41
42
43
44
45
46
47
48
49
50
51
# File 'lib/generators/locomotive/install/install_generator.rb', line 41

def insert_engine_routes
  route %(
  # Locomotive Back-office
  mount Locomotive::Engine => '/locomotive', as: 'locomotive' # you can change the value of the path, by default set to "/locomotive"

  # Locomotive API
  mount Locomotive::API.to_app => '/locomotive(/:site_handle)/api'

  # Render site
  mount Locomotive::Steam.to_app => '/', anchor: false)
end

#install_awsObject


18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/generators/locomotive/install/install_generator.rb', line 18

def install_aws
  if options.heroku? || yes?('Do you want to store your assets on Amazon S3?')
    template 'carrierwave_aws.rb', 'config/initializers/carrierwave.rb'
    gem 'carrierwave-aws'
    gem 'rack-cors', require: 'rack/cors'
    inject_into_file 'Gemfile', after: "# the framework and any gems in your application.\n" do <<-RUBY

config.assets.initialize_on_precompile = false

config.middleware.insert_before ActionDispatch::Static, Rack::Cors do
  allow do
    origins '*'
    resource '/assets/*', headers: :any, methods: :any
  end
end

    RUBY
    end
  else
    template 'carrierwave.rb', 'config/initializers/carrierwave.rb'
  end
end

#remove_index_htmlObject


84
85
86
# File 'lib/generators/locomotive/install/install_generator.rb', line 84

def remove_index_html
  remove_file 'public/index.html'
end

#remove_robots_txtObject


88
89
90
# File 'lib/generators/locomotive/install/install_generator.rb', line 88

def remove_robots_txt
  remove_file 'public/robots.txt'
end

#show_readmeObject


92
93
94
# File 'lib/generators/locomotive/install/install_generator.rb', line 92

def show_readme
  readme 'README'
end