Class: Spree::InstallGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Spree::InstallGenerator
- Defined in:
- lib/generators/spree/install/install_generator.rb
Constant Summary collapse
- CORE_MOUNT_ROUTE =
"mount Spree::Core::Engine"
Class Method Summary collapse
Instance Method Summary collapse
- #add_files ⇒ Object
- #additional_tweaks ⇒ Object
- #complete ⇒ Object
- #configure_application ⇒ Object
- #create_database ⇒ Object
- #create_overrides_directory ⇒ Object
- #include_seed_data ⇒ Object
- #install_migrations ⇒ Object
- #install_routes ⇒ Object
- #load_sample_data ⇒ Object
- #populate_seed_data ⇒ Object
- #prepare_options ⇒ Object
- #run_migrations ⇒ Object
- #setup_assets ⇒ Object
Class Method Details
.source_paths ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/generators/spree/install/install_generator.rb', line 22 def self.source_paths paths = superclass.source_paths paths << File.('../templates', "../../#{__FILE__}") paths << File.('../templates', "../#{__FILE__}") paths << File.('templates', __dir__) paths.flatten end |
Instance Method Details
#add_files ⇒ Object
41 42 43 |
# File 'lib/generators/spree/install/install_generator.rb', line 41 def add_files template 'config/initializers/spree.rb.tt', 'config/initializers/spree.rb' end |
#additional_tweaks ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/generators/spree/install/install_generator.rb', line 45 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 ROBOTS end |
#complete ⇒ Object
188 189 190 191 192 193 194 195 |
# File 'lib/generators/spree/install/install_generator.rb', line 188 def complete unless [:quiet] puts "*" * 50 puts "Solidus has been installed successfully. You're all ready to go!" puts " " puts "Enjoy!" end end |
#configure_application ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/generators/spree/install/install_generator.rb', line 84 def configure_application application <<-RUBY # Load application's model / class decorators initializer 'spree.decorators' do |app| config.to_prepare do Dir.glob(Rails.root.join('app/**/*_decorator*.rb')) do |path| require_dependency(path) end end end # Load application's view overrides initializer 'spree.overrides' do |app| config.to_prepare do Dir.glob(Rails.root.join('app/overrides/*.rb')) do |path| require_dependency(path) end end end RUBY if ![:enforce_available_locales].nil? application <<-RUBY # Prevent this deprecation message: https://github.com/svenfuchs/i18n/commit/3b6e56e I18n.enforce_available_locales = #{[:enforce_available_locales]} RUBY end end |
#create_database ⇒ Object
126 127 128 129 |
# File 'lib/generators/spree/install/install_generator.rb', line 126 def create_database say_status :creating, "database" rake 'db:create' end |
#create_overrides_directory ⇒ Object
80 81 82 |
# File 'lib/generators/spree/install/install_generator.rb', line 80 def create_overrides_directory empty_directory "app/overrides" end |
#include_seed_data ⇒ Object
113 114 115 116 117 118 119 |
# File 'lib/generators/spree/install/install_generator.rb', line 113 def include_seed_data append_file "db/seeds.rb", <<-RUBY.strip_heredoc Spree::Core::Engine.load_seed if defined?(Spree::Core) Spree::Auth::Engine.load_seed if defined?(Spree::Auth) RUBY end |
#install_migrations ⇒ Object
121 122 123 124 |
# File 'lib/generators/spree/install/install_generator.rb', line 121 def install_migrations say_status :copying, "migrations" `rake railties:install:migrations` end |
#install_routes ⇒ Object
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
# File 'lib/generators/spree/install/install_generator.rb', line 164 def install_routes routes_file_path = File.join('config', 'routes.rb') unless File.read(routes_file_path).include? CORE_MOUNT_ROUTE insert_into_file routes_file_path, after: "Rails.application.routes.draw do\n" do <<-RUBY # 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" #{CORE_MOUNT_ROUTE}, at: '/' RUBY end end unless [:quiet] puts "*" * 50 puts "We added the following line to your application's config/routes.rb file:" puts " " puts " #{CORE_MOUNT_ROUTE}, at: '/'" end end |
#load_sample_data ⇒ Object
155 156 157 158 159 160 161 162 |
# File 'lib/generators/spree/install/install_generator.rb', line 155 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_data ⇒ Object
141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/generators/spree/install/install_generator.rb', line 141 def populate_seed_data if @load_seed_data say_status :loading, "seed data" = [] << "AUTO_ACCEPT=1" if [:auto_accept] << "ADMIN_EMAIL=#{[:admin_email]}" if [:admin_email] << "ADMIN_PASSWORD=#{[:admin_password]}" if [:admin_password] rake("db:seed #{.join(' ')}") else say_status :skipping, "seed data (you can always run rake db:seed)" end end |
#prepare_options ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/generators/spree/install/install_generator.rb', line 30 def @run_migrations = [:migrate] @load_seed_data = [:seed] @load_sample_data = [:sample] unless @run_migrations @load_seed_data = false @load_sample_data = false end end |
#run_migrations ⇒ Object
131 132 133 134 135 136 137 138 139 |
# File 'lib/generators/spree/install/install_generator.rb', line 131 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_assets ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/generators/spree/install/install_generator.rb', line 59 def setup_assets @lib_name = 'spree' empty_directory 'app/assets/images' %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 |