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


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

def self.source_paths
  paths = self.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


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

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

#additional_tweaksObject


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

def additional_tweaks
  return unless File.exists? 'public/robots.txt'
  append_file "public/robots.txt", "User-agent: *\nDisallow: /checkout\nDisallow: /cart\nDisallow: /orders\nDisallow: /countries\nDisallow: /line_items\nDisallow: /password_resets\nDisallow: /states\nDisallow: /user_sessions\nDisallow: /user_registrations\nDisallow: /users\nDisallow: /account\n"
end

#completeObject


190
191
192
193
194
195
196
197
# File 'lib/generators/spree/install/install_generator.rb', line 190

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

#config_spree_ymlObject


40
41
42
43
44
45
46
# File 'lib/generators/spree/install/install_generator.rb', line 40

def config_spree_yml
  create_file "config/spree.yml" do
    settings = { 'version' => Spree.version }

    settings.to_yaml
  end
end

#configure_applicationObject


92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/generators/spree/install/install_generator.rb', line 92

def configure_application
  application "\nconfig.to_prepare do\n# Load application's model / class decorators\nDir.glob(File.join(File.dirname(__FILE__), \"../app/**/*_decorator*.rb\")) do |c|\nRails.configuration.cache_classes ? require(c) : load(c)\nend\n\n# Load application's view overrides\nDir.glob(File.join(File.dirname(__FILE__), \"../app/overrides/*.rb\")) do |c|\nRails.configuration.cache_classes ? require(c) : load(c)\nend\nend\n"
end

#create_databaseObject


124
125
126
127
128
129
130
131
# File 'lib/generators/spree/install/install_generator.rb', line 124

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_directoryObject


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

def create_overrides_directory
  empty_directory "app/overrides"
end

#include_seed_dataObject


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

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

#install_migrationsObject


117
118
119
120
121
122
# File 'lib/generators/spree/install/install_generator.rb', line 117

def install_migrations
  say_status :copying, "migrations"
  silence_stream(STDOUT) do
    silence_warnings { rake 'railties:install:migrations' }
  end
end

#load_sample_dataObject


161
162
163
164
165
166
167
168
# File 'lib/generators/spree/install/install_generator.rb', line 161

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_routesObject


170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# File 'lib/generators/spree/install/install_generator.rb', line 170

def notify_about_routes
  insert_into_file File.join('config', 'routes.rb'), :after => "Application.routes.draw do\n" do
    %Q{
  # 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 => '/'
    }
  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_dataObject


142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'lib/generators/spree/install/install_generator.rb', line 142

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 = lambda { rake("db:seed #{rake_options.join(' ')}") }
    if options[:auto_accept] || (options[:admin_email] && options[:admin_password])
      quietly &cmd
    else
      cmd.call
    end
  else
    say_status :skipping, "seed data (you can always run rake db:seed)"
  end
end

#prepare_optionsObject


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

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

#remove_unneeded_filesObject


48
49
50
# File 'lib/generators/spree/install/install_generator.rb', line 48

def remove_unneeded_files
  remove_file "public/index.html"
end

#run_migrationsObject


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

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_assetsObject


70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/generators/spree/install/install_generator.rb', line 70

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

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

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