Skip to content

Commit

Permalink
Merge pull request #125 from eugeneius/erb_right_trim_equals
Browse files Browse the repository at this point in the history
Accept = as expression right trim
  • Loading branch information
rafaelfranca authored Mar 14, 2024
2 parents 9fab8b1 + 370f77a commit 1c77388
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/better_html/tokenizer/base_erb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module Tokenizer
class BaseErb < ::Erubi::Engine
REGEXP_WITHOUT_TRIM = /<%(={1,2})?(.*?)()?%>([ \t]*\r?\n)?/m
STMT_TRIM_MATCHER = /\A(-|#)?(.*?)([-=])?\z/m
EXPR_TRIM_MATCHER = /\A(.*?)(-)?\z/m
EXPR_TRIM_MATCHER = /\A(.*?)([-=])?\z/m

attr_reader :tokens
attr_reader :current_position
Expand Down
11 changes: 11 additions & 0 deletions test/better_html/tokenizer/html_erb_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,17 @@ class HtmlErbTest < ActiveSupport::TestCase
assert_attributes ({ type: :erb_end, loc: { begin_pos: 13, end_pos: 15, source: "%>" } }), scanner.tokens[3]
end

test "expression right trim with =%>" do
scanner = HtmlErb.new(buffer("<%= literal =%>"))
assert_equal 5, scanner.tokens.size

assert_attributes ({ type: :erb_begin, loc: { begin_pos: 0, end_pos: 2, source: "<%" } }), scanner.tokens[0]
assert_attributes ({ type: :indicator, loc: { begin_pos: 2, end_pos: 3, source: "=" } }), scanner.tokens[1]
assert_attributes ({ type: :code, loc: { begin_pos: 3, end_pos: 12, source: " literal " } }), scanner.tokens[2]
assert_attributes ({ type: :trim, loc: { begin_pos: 12, source: "=" } }), scanner.tokens[3]
assert_attributes ({ type: :erb_end, loc: { begin_pos: 13, end_pos: 15, source: "%>" } }), scanner.tokens[4]
end

test "line number for multi-line statements" do
scanner = HtmlErb.new(buffer("before <% multi\nline %> after"))
assert_equal 5, scanner.tokens.size
Expand Down

0 comments on commit 1c77388

Please sign in to comment.