summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormakoto kuwata <kwa@kuwata-lab.com>2011-02-22 22:34:55 +0900
committermakoto kuwata <kwa@kuwata-lab.com>2011-02-22 22:34:55 +0900
commit9e9652ff5b1ba430f0f7884e62f1c3be399f707d (patch)
tree92ac2b6d37026c2bfb6427b17ece94844ac26636
parent39d8c032821817f4a622ccd88d761f5969c0d3b5 (diff)
downloaderubis-9e9652ff5b1ba430f0f7884e62f1c3be399f707d.tar.gz
[refactor] change 'PercentLineEnhancer' to be subset of 'PrefixedLineEnhancer'
-rw-r--r--lib/erubis/enhancer.rb79
1 files changed, 32 insertions, 47 deletions
diff --git a/lib/erubis/enhancer.rb b/lib/erubis/enhancer.rb
index 75f9219..29f5af3 100644
--- a/lib/erubis/enhancer.rb
+++ b/lib/erubis/enhancer.rb
@@ -434,53 +434,6 @@ module Erubis
##
- ## regards lines starting with '%' as program code
- ##
- ## this is for compatibility to eruby and ERB.
- ##
- ## this is language-independent.
- ##
- module PercentLineEnhancer
-
- def self.desc # :nodoc:
- "regard lines starting with '%' as program code"
- end
-
- def add_text(src, text)
- 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] == ?%
- text2 << line
- else
- super(src, text2)
- text2 = ''
- add_stmt(src, line)
- end
- end
- #rest = pos == 0 ? text : $' # ruby1.8
- rest = pos == 0 ? text : text[pos..-1] # ruby1.9
- unless text2.empty?
- text2 << rest if rest
- rest = text2
- end
- super(src, rest)
- end
-
- end
-
-
- ##
## regards lines starting with '^[ \t]*%' as program code
##
## in addition you can specify prefix character (default '%')
@@ -505,6 +458,7 @@ module Erubis
text.scan(@prefixrexp) do
space = $1
line = $2
+ space, line = '', $1 unless $2
match = Regexp.last_match
len = match.begin(0) - pos
str = text[pos, len]
@@ -535,6 +489,37 @@ module Erubis
##
+ ## regards lines starting with '%' as program code
+ ##
+ ## this is for compatibility to eruby and ERB.
+ ##
+ ## this is language-independent.
+ ##
+ module PercentLineEnhancer
+ include PrefixedLineEnhancer
+
+ def self.desc # :nodoc:
+ "regard lines starting with '%' as program code"
+ end
+
+ #--
+ #def init_generator(properties={})
+ # super
+ # @prefixchar = '%'
+ # @prefixrexp = /^\%(.*?\r?\n)/
+ #end
+ #++
+
+ def add_text(src, text)
+ @prefixchar = '%'
+ @prefixrexp = /^\%(.*?\r?\n)/
+ super
+ end
+
+ end
+
+
+ ##
## [experimental] allow header and footer in eRuby script
##
## ex.