Class: HotwiredComponent::InstallGenerator

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

Instance Method Summary collapse

Instance Method Details

#add_application_componentObject

def install_hotwired_rails

rake "hotwire:install"

end



9
10
11
12
# File 'lib/generators/hotwired_component/install/install_generator.rb', line 9

def add_application_component
  template "application_component.rb.erb", 
    "app/components/application_component.rb"
end

#add_component_controllersObject



14
15
16
17
18
19
20
21
# File 'lib/generators/hotwired_component/install/install_generator.rb', line 14

def add_component_controllers
  append_to_file "app/javascript/controllers/index.js" do
    "      context = require.context(\"../../components\", true, /_controller\\.js$/)\n      application.load(definitionsFromContext(context))    \n    JAVASCRIPT\n  end\nend\n"

#update_webpacker_configObject



23
24
25
26
# File 'lib/generators/hotwired_component/install/install_generator.rb', line 23

def update_webpacker_config
  gsub_file "config/webpacker.yml", "additional_paths: [", 
    "additional_paths: [\"app/components\""
end