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

Look up tailwind.config.js anywhere in the app directory (except dirs ignored explicitly) #204

Merged
merged 8 commits into from
Sep 6, 2024
26 changes: 21 additions & 5 deletions lib/generators/phlex/install/install_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@ class InstallGenerator < ::Rails::Generators::Base
source_root File.expand_path("templates", __dir__)

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"
)

ADD_EXTRA_AUTOLOAD_PATHS_CODE
ADD_EXTRA_AUTOLOAD_PATHS_CODE

def autoload_components_layouts_views
return unless APPLICATION_CONFIGURATION_PATH.exist?
Expand All @@ -26,9 +25,9 @@ def autoload_components_layouts_views
end

def configure_tailwind
return unless TAILWIND_CONFIGURATION_PATH.exist?
return unless tailwind_configuration_path.exist?

insert_into_file TAILWIND_CONFIGURATION_PATH, after: "content: [" do
insert_into_file tailwind_configuration_path, after: "content: [" do
"\n './app/views/**/*.rb'," \
end
end
Expand All @@ -44,5 +43,22 @@ def create_application_layout
def create_application_view
template "application_view.rb", Rails.root.join("app/views/application_view.rb")
end

private

def tailwind_configuration_path
@_tailwind_configuration_path ||=
Pathname.new(tailwind_configuration_files.first)
end

def tailwind_configuration_files
Dir.glob(
[
"#{Rails.root}/tailwind.config.js",
"#{Rails.root}/app/**/tailwind.config.js",
"#{Rails.root}/config/**/tailwind.config.js",
],
)
end
end
end
3 changes: 2 additions & 1 deletion test/dummy/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

# Reveal health status on /up that returns 200 if the app boots with no exceptions, otherwise 500.
# Can be used by load balancers and uptime monitors to verify that the app is live.
get "up", to: "rails/health#show", :as => :rails_health_check
get "up", to: "rails/health#show", as: :rails_health_check


# Defines the root path route ("/")
root "posts#index"
Expand Down
Loading