class Komponent::Generators::InstallGenerator
Public Instance Methods
append_to_application_configuration()
click to toggle source
# 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()
click to toggle source
# 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()
click to toggle source
# 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, dependencies_not_met_error_message end end
create_komponent_default_structure()
click to toggle source
# 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()
click to toggle source
# 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()
click to toggle source
# 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()
click to toggle source
# 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()
click to toggle source
# 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()
click to toggle source
# 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
Protected Instance Methods
application_pack_path()
click to toggle source
# File lib/generators/komponent/install_generator.rb, line 79 def application_pack_path komponent_root_directory.join("packs", "application.js") end
components_directory()
click to toggle source
# File lib/generators/komponent/install_generator.rb, line 87 def components_directory Rails.root.join(komponent_root_directory, "components") end
default_path()
click to toggle source
# File lib/generators/komponent/install_generator.rb, line 112 def default_path rails_configuration.komponent.root end
dependencies_not_met_error_message()
click to toggle source
# File lib/generators/komponent/install_generator.rb, line 103 def dependencies_not_met_error_message "Seems you don't have webpacker installed in your project. Please install webpacker, and follow instructions at https://github.com/rails/webpacker" end
komponent_already_installed?()
click to toggle source
# File lib/generators/komponent/install_generator.rb, line 99 def komponent_already_installed? File.directory?(relative_path_from_rails) end
komponent_root_directory()
click to toggle source
# File lib/generators/komponent/install_generator.rb, line 83 def komponent_root_directory default_path end
relative_path_from_rails()
click to toggle source
# File lib/generators/komponent/install_generator.rb, line 116 def relative_path_from_rails default_path.relative_path_from(Rails.root) end
stimulus?()
click to toggle source
# File lib/generators/komponent/install_generator.rb, line 107 def stimulus? return options[:stimulus] if options[:stimulus] komponent_configuration[:stimulus] end
stimulus_application_path()
click to toggle source
# File lib/generators/komponent/install_generator.rb, line 75 def stimulus_application_path komponent_root_directory.join("stimulus_application.js") end
stimulus_application_template()
click to toggle source
# File lib/generators/komponent/install_generator.rb, line 65 def stimulus_application_template <<-JAVASCRIPT import { Application } from "stimulus"; const application = Application.start(); export default application; JAVASCRIPT end
webpacker_configuration_file()
click to toggle source
# File lib/generators/komponent/install_generator.rb, line 91 def webpacker_configuration_file Rails.root.join("config", "webpacker.yml") end
webpacker_default_structure()
click to toggle source
# File lib/generators/komponent/install_generator.rb, line 95 def webpacker_default_structure Rails.root.join("app", "javascript") end
Private Instance Methods
app_generators()
click to toggle source
# File lib/generators/komponent/install_generator.rb, line 133 def app_generators rails_configuration.app_generators end
komponent_configuration()
click to toggle source
# File lib/generators/komponent/install_generator.rb, line 122 def komponent_configuration { stimulus: nil, locale: nil, }.merge(app_generators.komponent) end
rails_configuration()
click to toggle source
# File lib/generators/komponent/install_generator.rb, line 129 def rails_configuration Rails.application.config end