Skip to content

Commit

Permalink
Handles indentation for multiline ERB-comments
Browse files Browse the repository at this point in the history
  • Loading branch information
davidwessman committed Aug 30, 2023
1 parent 56470a8 commit f4a2ba1
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
## [Unreleased]

- Handle ERB-tags inside HTML-tags, like `<div <%= "class='foo'" %>>`
- Handles indentation for multiline ERB-comment

## [0.10.4] - 2023-08-28

Expand Down
4 changes: 3 additions & 1 deletion lib/syntax_tree/erb/format.rb
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,9 @@ def visit_html_comment(node)
end

def visit_erb_comment(node)
visit(node.token)
q.seplist(node.token.value.split("\n"), -> { q.breakable }) do |line|
q.text(line.lstrip)
end
end

# Visit a CharData node.
Expand Down
4 changes: 2 additions & 2 deletions test/erb_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ def test_erb_comment

def test_erb_multiline_comment
source =
"<%#\n This is the first\nThis is the second\nThis is the third %>"
"<%#\n This is the first\n This is the second\n This is the third %>"
expected =
"<%#\n This is the first\nThis is the second\nThis is the third %>\n"
"<%#\nThis is the first\nThis is the second\nThis is the third %>\n"

assert_formatting(source, expected)
end
Expand Down
6 changes: 3 additions & 3 deletions test/fixture/erb_syntax_formatted.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
<%- "this only works in ERB not erubis" %>
<% # This should be written on one line %>
<%#
This is a comment
It can be mutiline
Treat it as a comment
This is a comment
It can be mutiline
Treat it as a comment
%>
<% if this -%>
Expand Down

0 comments on commit f4a2ba1

Please sign in to comment.