From 3363cbf385be8298c9c30d605371636e7b73d69f Mon Sep 17 00:00:00 2001 From: Trinity Takei Date: Thu, 27 Jun 2024 21:00:38 +0200 Subject: [PATCH] Change the way autoload paths are added to application.rb --- .../phlex/install/install_generator.rb | 48 +++++++------------ 1 file changed, 18 insertions(+), 30 deletions(-) diff --git a/lib/generators/phlex/install/install_generator.rb b/lib/generators/phlex/install/install_generator.rb index ecbd734..43a1aa8 100644 --- a/lib/generators/phlex/install/install_generator.rb +++ b/lib/generators/phlex/install/install_generator.rb @@ -6,36 +6,24 @@ class InstallGenerator < ::Rails::Generators::Base APPLICATION_CONFIGURATION_PATH = Rails.root.join("config/application.rb") TAILWIND_CONFIGURATION_PATH = Rails.root.join("tailwind.config.js") - - def autoload_components - return unless APPLICATION_CONFIGURATION_PATH.exist? - - inject_into_class( - APPLICATION_CONFIGURATION_PATH, - "Application", - %( config.autoload_paths << "\#{root}/app/views/components"\n), - ) - end - - def autoload_layouts - return unless APPLICATION_CONFIGURATION_PATH.exist? - - inject_into_class( - APPLICATION_CONFIGURATION_PATH, - "Application", - %( config.autoload_paths << "\#{root}/app/views/layouts"\n), - ) - end - - def autoload_views - return unless APPLICATION_CONFIGURATION_PATH.exist? - - inject_into_class( - APPLICATION_CONFIGURATION_PATH, - "Application", - %( config.autoload_paths << "\#{root}/app/views"\n), - ) - end + ADD_EXTRA_AUTOLOAD_PATHS_CODE = <<-ADD_EXTRA_AUTOLOAD_PATHS_CODE + config.autoload_paths.push( + "\#{root}/app/views/components", + "\#{root}/app/views", + "\#{root}/app/views/layouts" + ) + + ADD_EXTRA_AUTOLOAD_PATHS_CODE + + def autoload_components_layouts_views + return unless APPLICATION_CONFIGURATION_PATH.exist? + + inject_into_class( + APPLICATION_CONFIGURATION_PATH, + "Application", + ADD_EXTRA_AUTOLOAD_PATHS_CODE, + ) + end def configure_tailwind return unless TAILWIND_CONFIGURATION_PATH.exist?