Class: Sprangular::InstallGenerator

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

Instance Method Summary collapse

Instance Method Details

#add_assetsObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/generators/sprangular/install/install_generator.rb', line 33

def add_assets
  inject_into_file 'app/assets/stylesheets/application.css', " *= require sprangular\n", before: /\*\//, verbose: true
  append_file 'app/assets/javascripts/application.js', "//= require jquery\n//= require bootstrap-sass-official\n//= require sprangular\n//= require sprangular/host\n//= require sprangular/extraRoutes\n//= require_tree ./sprangular/controllers\n//= require_tree ./sprangular/services\n"

  template 'host.coffee',        'app/assets/javascripts/sprangular/host.coffee'
  template 'extraRoutes.coffee', 'app/assets/javascripts/sprangular/extraRoutes.coffee'

  create_file 'app/assets/javascripts/sprangular/controllers/.keep', ''
  create_file 'app/assets/javascripts/sprangular/services/.keep', ''

  copy_file 'about.html.slim',    'app/assets/templates/static/about.html.slim'
  copy_file 'terms.html.slim',    'app/assets/templates/static/terms.html.slim'
  copy_file 'privacy.html.slim',  'app/assets/templates/static/privacy.html.slim'
end

#add_layoutObject



56
57
58
# File 'lib/generators/sprangular/install/install_generator.rb', line 56

def add_layout
  template 'layout.slim', 'app/views/layouts/sprangular/application.slim'
end

#add_migrationsObject



66
67
68
# File 'lib/generators/sprangular/install/install_generator.rb', line 66

def add_migrations
  run 'bundle exec rake railties:install:migrations FROM=sprangular_engine'
end

#add_routesObject



15
16
17
18
# File 'lib/generators/sprangular/install/install_generator.rb', line 15

def add_routes
  route "mount Sprangular::Engine  => '/'"
  route "mount Spree::Core::Engine => '/spree'"
end

#copy_templatesObject



60
61
62
63
64
# File 'lib/generators/sprangular/install/install_generator.rb', line 60

def copy_templates
  if options["copy_templates"]
    directory "../../../../../app/assets/templates", "app/assets/templates"
  end
end

#remove_assetsObject



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

def remove_assets
  run "rm -rf vendor/assets/images/spree/frontend"
  run "rm -rf vendor/assets/javascripts/spree/frontend"
  run "rm -rf vendor/assets/stylesheets/spree/frontend"
end

#remove_spree_core_engine_routeObject



11
12
13
# File 'lib/generators/sprangular/install/install_generator.rb', line 11

def remove_spree_core_engine_route
  gsub_file 'config/routes.rb', /^.*Spree::Core::Engine.*\n/, ''
end

#remove_spree_umbrella_gemObject



7
8
9
# File 'lib/generators/sprangular/install/install_generator.rb', line 7

def remove_spree_umbrella_gem
  gsub_file 'Gemfile', /^.*gem.["']spree["'].*\n/, ''
end

#remove_uneeded_jsObject



26
27
28
29
30
31
# File 'lib/generators/sprangular/install/install_generator.rb', line 26

def remove_uneeded_js
  gsub_file 'app/assets/javascripts/application.js', %r{//= require jquery\n}, ''
  gsub_file 'app/assets/javascripts/application.js', %r{//= require jquery_ujs\n}, ''
  gsub_file 'app/assets/javascripts/application.js', %r{//= require turbolinks\n}, ''
  gsub_file 'app/assets/javascripts/application.js', %r{//= require_tree .\n}, ''
end

#run_migrationsObject



70
71
72
73
74
75
76
77
78
# File 'lib/generators/sprangular/install/install_generator.rb', line 70

def run_migrations
  run_migrations = options[:auto_run_migrations] || ['', 'y', 'Y'].include?(ask 'Would you like to run the migrations now? [Y/n]')

  if run_migrations
    run 'bundle exec rake db:migrate'
  else
    puts 'Skipping rake db:migrate, don\'t forget to run it!'
  end
end