class Spree::InstallGenerator
Public Class Methods
source_paths()
click to toggle source
# File lib/generators/spree/install/install_generator.rb, line 22 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', __dir__) paths.flatten end
Public Instance Methods
add_files()
click to toggle source
# File lib/generators/spree/install/install_generator.rb, line 43 def add_files template 'config/initializers/spree.rb', 'config/initializers/spree.rb' end
additional_tweaks()
click to toggle source
# File lib/generators/spree/install/install_generator.rb, line 47 def additional_tweaks return unless File.exist? 'public/robots.txt' append_file 'public/robots.txt', <<-ROBOTS.strip_heredoc User-agent: * Disallow: /checkout Disallow: /cart Disallow: /orders Disallow: /user Disallow: /account Disallow: /api Disallow: /password Disallow: /api_tokens Disallow: /cart_link Disallow: /account_link ROBOTS end
complete()
click to toggle source
# File lib/generators/spree/install/install_generator.rb, line 224 def complete unless options[:quiet] puts '*' * 50 puts "Spree has been installed successfully. You're all ready to go!" puts ' ' puts 'Enjoy!' end end
configure_application()
click to toggle source
# File lib/generators/spree/install/install_generator.rb, line 103 def configure_application application <<-APP.strip_heredoc.indent!(4) 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 unless options[:enforce_available_locales].nil? application <<-APP.strip_heredoc.indent!(4) # Prevent this deprecation message: https://github.com/svenfuchs/i18n/commit/3b6e56e I18n.enforce_available_locales = #{options[:enforce_available_locales]} APP end end
copy_storefront()
click to toggle source
# File lib/generators/spree/install/install_generator.rb, line 97 def copy_storefront if @copy_storefront && Spree::Core::Engine.frontend_available? generate 'spree:frontend:copy_storefront' end end
create_database()
click to toggle source
# File lib/generators/spree/install/install_generator.rb, line 142 def create_database say_status :creating, 'database' silence_stream(STDOUT) do silence_stream(STDERR) do silence_warnings { rake 'db:create' } end end end
create_overrides_directory()
click to toggle source
# File lib/generators/spree/install/install_generator.rb, line 87 def create_overrides_directory empty_directory 'app/overrides' end
include_seed_data()
click to toggle source
# File lib/generators/spree/install/install_generator.rb, line 127 def include_seed_data append_file 'db/seeds.rb', <<-SEEDS.strip_heredoc Spree::Core::Engine.load_seed if defined?(Spree::Core) Spree::Auth::Engine.load_seed if defined?(Spree::Auth) SEEDS end
install_migrations()
click to toggle source
# File lib/generators/spree/install/install_generator.rb, line 135 def install_migrations say_status :copying, 'migrations' silence_stream(STDOUT) do silence_warnings { rake 'railties:install:migrations' } end end
install_storefront()
click to toggle source
# File lib/generators/spree/install/install_generator.rb, line 91 def install_storefront if @install_storefront && Spree::Core::Engine.frontend_available? generate 'spree:frontend:install' end end
load_sample_data()
click to toggle source
# File lib/generators/spree/install/install_generator.rb, line 187 def load_sample_data if @load_sample_data say_status :loading, 'sample data' silence_stream(STDOUT) do silence_stream(STDERR) do silence_warnings { rake 'spree_sample:load' } end end else say_status :skipping, 'sample data (you can always run rake spree_sample:load)' end end
notify_about_routes()
click to toggle source
# File lib/generators/spree/install/install_generator.rb, line 200 def notify_about_routes insert_into_file(File.join('config', 'routes.rb'), after: "Rails.application.routes.draw do\n") do <<-ROUTES.strip_heredoc.indent!(2) # This line mounts Spree'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 Spree 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
populate_seed_data()
click to toggle source
# File lib/generators/spree/install/install_generator.rb, line 164 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] cmd = -> { rake("db:seed #{rake_options.join(' ')}") } if options[:auto_accept] || (options[:admin_email] && options[:admin_password]) silence_stream(STDOUT) do silence_stream(STDERR) do silence_warnings &cmd end end else cmd.call end else say_status :skipping, 'seed data (you can always run rake db:seed)' end end
prepare_options()
click to toggle source
# File lib/generators/spree/install/install_generator.rb, line 30 def prepare_options @run_migrations = options[:migrate] @load_seed_data = options[:seed] @load_sample_data = options[:sample] @install_storefront = options[:install_storefront] @copy_storefront = options[:copy_storefront] unless @run_migrations @load_seed_data = false @load_sample_data = false end end
run_migrations()
click to toggle source
# File lib/generators/spree/install/install_generator.rb, line 151 def run_migrations if @run_migrations say_status :running, 'migrations' silence_stream(STDOUT) do silence_stream(STDERR) do silence_warnings { rake 'db:migrate' } end end else say_status :skipping, "migrations (don't forget to run rake db:migrate)" end end
setup_assets()
click to toggle source
# File lib/generators/spree/install/install_generator.rb, line 65 def setup_assets @lib_name = 'spree' %w{javascripts stylesheets images}.each do |path| if Spree::Core::Engine.frontend_available? || Rails.env.test? empty_directory "vendor/assets/#{path}/spree/frontend" end if Spree::Core::Engine.backend_available? || Rails.env.test? empty_directory "vendor/assets/#{path}/spree/backend" end end if Spree::Core::Engine.frontend_available? || Rails.env.test? template 'vendor/assets/javascripts/spree/frontend/all.js' template 'vendor/assets/stylesheets/spree/frontend/all.css' end if Spree::Core::Engine.backend_available? || Rails.env.test? template 'vendor/assets/javascripts/spree/backend/all.js' template 'vendor/assets/stylesheets/spree/backend/all.css' end end
Protected Instance Methods
file_exists?(extensions, filename)
click to toggle source
# File lib/generators/spree/install/install_generator.rb, line 245 def file_exists?(extensions, filename) extensions.detect do |extension| File.exist?("#{filename}#{extension}") end end
javascript_exists?(script)
click to toggle source
# File lib/generators/spree/install/install_generator.rb, line 235 def javascript_exists?(script) extensions = %w(.js.coffee .js.erb .js.coffee.erb .js) file_exists?(extensions, script) end
stylesheet_exists?(stylesheet)
click to toggle source
# File lib/generators/spree/install/install_generator.rb, line 240 def stylesheet_exists?(stylesheet) extensions = %w(.css.scss .css.erb .css.scss.erb .css) file_exists?(extensions, stylesheet) end
Private Instance Methods
silence_stream(stream) { || ... }
click to toggle source
# File lib/generators/spree/install/install_generator.rb, line 253 def silence_stream(stream) old_stream = stream.dup stream.reopen(RbConfig::CONFIG['host_os'] =~ /mswin|mingw/ ? 'NUL:' : '/dev/null') stream.sync = true yield ensure stream.reopen(old_stream) old_stream.close end