Skip to content

Commit 7a4c3bd

Browse files
authored
Handle whitespace in HTML-strings with ERB (#40)
1 parent b43c4d6 commit 7a4c3bd

File tree

4 files changed

+12
-1
lines changed

4 files changed

+12
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
66

77
## [Unreleased]
88

9+
- Handle whitespace in HTML-strings using ERB-tags
10+
911
## [0.9.1] - 2023-06-28
1012

1113
- Handle formatting of multi-line ERB-tags with more than one statement.

lib/syntax_tree/erb/format.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ def initialize(q)
1111

1212
# Visit a Token node.
1313
def visit_token(node)
14-
q.text(node.value.strip)
14+
if %i[text whitespace].include?(node.type)
15+
q.text(node.value)
16+
else
17+
q.text(node.value.strip)
18+
end
1519
end
1620

1721
# Visit a Document node.

test/fixture/erb_syntax_formatted.html.erb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,6 @@
4141
assign_b ||= "b"
4242
assign_c ||= "c"
4343
%>
44+
45+
<div class="card mb-2 <%= condition ? "pb-3" : "pb-0" %> mt-<%= 5 * 5 %>">
46+
</div>

test/fixture/erb_syntax_unformatted.html.erb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,5 @@
4040
assign_b ||= "b"
4141
assign_c ||= "c"
4242
%>
43+
44+
<div class="card mb-2 <%= condition ? "pb-3" : "pb-0" %> mt-<%=5 * 5%>"></div>

0 commit comments

Comments
 (0)