Class: Spree::InstallGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Spree::InstallGenerator
- Defined in:
- lib/generators/spree/install/install_generator.rb
Class Method Summary collapse
Instance Method Summary collapse
- #add_files ⇒ Object
- #additional_tweaks ⇒ Object
- #complete ⇒ Object
- #config_spree_yml ⇒ Object
- #configure_application ⇒ Object
- #create_overrides_directory ⇒ Object
- #include_seed_data ⇒ Object
- #install_migrations ⇒ Object
- #load_sample_data ⇒ Object
- #notify_about_routes ⇒ Object
- #populate_seed_data ⇒ Object
- #prepare_options ⇒ Object
- #remove_unneeded_files ⇒ Object
- #run_migrations ⇒ Object
- #setup_assets ⇒ Object
Class Method Details
.source_paths ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/generators/spree/install/install_generator.rb', line 16 def self.source_paths paths = self.superclass.source_paths paths << File.('../templates', "../../#{__FILE__}") paths << File.('../templates', "../#{__FILE__}") paths << File.('../templates', __FILE__) paths.flatten end |
Instance Method Details
#add_files ⇒ Object
35 36 37 |
# File 'lib/generators/spree/install/install_generator.rb', line 35 def add_files template 'config/initializers/spree.rb', 'config/initializers/spree.rb' end |
#additional_tweaks ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/generators/spree/install/install_generator.rb', line 51 def additional_tweaks return unless File.exists? 'public/robots.txt' append_file "public/robots.txt", <<-ROBOTS User-agent: * Disallow: /checkouts Disallow: /orders Disallow: /countries Disallow: /line_items Disallow: /password_resets Disallow: /states Disallow: /user_sessions Disallow: /users ROBOTS end |
#complete ⇒ Object
167 168 169 170 171 172 173 174 |
# File 'lib/generators/spree/install/install_generator.rb', line 167 def complete unless [:quiet] puts "*" * 50 puts "Spree has been installed successfully. You're all ready to go!" puts " " puts "Enjoy!" end end |
#config_spree_yml ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/generators/spree/install/install_generator.rb', line 39 def config_spree_yml create_file "config/spree.yml" do settings = { 'version' => Spree.version } settings.to_yaml end end |
#configure_application ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/generators/spree/install/install_generator.rb', line 83 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 append_file "config/environment.rb", "\nActiveRecord::Base.include_root_in_json = true\n" end |
#create_overrides_directory ⇒ Object
79 80 81 |
# File 'lib/generators/spree/install/install_generator.rb', line 79 def create_overrides_directory empty_directory "app/overrides" end |
#include_seed_data ⇒ Object
102 103 104 105 106 107 108 |
# File 'lib/generators/spree/install/install_generator.rb', line 102 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_migrations ⇒ Object
110 111 112 113 114 115 |
# File 'lib/generators/spree/install/install_generator.rb', line 110 def install_migrations say_status :copying, "migrations" silence_stream(STDOUT) do silence_warnings { rake 'railties:install:migrations' } end end |
#load_sample_data ⇒ Object
145 146 147 148 149 150 151 152 |
# File 'lib/generators/spree/install/install_generator.rb', line 145 def load_sample_data if @load_sample_data say_status :loading, "sample data" quietly { rake 'spree_sample:load' } else say_status :skipping, "sample data (you can always run rake spree_sample:load)" end end |
#notify_about_routes ⇒ Object
154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/generators/spree/install/install_generator.rb', line 154 def notify_about_routes insert_into_file File.join('config', 'routes.rb'), :after => "Application.routes.draw do\n" do " # Mount Spree's routes\n mount Spree::Core::Engine, :at => '/'\n" end unless [: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 ⇒ Object
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/generators/spree/install/install_generator.rb', line 126 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] cmd = lambda { rake("db:seed #{.join(' ')}") } if [:auto_accept] || ([:admin_email] && [:admin_password]) quietly &cmd else cmd.call end else say_status :skipping, "seed data (you can always run rake db:seed)" end end |
#prepare_options ⇒ Object
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/generators/spree/install/install_generator.rb', line 24 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 |
#remove_unneeded_files ⇒ Object
47 48 49 |
# File 'lib/generators/spree/install/install_generator.rb', line 47 def remove_unneeded_files remove_file "public/index.html" end |
#run_migrations ⇒ Object
117 118 119 120 121 122 123 124 |
# File 'lib/generators/spree/install/install_generator.rb', line 117 def run_migrations if @run_migrations say_status :running, "migrations" quietly { rake 'db:migrate' } else say_status :skipping, "migrations (don't forget to run rake db:migrate)" end end |
#setup_assets ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/generators/spree/install/install_generator.rb', line 66 def setup_assets @lib_name = 'spree' %w{javascripts stylesheets images}.each do |path| empty_directory "app/assets/#{path}/store" empty_directory "app/assets/#{path}/admin" end template "app/assets/javascripts/store/all.js" template "app/assets/javascripts/admin/all.js" template "app/assets/stylesheets/store/all.css" template "app/assets/stylesheets/admin/all.css" end |