Skip to content

Commit dcd0973

Browse files
authored
Fix: Insert centering container around the yield (#106)
Insertion point of the centering container was problematic. Meaning, if someone has a `yield :somethig` inside theirs `application.html.erb` old regex would pick that as a insertion point and possiblly break the html structure. This commit makes that regex more rigid to only insert centering container around the `<%= yield %>`.
1 parent 651d5a7 commit dcd0973

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

lib/install/tailwindcss.rb

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
APPLICATION_LAYOUT_PATH = Rails.root.join("app/views/layouts/application.html.erb")
1+
APPLICATION_LAYOUT_PATH = Rails.root.join("app/views/layouts/application.html.erb")
2+
CENTERING_CONTAINER_INSERTION_POINT = /^\s*<%= yield %>/.freeze
23

34
if APPLICATION_LAYOUT_PATH.exist?
45
say "Add Tailwindcss include tags and container element in application layout"
56
insert_into_file APPLICATION_LAYOUT_PATH.to_s, <<~ERB.indent(4), before: /^\s*<%= stylesheet_link_tag/
67
<%= stylesheet_link_tag "tailwind", "inter-font", "data-turbo-track": "reload" %>
78
ERB
8-
insert_into_file APPLICATION_LAYOUT_PATH.to_s, %( <main class="container mx-auto mt-28 px-5 flex">\n ), before: /^\s*<%= yield/
9-
insert_into_file APPLICATION_LAYOUT_PATH.to_s, %(\n </main>), after: /^\s*<%= yield %>/
9+
10+
insert_into_file APPLICATION_LAYOUT_PATH.to_s, %( <main class="container mx-auto mt-28 px-5 flex">\n ), before: CENTERING_CONTAINER_INSERTION_POINT
11+
insert_into_file APPLICATION_LAYOUT_PATH.to_s, %(\n </main>), after: CENTERING_CONTAINER_INSERTION_POINT
1012
else
1113
say "Default application.html.erb is missing!", :red
1214
say %( Add <%= stylesheet_link_tag "tailwind", "inter-font", "data-turbo-track": "reload" %> within the <head> tag in your custom layout.)

0 commit comments

Comments
 (0)