Skip to content

fix: unnecessary stylesheet_link_tag for tailwind #473

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

Merged
merged 1 commit into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions lib/install/install_tailwindcss.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@
CENTERING_CONTAINER_INSERTION_POINT = /^\s*<%= yield %>/.freeze

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

say "Add Tailwindcss container element in application layout"
if File.open(APPLICATION_LAYOUT_PATH).read =~ /<body>\n\s*<%= yield %>\n\s*<\/body>/
insert_into_file APPLICATION_LAYOUT_PATH.to_s, %( <main class="container mx-auto mt-28 px-5 flex">\n ), before: CENTERING_CONTAINER_INSERTION_POINT
insert_into_file APPLICATION_LAYOUT_PATH.to_s, %(\n </main>), after: CENTERING_CONTAINER_INSERTION_POINT
Expand Down
6 changes: 6 additions & 0 deletions lib/install/upgrade_tailwindcss.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@
end

if APPLICATION_LAYOUT_PATH.exist?
if File.read(APPLICATION_LAYOUT_PATH).match?(/stylesheet_link_tag :app/) &&
File.read(APPLICATION_LAYOUT_PATH).match?(/stylesheet_link_tag "tailwind"/)
say "Remove unnecessary stylesheet_link_tag from application layout"
gsub_file APPLICATION_LAYOUT_PATH.to_s, %r{^\s*<%= stylesheet_link_tag "tailwind".*%>$}, ""
end

if File.read(APPLICATION_LAYOUT_PATH).match?(/"inter-font"/)
say "Strip Inter font CSS from application layout"
gsub_file APPLICATION_LAYOUT_PATH.to_s, %r{, "inter-font"}, ""
Expand Down
3 changes: 2 additions & 1 deletion test/integration/user_install_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ bundle binstubs --all
bin/rails tailwindcss:install

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

# TEST: rake tasks don't exec (#188)
cat <<EOF >> Rakefile
Expand Down
Loading