Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
27 changes: 19 additions & 8 deletions lib/herb/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -286,14 +286,25 @@ def add_expression_block_end(code, escaped: false)

@src.chomp! if @src.end_with?("\n") && code_stripped.start_with?(" ")

@src << " " << code_stripped
@src << (escaped ? "))" : ")")

@src << if code.include?("#") || trailing_newline
"\n"
else
";"
end
has_comment = code.include?("#")
closing = escaped ? "))" : ")"

if has_comment
comment_index = code_stripped.index("#")
code_part = code_stripped[0...comment_index].rstrip
comment_part = code_stripped[comment_index..]

@src << " " << code_part << closing << " " << comment_part << "\n"
else
@src << " " << code_stripped
@src << closing

@src << if trailing_newline
"\n"
else
";"
end
end

@buffer_on_stack = false
end
Expand Down
6 changes: 6 additions & 0 deletions test/engine/engine_block_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,11 @@ class EngineBlockTest < Minitest::Spec

assert_compiled_snapshot(template)
end

test "inline comment on end inside output block does not break parens" do
template = "<%= render Foo.new do %>hello<% end # comment %>"

assert_compiled_snapshot(template)
end
end
end

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading