Skip to content

Commit 2715aae

Browse files
authored
Merge pull request #204 from trinitytakei/tailwind-config-js-lookup
Look up tailwind.config.js anywhere in the app directory (except dirs ignored explicitly)
2 parents 51fd83a + 0d9edb2 commit 2715aae

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

lib/generators/phlex/install/install_generator.rb

+21-5
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@ class InstallGenerator < ::Rails::Generators::Base
55
source_root File.expand_path("templates", __dir__)
66

77
APPLICATION_CONFIGURATION_PATH = Rails.root.join("config/application.rb")
8-
TAILWIND_CONFIGURATION_PATH = Rails.root.join("tailwind.config.js")
8+
99
ADD_EXTRA_AUTOLOAD_PATHS_CODE = <<-ADD_EXTRA_AUTOLOAD_PATHS_CODE
1010
config.autoload_paths.push(
1111
"\#{root}/app/views/components",
1212
"\#{root}/app/views",
1313
"\#{root}/app/views/layouts"
1414
)
15-
16-
ADD_EXTRA_AUTOLOAD_PATHS_CODE
15+
ADD_EXTRA_AUTOLOAD_PATHS_CODE
1716

1817
def autoload_components_layouts_views
1918
return unless APPLICATION_CONFIGURATION_PATH.exist?
@@ -26,9 +25,9 @@ def autoload_components_layouts_views
2625
end
2726

2827
def configure_tailwind
29-
return unless TAILWIND_CONFIGURATION_PATH.exist?
28+
return unless tailwind_configuration_path.exist?
3029

31-
insert_into_file TAILWIND_CONFIGURATION_PATH, after: "content: [" do
30+
insert_into_file tailwind_configuration_path, after: "content: [" do
3231
"\n './app/views/**/*.rb'," \
3332
end
3433
end
@@ -44,5 +43,22 @@ def create_application_layout
4443
def create_application_view
4544
template "application_view.rb", Rails.root.join("app/views/application_view.rb")
4645
end
46+
47+
private
48+
49+
def tailwind_configuration_path
50+
@_tailwind_configuration_path ||=
51+
Pathname.new(tailwind_configuration_files.first)
52+
end
53+
54+
def tailwind_configuration_files
55+
Dir.glob(
56+
[
57+
"#{Rails.root}/tailwind.config.js",
58+
"#{Rails.root}/app/**/tailwind.config.js",
59+
"#{Rails.root}/config/**/tailwind.config.js",
60+
],
61+
)
62+
end
4763
end
4864
end

test/dummy/config/routes.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55

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

1011
# Defines the root path route ("/")
1112
root "posts#index"

0 commit comments

Comments
 (0)