Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change the way autoload paths are added to application.rb #205

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 9 additions & 21 deletions lib/generators/phlex/install/install_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,22 @@ class InstallGenerator < ::Rails::Generators::Base

APPLICATION_CONFIGURATION_PATH = Rails.root.join("config/application.rb")
TAILWIND_CONFIGURATION_PATH = Rails.root.join("tailwind.config.js")
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"
)

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
ADD_EXTRA_AUTOLOAD_PATHS_CODE

def autoload_views
def autoload_components_layouts_views
return unless APPLICATION_CONFIGURATION_PATH.exist?

inject_into_class(
APPLICATION_CONFIGURATION_PATH,
"Application",
%( config.autoload_paths << "\#{root}/app/views"\n),
ADD_EXTRA_AUTOLOAD_PATHS_CODE,
)
end

Expand Down