Skip to content

Commit

Permalink
Change the way autoload paths are added to application.rb
Browse files Browse the repository at this point in the history
  • Loading branch information
trinitytakei committed Aug 14, 2024
1 parent d941453 commit 3363cbf
Showing 1 changed file with 18 additions and 30 deletions.
48 changes: 18 additions & 30 deletions lib/generators/phlex/install/install_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down

0 comments on commit 3363cbf

Please sign in to comment.