summaryrefslogtreecommitdiff
path: root/lib/erubis/enhancer.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/erubis/enhancer.rb')
-rw-r--r--lib/erubis/enhancer.rb27
1 files changed, 21 insertions, 6 deletions
diff --git a/lib/erubis/enhancer.rb b/lib/erubis/enhancer.rb
index 3b61975..b129a11 100644
--- a/lib/erubis/enhancer.rb
+++ b/lib/erubis/enhancer.rb
@@ -443,18 +443,33 @@ module Erubis
"regard lines starting with '%' as program code"
end
- PERCENT_LINE_PATTERN = /(.*?)^\%(.*?\r?\n)/m
-
def add_text(src, text)
- text.scan(PERCENT_LINE_PATTERN) do |txt, line|
- super(src, txt)
+ pos = 0
+ text2 = ''
+ text.scan(/^\%(.*?\r?\n)/) do
+ line = $1
+ match = Regexp.last_match
+ len = match.begin(0) - pos
+ str = text[pos, len]
+ pos = match.end(0)
+ if text2.empty?
+ text2 = str
+ else
+ text2 << str
+ end
if line[0] == ?%
- super(src, line)
+ text2 << line
else
+ super(src, text2)
+ text2 = ''
add_stmt(src, line)
end
end
- rest = $' || text
+ rest = pos == 0 ? text : $' # or $' || text
+ unless text2.empty?
+ text2 << rest if rest
+ rest = text2
+ end
super(src, rest)
end