Skip to content

Commit 9d30e2a

Browse files
authored
Merge pull request #473 from rails/flavorjones-fix-stylesheet-link-tags
fix: unnecessary stylesheet_link_tag for tailwind
2 parents 52515eb + 7ae7a06 commit 9d30e2a

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

Diff for: lib/install/install_tailwindcss.rb

+7-4
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22
CENTERING_CONTAINER_INSERTION_POINT = /^\s*<%= yield %>/.freeze
33

44
if APPLICATION_LAYOUT_PATH.exist?
5-
say "Add Tailwindcss include tags and container element in application layout"
6-
insert_into_file APPLICATION_LAYOUT_PATH.to_s, <<~ERB.indent(4), before: /^\s*<%= stylesheet_link_tag/
7-
<%= stylesheet_link_tag "tailwind", "data-turbo-track": "reload" %>
8-
ERB
5+
unless File.read(APPLICATION_LAYOUT_PATH).match?(/stylesheet_link_tag :app/)
6+
say "Add Tailwindcss include tags in application layout"
7+
insert_into_file APPLICATION_LAYOUT_PATH.to_s, <<~ERB.indent(4), before: /^\s*<%= stylesheet_link_tag/
8+
<%= stylesheet_link_tag "tailwind", "data-turbo-track": "reload" %>
9+
ERB
10+
end
911

12+
say "Add Tailwindcss container element in application layout"
1013
if File.open(APPLICATION_LAYOUT_PATH).read =~ /<body>\n\s*<%= yield %>\n\s*<\/body>/
1114
insert_into_file APPLICATION_LAYOUT_PATH.to_s, %( <main class="container mx-auto mt-28 px-5 flex">\n ), before: CENTERING_CONTAINER_INSERTION_POINT
1215
insert_into_file APPLICATION_LAYOUT_PATH.to_s, %(\n </main>), after: CENTERING_CONTAINER_INSERTION_POINT

Diff for: lib/install/upgrade_tailwindcss.rb

+6
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@
1818
end
1919

2020
if APPLICATION_LAYOUT_PATH.exist?
21+
if File.read(APPLICATION_LAYOUT_PATH).match?(/stylesheet_link_tag :app/) &&
22+
File.read(APPLICATION_LAYOUT_PATH).match?(/stylesheet_link_tag "tailwind"/)
23+
say "Remove unnecessary stylesheet_link_tag from application layout"
24+
gsub_file APPLICATION_LAYOUT_PATH.to_s, %r{^\s*<%= stylesheet_link_tag "tailwind".*%>$}, ""
25+
end
26+
2127
if File.read(APPLICATION_LAYOUT_PATH).match?(/"inter-font"/)
2228
say "Strip Inter font CSS from application layout"
2329
gsub_file APPLICATION_LAYOUT_PATH.to_s, %r{, "inter-font"}, ""

Diff for: test/integration/user_install_test.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ bundle binstubs --all
3636
bin/rails tailwindcss:install
3737

3838
# TEST: tailwind was installed correctly
39-
grep -q tailwind app/views/layouts/application.html.erb
39+
grep -q "<main class=\"container" app/views/layouts/application.html.erb
40+
test -a app/assets/stylesheets/application.tailwind.css
4041

4142
# TEST: rake tasks don't exec (#188)
4243
cat <<EOF >> Rakefile

0 commit comments

Comments
 (0)