summaryrefslogtreecommitdiff
path: root/lib/erb.rb
diff options
context:
space:
mode:
authorseki <seki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-12-04 15:10:17 +0000
committerseki <seki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-12-04 15:10:17 +0000
commitd8164d50c907b1908b578965af1a1ecf5a19d852 (patch)
treef7e944dd8b4c9543223a3c3f726ced8d9555df62 /lib/erb.rb
parent784019f7400b5c1af123a9af1ab113906effffc6 (diff)
* lib/erb.rb (make_compiler, add_put_cmd, add_insert_cmd): extract
methods. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38186 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/erb.rb')
-rw-r--r--lib/erb.rb36
1 files changed, 20 insertions, 16 deletions
diff --git a/lib/erb.rb b/lib/erb.rb
index 934d83aa48..b2d6d36f13 100644
--- a/lib/erb.rb
+++ b/lib/erb.rb
@@ -583,6 +583,14 @@ class ERB
end
end
+ def add_put_cmd(out, content)
+ out.push("#{@put_cmd} #{content_dump(content)}")
+ end
+
+ def add_insert_cmd(out, content)
+ out.push("#{@insert_cmd}((#{content}).to_s)")
+ end
+
# Compiles an ERB template into Ruby code. Returns an array of the code
# and encoding like ["code", Encoding].
def compile(s)
@@ -600,7 +608,7 @@ class ERB
if scanner.stag.nil?
case token
when PercentLine
- out.push("#{@put_cmd} #{content_dump(content)}") if content.size > 0
+ add_put_cmd(out, content) if content.size > 0
content = ''
out.push(token.to_s)
out.cr
@@ -608,11 +616,11 @@ class ERB
out.cr
when '<%', '<%=', '<%#'
scanner.stag = token
- out.push("#{@put_cmd} #{content_dump(content)}") if content.size > 0
+ add_put_cmd(out, content) if content.size > 0
content = ''
when "\n"
content << "\n"
- out.push("#{@put_cmd} #{content_dump(content)}")
+ add_put_cmd(out, content)
content = ''
when '<%%'
content << '<%'
@@ -632,7 +640,7 @@ class ERB
out.push(content)
end
when '<%='
- out.push("#{@insert_cmd}((#{content}).to_s)")
+ add_insert_cmd(out, content)
when '<%#'
# out.push("# #{content_dump(content)}")
end
@@ -645,7 +653,7 @@ class ERB
end
end
end
- out.push("#{@put_cmd} #{content_dump(content)}") if content.size > 0
+ add_put_cmd(out, content) if content.size > 0
out.close
return out.script, enc
end
@@ -785,12 +793,16 @@ class ERB
#
def initialize(str, safe_level=nil, trim_mode=nil, eoutvar='_erbout')
@safe_level = safe_level
- compiler = ERB::Compiler.new(trim_mode)
+ compiler = make_compiler(trim_mode)
set_eoutvar(compiler, eoutvar)
@src, @enc = *compiler.compile(str)
@filename = nil
end
+ def make_compiler(trim_mode)
+ ERB::Compiler.new(trim_mode)
+ end
+
# The Ruby code generated by ERB
attr_reader :src
@@ -806,16 +818,8 @@ class ERB
def set_eoutvar(compiler, eoutvar = '_erbout')
compiler.put_cmd = "#{eoutvar}.concat"
compiler.insert_cmd = "#{eoutvar}.concat"
-
- cmd = []
- cmd.push "#{eoutvar} = ''"
-
- compiler.pre_cmd = cmd
-
- cmd = []
- cmd.push("#{eoutvar}.force_encoding(__ENCODING__)")
-
- compiler.post_cmd = cmd
+ compiler.pre_cmd = ["#{eoutvar} = ''"]
+ compiler.post_cmd = ["#{eoutvar}.force_encoding(__ENCODING__)"]
end
# Generate results and print them. (see ERB#result)