@@ -5,15 +5,14 @@ class InstallGenerator < ::Rails::Generators::Base
5
5
source_root File . expand_path ( "templates" , __dir__ )
6
6
7
7
APPLICATION_CONFIGURATION_PATH = Rails . root . join ( "config/application.rb" )
8
- TAILWIND_CONFIGURATION_PATH = Rails . root . join ( "tailwind.config.js" )
8
+
9
9
ADD_EXTRA_AUTOLOAD_PATHS_CODE = <<-ADD_EXTRA_AUTOLOAD_PATHS_CODE
10
10
config.autoload_paths.push(
11
11
"\# {root}/app/views/components",
12
12
"\# {root}/app/views",
13
13
"\# {root}/app/views/layouts"
14
14
)
15
-
16
- ADD_EXTRA_AUTOLOAD_PATHS_CODE
15
+ ADD_EXTRA_AUTOLOAD_PATHS_CODE
17
16
18
17
def autoload_components_layouts_views
19
18
return unless APPLICATION_CONFIGURATION_PATH . exist?
@@ -26,9 +25,9 @@ def autoload_components_layouts_views
26
25
end
27
26
28
27
def configure_tailwind
29
- return unless TAILWIND_CONFIGURATION_PATH . exist?
28
+ return unless tailwind_configuration_path . exist?
30
29
31
- insert_into_file TAILWIND_CONFIGURATION_PATH , after : "content: [" do
30
+ insert_into_file tailwind_configuration_path , after : "content: [" do
32
31
"\n './app/views/**/*.rb'," \
33
32
end
34
33
end
@@ -44,5 +43,22 @@ def create_application_layout
44
43
def create_application_view
45
44
template "application_view.rb" , Rails . root . join ( "app/views/application_view.rb" )
46
45
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
47
63
end
48
64
end
0 commit comments