summaryrefslogtreecommitdiff
path: root/lib/erb.rb
diff options
context:
space:
mode:
authorseki <seki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-07-29 14:35:42 +0000
committerseki <seki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-07-29 14:35:42 +0000
commit38ac53f0c1f1deb37ef7d544cd43f423bfaaafdb (patch)
tree69e719d83e21a6aaa0acb942b5c9b651ddae2753 /lib/erb.rb
parente078a75b73284f265092bb8e66871a87ce47a249 (diff)
import erb_2_0_4b2
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4216 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/erb.rb')
-rw-r--r--lib/erb.rb20
1 files changed, 14 insertions, 6 deletions
diff --git a/lib/erb.rb b/lib/erb.rb
index ec4823e..f8c1c98 100644
--- a/lib/erb.rb
+++ b/lib/erb.rb
@@ -34,6 +34,8 @@ class ERB
end
class TrimScanner < Scanner
+ TrimSplitRegexp = /(<%%)|(%%>)|(<%=)|(<%#)|(<%)|(%>\n)|(%>)|(\n)/
+
def initialize(src, trim_mode, percent)
super(src)
@trim_mode = trim_mode
@@ -83,17 +85,21 @@ class ERB
def trim_line(line)
head = nil
last = nil
- line.split(SplitRegexp).each do |token|
+ line.split(TrimSplitRegexp).each do |token|
next if token.empty?
head = token unless head
- if token == "\n" && last == '%>'
- next if @trim_mode == '>'
- next if @trim_mode == '<>' && is_erb_stag?(head)
- yield("\n")
+ if token == "%>\n"
+ yield('%>')
+ if @trim_mode == '>'
+ yield(:cr)
+ elsif @trim_mode == '<>' && is_erb_stag?(head)
+ yield(:cr)
+ else
+ yield("\n")
+ end
break
end
yield(token)
- last = token
end
end
@@ -158,6 +164,8 @@ class ERB
content = ''
out.push(token.to_s)
out.cr
+ when :cr
+ out.cr
when '<%', '<%=', '<%#'
scanner.stag = token
out.push("#{@put_cmd} #{content.dump}") if content.size > 0