import erb_2_0_4b2

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4216 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
seki 2003-07-29 14:35:42 +00:00
parent e078a75b73
commit 38ac53f0c1

View File

@ -34,6 +34,8 @@ class ERB
end end
class TrimScanner < Scanner class TrimScanner < Scanner
TrimSplitRegexp = /(<%%)|(%%>)|(<%=)|(<%#)|(<%)|(%>\n)|(%>)|(\n)/
def initialize(src, trim_mode, percent) def initialize(src, trim_mode, percent)
super(src) super(src)
@trim_mode = trim_mode @trim_mode = trim_mode
@ -83,17 +85,21 @@ class ERB
def trim_line(line) def trim_line(line)
head = nil head = nil
last = nil last = nil
line.split(SplitRegexp).each do |token| line.split(TrimSplitRegexp).each do |token|
next if token.empty? next if token.empty?
head = token unless head head = token unless head
if token == "\n" && last == '%>' if token == "%>\n"
next if @trim_mode == '>' yield('%>')
next if @trim_mode == '<>' && is_erb_stag?(head) if @trim_mode == '>'
yield("\n") yield(:cr)
elsif @trim_mode == '<>' && is_erb_stag?(head)
yield(:cr)
else
yield("\n")
end
break break
end end
yield(token) yield(token)
last = token
end end
end end
@ -158,6 +164,8 @@ class ERB
content = '' content = ''
out.push(token.to_s) out.push(token.to_s)
out.cr out.cr
when :cr
out.cr
when '<%', '<%=', '<%#' when '<%', '<%=', '<%#'
scanner.stag = token scanner.stag = token
out.push("#{@put_cmd} #{content.dump}") if content.size > 0 out.push("#{@put_cmd} #{content.dump}") if content.size > 0