Class: Komponent::Generators::InstallGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Komponent::Generators::InstallGenerator
- Defined in:
- lib/generators/komponent/install_generator.rb
Instance Method Summary collapse
- #append_to_application_configuration ⇒ Object
- #append_to_application_pack ⇒ Object
- #check_webpacker_dependency ⇒ Object
- #create_komponent_default_structure ⇒ Object
- #create_root_directory ⇒ Object
- #create_stimulus_file ⇒ Object
- #install_stimulus ⇒ Object
- #modify_webpacker_configuration ⇒ Object
- #move_webpacker_default_structure ⇒ Object
Instance Method Details
#append_to_application_configuration ⇒ Object
46 47 48 49 |
# File 'lib/generators/komponent/install_generator.rb', line 46 def append_to_application_configuration application "config.autoload_paths << config.root.join('#{relative_path_from_rails}/components')" application "config.i18n.load_path += Dir[config.root.join('#{relative_path_from_rails}/components/**/*.yml')]" end |
#append_to_application_pack ⇒ Object
51 52 53 |
# File 'lib/generators/komponent/install_generator.rb', line 51 def append_to_application_pack append_to_file(application_pack_path, "import 'components';") end |
#check_webpacker_dependency ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/generators/komponent/install_generator.rb', line 8 def check_webpacker_dependency return if komponent_already_installed? unless File.exist?(webpacker_configuration_file) and File.directory?(webpacker_default_structure) raise Thor::Error, end end |
#create_komponent_default_structure ⇒ Object
32 33 34 35 36 37 |
# File 'lib/generators/komponent/install_generator.rb', line 32 def create_komponent_default_structure return if File.exist?(components_directory.join("index.js")) empty_directory(components_directory) create_file(components_directory.join("index.js")) end |
#create_root_directory ⇒ Object
16 17 18 19 20 |
# File 'lib/generators/komponent/install_generator.rb', line 16 def create_root_directory return if File.directory?(komponent_root_directory) empty_directory(komponent_root_directory) end |
#create_stimulus_file ⇒ Object
39 40 41 42 43 44 |
# File 'lib/generators/komponent/install_generator.rb', line 39 def create_stimulus_file return if File.exist?(stimulus_application_path) return unless stimulus? create_file(stimulus_application_path, stimulus_application_template) end |
#install_stimulus ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/generators/komponent/install_generator.rb', line 55 def install_stimulus if stimulus? in_root do run("yarn add stimulus") end end end |
#modify_webpacker_configuration ⇒ Object
22 23 24 |
# File 'lib/generators/komponent/install_generator.rb', line 22 def modify_webpacker_configuration gsub_file(webpacker_configuration_file, /source_path: app\/javascript$/, "source_path: #{relative_path_from_rails}") end |
#move_webpacker_default_structure ⇒ Object
26 27 28 29 30 |
# File 'lib/generators/komponent/install_generator.rb', line 26 def move_webpacker_default_structure return if File.directory?(komponent_root_directory) run("mv #{webpacker_default_structure}/* #{komponent_root_directory}") end |