Skip to content
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
6 changes: 4 additions & 2 deletions lib/herb/engine/compiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ def process_erb_tag(node, skip_comment_check: false)
code = node.content.value.strip

if erb_output?(opening)
process_erb_output(opening, code)
process_erb_output(node, opening, code)
else
apply_trim(node, code)
end
Expand Down Expand Up @@ -487,9 +487,11 @@ def find_token_before_code_sequence(tokens, whitespace_index)
search_index >= 0 ? tokens[search_index] : nil
end

def process_erb_output(opening, code)
def process_erb_output(node, opening, code)
has_right_trim = node.tag_closing&.value == "-%>"
should_escape = should_escape_output?(opening)
add_expression_with_escaping(code, should_escape)
@trim_next_whitespace = true if has_right_trim
end

def should_escape_output?(opening)
Expand Down
2 changes: 1 addition & 1 deletion sig/herb/engine/compiler.rbs

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

21 changes: 21 additions & 0 deletions test/engine/whitespace_trimming_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,5 +148,26 @@ class WhitespaceTrimmingTest < Minitest::Spec
assert_compiled_snapshot(template)
assert_evaluated_snapshot(template, enforce_erubi_equality: true)
end

test "expression tag with right trim removes following newline" do
template = "<%= \"hello\" -%>\nworld"

assert_compiled_snapshot(template)
assert_evaluated_snapshot(template, enforce_erubi_equality: true)
end

test "expression tag with right trim inline" do
template = "<%= \"hello\" -%> world"

assert_compiled_snapshot(template)
assert_evaluated_snapshot(template, enforce_erubi_equality: true)
end

test "expression tag with right trim as no-op for newline control" do
template = "2024-07-09 with the filters: \"archived:false\"<%= -%>.\n"

assert_compiled_snapshot(template)
assert_evaluated_snapshot(template, enforce_erubi_equality: true)
end
end
end

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

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

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

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

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

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

Loading