1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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
This commit is contained in:
seki 2012-12-04 15:10:17 +00:00
parent 784019f740
commit d8164d50c9
2 changed files with 25 additions and 16 deletions

View file

@ -1,3 +1,8 @@
Wed Dec 5 00:05:47 2012 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
* lib/erb.rb (make_compiler, add_put_cmd, add_insert_cmd): extract
methods.
Tue Dec 4 18:21:04 2012 Naohisa Goto <ngotogenome@gmail.com>
* test/ruby/memory_status.rb (Memory): use fiddle/types if available.

View file

@ -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)