Class: Spree::InstallGenerator

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.source_pathsObject



18
19
20
21
22
23
24
# File 'lib/generators/spree/install/install_generator.rb', line 18

def self.source_paths
  paths = superclass.source_paths
  paths << File.expand_path('../templates', "../../#{__FILE__}")
  paths << File.expand_path('../templates', "../#{__FILE__}")
  paths << File.expand_path('../templates', __FILE__)
  paths.flatten
end

Instance Method Details

#add_filesObject



37
38
39
# File 'lib/generators/spree/install/install_generator.rb', line 37

def add_files
  template 'config/initializers/solidus.rb', 'config/initializers/solidus.rb'
end

#additional_tweaksObject



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

def additional_tweaks
  return unless File.exist? 'public/robots.txt'
  append_file "public/robots.txt", <<-ROBOTS
User-agent: *
Disallow: /checkout
Disallow: /cart
Disallow: /orders
Disallow: /user
Disallow: /account
Disallow: /api
Disallow: /password
  ROBOTS
end

#completeObject



173
174
175
176
177
178
179
180
# File 'lib/generators/spree/install/install_generator.rb', line 173

def complete
  unless options[:quiet]
    puts "*" * 50
    puts "Solidus has been installed successfully. You're all ready to go!"
    puts " "
    puts "Enjoy!"
  end
end

#configure_applicationObject



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/generators/spree/install/install_generator.rb', line 77

def configure_application
  application <<-APP

config.to_prepare do
  # Load application's model / class decorators
  Dir.glob(File.join(File.dirname(__FILE__), "../app/**/*_decorator*.rb")) do |c|
    Rails.configuration.cache_classes ? require(c) : load(c)
  end

  # Load application's view overrides
  Dir.glob(File.join(File.dirname(__FILE__), "../app/overrides/*.rb")) do |c|
    Rails.configuration.cache_classes ? require(c) : load(c)
  end
end
  APP

  if !options[:enforce_available_locales].nil?
    application <<-APP
# Prevent this deprecation message: https://github.com/svenfuchs/i18n/commit/3b6e56e
I18n.enforce_available_locales = #{options[:enforce_available_locales]}
    APP
  end
end

#create_databaseObject



114
115
116
117
# File 'lib/generators/spree/install/install_generator.rb', line 114

def create_database
  say_status :creating, "database"
  rake 'db:create'
end

#create_overrides_directoryObject



73
74
75
# File 'lib/generators/spree/install/install_generator.rb', line 73

def create_overrides_directory
  empty_directory "app/overrides"
end

#include_seed_dataObject



101
102
103
104
105
106
107
# File 'lib/generators/spree/install/install_generator.rb', line 101

def include_seed_data
  append_file "db/seeds.rb", <<-SEEDS
\n
Spree::Core::Engine.load_seed if defined?(Spree::Core)
Spree::Auth::Engine.load_seed if defined?(Spree::Auth)
  SEEDS
end

#install_migrationsObject



109
110
111
112
# File 'lib/generators/spree/install/install_generator.rb', line 109

def install_migrations
  say_status :copying, "migrations"
  `rake railties:install:migrations`
end

#install_routesObject



152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/generators/spree/install/install_generator.rb', line 152

def install_routes
  insert_into_file File.join('config', 'routes.rb'), after: "Rails.application.routes.draw do\n" do
    <<-ROUTES
  # This line mounts Solidus's routes at the root of your application.
  # This means, any requests to URLs such as /products, will go to Spree::ProductsController.
  # If you would like to change where this engine is mounted, simply change the :at option to something different.
  #
  # We ask that you don't use the :as option here, as Solidus relies on it being the default of "spree"
  mount Spree::Core::Engine, at: '/'

    ROUTES
  end

  unless options[:quiet]
    puts "*" * 50
    puts "We added the following line to your application's config/routes.rb file:"
    puts " "
    puts "    mount Spree::Core::Engine, at: '/'"
  end
end

#load_sample_dataObject



143
144
145
146
147
148
149
150
# File 'lib/generators/spree/install/install_generator.rb', line 143

def load_sample_data
  if @load_sample_data
    say_status :loading, "sample data"
    rake 'spree_sample:load'
  else
    say_status :skipping, "sample data (you can always run rake spree_sample:load)"
  end
end

#populate_seed_dataObject



129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/generators/spree/install/install_generator.rb', line 129

def populate_seed_data
  if @load_seed_data
    say_status :loading,  "seed data"
    rake_options = []
    rake_options << "AUTO_ACCEPT=1" if options[:auto_accept]
    rake_options << "ADMIN_EMAIL=#{options[:admin_email]}" if options[:admin_email]
    rake_options << "ADMIN_PASSWORD=#{options[:admin_password]}" if options[:admin_password]

    rake("db:seed #{rake_options.join(' ')}")
  else
    say_status :skipping, "seed data (you can always run rake db:seed)"
  end
end

#prepare_optionsObject



26
27
28
29
30
31
32
33
34
35
# File 'lib/generators/spree/install/install_generator.rb', line 26

def prepare_options
  @run_migrations = options[:migrate]
  @load_seed_data = options[:seed]
  @load_sample_data = options[:sample]

  unless @run_migrations
     @load_seed_data = false
     @load_sample_data = false
  end
end

#run_migrationsObject



119
120
121
122
123
124
125
126
127
# File 'lib/generators/spree/install/install_generator.rb', line 119

def run_migrations
  if @run_migrations
    say_status :running, "migrations"

    rake 'db:migrate VERBOSE=false'
  else
    say_status :skipping, "migrations (don't forget to run rake db:migrate)"
  end
end

#setup_assetsObject



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/generators/spree/install/install_generator.rb', line 55

def setup_assets
  @lib_name = 'spree'
  %w{javascripts stylesheets images}.each do |path|
    empty_directory "vendor/assets/#{path}/spree/frontend" if defined? Spree::Frontend || Rails.env.test?
    empty_directory "vendor/assets/#{path}/spree/backend" if defined? Spree::Backend || Rails.env.test?
  end

  if defined? Spree::Frontend || Rails.env.test?
    template "vendor/assets/javascripts/spree/frontend/all.js"
    template "vendor/assets/stylesheets/spree/frontend/all.css"
  end

  if defined? Spree::Backend || Rails.env.test?
    template "vendor/assets/javascripts/spree/backend/all.js"
    template "vendor/assets/stylesheets/spree/backend/all.css"
  end
end