Skip to content

Commit

Permalink
Merge pull request #204 from trinitytakei/tailwind-config-js-lookup
Browse files Browse the repository at this point in the history
Look up tailwind.config.js anywhere in the app directory (except dirs ignored explicitly)
  • Loading branch information
joeldrapper authored Sep 6, 2024
2 parents 51fd83a + 0d9edb2 commit 2715aae
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
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

0 comments on commit 2715aae

Please sign in to comment.