summaryrefslogtreecommitdiff
path: root/lib/erb.rb
diff options
context:
space:
mode:
authorseki <seki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-07-25 22:03:52 +0000
committerseki <seki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-07-25 22:03:52 +0000
commit74709388228b2a00bbdaf39c82ec4d7b90fc0898 (patch)
tree324efc426f5784e5285e7322464e4d7eb6fad44e /lib/erb.rb
parent0a39c5748964df1bc9d742d25a97965d09cd0601 (diff)
fix: keep lineno
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4166 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/erb.rb')
-rw-r--r--lib/erb.rb32
1 files changed, 21 insertions, 11 deletions
diff --git a/lib/erb.rb b/lib/erb.rb
index 7fa5f2d..ec4823e 100644
--- a/lib/erb.rb
+++ b/lib/erb.rb
@@ -13,11 +13,18 @@ end
# ERB::Compiler
class ERB
class Compiler
+ class PercentLine
+ def initialize(str)
+ @value = str
+ end
+ attr_reader :value
+ alias :to_s :value
+ end
+
class Scanner
SplitRegexp = /(<%%)|(%%>)|(<%=)|(<%#)|(<%)|(%>)|(\n)/
- def initialize(compiler, src)
- @compiler = compiler
+ def initialize(src)
@src = src
@stag = nil
end
@@ -27,10 +34,10 @@ class ERB
end
class TrimScanner < Scanner
- def initialize(compiler, src)
- super(compiler, src)
- @trim_mode = compiler.trim_mode
- @percent = compiler.percent
+ def initialize(src, trim_mode, percent)
+ super(src)
+ @trim_mode = trim_mode
+ @percent = percent
if @trim_mode
@scan_line = self.method(:trim_line)
else
@@ -62,9 +69,7 @@ class ERB
if line[0] == ?%
@scan_line.call(line, &block)
else
- yield('<%')
- yield(' ' +line.chomp)
- yield('%>')
+ yield(PercentLine.new(line.chomp))
end
end
@@ -148,6 +153,11 @@ class ERB
scanner.scan do |token|
if scanner.stag.nil?
case token
+ when PercentLine
+ out.push("#{@put_cmd} #{content.dump}") if content.size > 0
+ content = ''
+ out.push(token.to_s)
+ out.cr
when '<%', '<%=', '<%#'
scanner.stag = token
out.push("#{@put_cmd} #{content.dump}") if content.size > 0
@@ -217,9 +227,9 @@ class ERB
def make_scanner(src)
if @percent || @trim_mode
- TrimScanner.new(self, src)
+ TrimScanner.new(src, @trim_mode, @percent)
else
- SimpleScanner.new(self, src)
+ SimpleScanner.new(src)
end
end