Class: Rsg::Generators::Webpacker::InstallGenerator

Inherits:
Base
  • Object
show all
Defined in:
lib/rsg/generators/webpacker/install_generator.rb

Instance Method Summary collapse

Instance Method Details

#add_webpackerObject



10
11
12
# File 'lib/rsg/generators/webpacker/install_generator.rb', line 10

def add_webpacker
  append_gem("webpacker", version: "~> 5.0")
end


6
7
8
# File 'lib/rsg/generators/webpacker/install_generator.rb', line 6

def banner
  say("Configuring webpacker")
end

#configure_jsObject



18
19
20
21
22
23
24
# File 'lib/rsg/generators/webpacker/install_generator.rb', line 18

def configure_js
  copy_file "application.js", "app/javascript/packs/application.js", force: true

  inject_into_file "app/views/layouts/application.html.erb",
    "  <%= javascript_pack_tag 'application' %>\n  ",
    before: /<\/body>/
end

#configure_landingObject



33
34
35
36
37
38
39
40
# File 'lib/rsg/generators/webpacker/install_generator.rb', line 33

def configure_landing
  template "landing_controller.rb.erb", "app/controllers/landing_controller.rb"
  copy_file "landing_show.html.erb", "app/views/landing/show.html.erb"
  inject_into_file "config/routes.rb", <<-CODE, before: "end"

 root 'landing#show'
  CODE
end

#configure_sassObject



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

def configure_sass
  copy_file "application.sass", "app/javascript/stylesheets/application.sass"
  gsub_file "app/views/layouts/application.html.erb",
    "stylesheet_link_tag",
    "stylesheet_pack_tag"
end

#install_webpackerObject



14
15
16
# File 'lib/rsg/generators/webpacker/install_generator.rb', line 14

def install_webpacker
  rake("webpacker:install")
end

#sanity_checkObject



2
3
4
# File 'lib/rsg/generators/webpacker/install_generator.rb', line 2

def sanity_check
  raise "Can't configure webpacker on API apps" if api_mode?
end