Skip to content

Commit

Permalink
refactor erb scanner open tag matching to fix a minor bug
Browse files Browse the repository at this point in the history
  • Loading branch information
korny committed Sep 8, 2011
1 parent b256ecf commit 9a2edcc
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions lib/coderay/scanners/erb.rb
Expand Up @@ -13,15 +13,15 @@ class ERB < Scanner
KINDS_NOT_LOC = HTML::KINDS_NOT_LOC

ERB_RUBY_BLOCK = /
<%(?!%)[=-]?
(?>
(<%(?!%)[-=\#]?)
((?>
[^\-%]* # normal*
(?> # special
(?: %(?!>) | -(?!%>) )
[^\-%]* # normal*
)*
)
(?: -?%> )?
))
((?: -?%> )?)
/x # :nodoc:

START_OF_ERB = /
Expand All @@ -48,21 +48,25 @@ def scan_tokens encoder, options
@html_scanner.tokenize match, :tokens => encoder

elsif match = scan(/#{ERB_RUBY_BLOCK}/o)
start_tag = match[/\A<%[-=#]?/]
end_tag = match[/-?%?>?\z/]
start_tag = self[1]
code = self[2]
end_tag = self[3]

encoder.begin_group :inline
encoder.text_token start_tag, :inline_delimiter
code = match[start_tag.size .. -1 - end_tag.size]
if start_tag[/\A<%#/]

if start_tag == '<%#'
encoder.text_token code, :comment
else
@ruby_scanner.tokenize code, :tokens => encoder
end unless code.empty?

encoder.text_token end_tag, :inline_delimiter unless end_tag.empty?
encoder.end_group :inline

else
raise_inspect 'else-case reached!', encoder

end

end
Expand Down

0 comments on commit 9a2edcc

Please sign in to comment.