* 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:
parent
784019f740
commit
d8164d50c9
@ -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>
|
Tue Dec 4 18:21:04 2012 Naohisa Goto <ngotogenome@gmail.com>
|
||||||
|
|
||||||
* test/ruby/memory_status.rb (Memory): use fiddle/types if available.
|
* test/ruby/memory_status.rb (Memory): use fiddle/types if available.
|
||||||
|
36
lib/erb.rb
36
lib/erb.rb
@ -583,6 +583,14 @@ class ERB
|
|||||||
end
|
end
|
||||||
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
|
# Compiles an ERB template into Ruby code. Returns an array of the code
|
||||||
# and encoding like ["code", Encoding].
|
# and encoding like ["code", Encoding].
|
||||||
def compile(s)
|
def compile(s)
|
||||||
@ -600,7 +608,7 @@ class ERB
|
|||||||
if scanner.stag.nil?
|
if scanner.stag.nil?
|
||||||
case token
|
case token
|
||||||
when PercentLine
|
when PercentLine
|
||||||
out.push("#{@put_cmd} #{content_dump(content)}") if content.size > 0
|
add_put_cmd(out, content) if content.size > 0
|
||||||
content = ''
|
content = ''
|
||||||
out.push(token.to_s)
|
out.push(token.to_s)
|
||||||
out.cr
|
out.cr
|
||||||
@ -608,11 +616,11 @@ class ERB
|
|||||||
out.cr
|
out.cr
|
||||||
when '<%', '<%=', '<%#'
|
when '<%', '<%=', '<%#'
|
||||||
scanner.stag = token
|
scanner.stag = token
|
||||||
out.push("#{@put_cmd} #{content_dump(content)}") if content.size > 0
|
add_put_cmd(out, content) if content.size > 0
|
||||||
content = ''
|
content = ''
|
||||||
when "\n"
|
when "\n"
|
||||||
content << "\n"
|
content << "\n"
|
||||||
out.push("#{@put_cmd} #{content_dump(content)}")
|
add_put_cmd(out, content)
|
||||||
content = ''
|
content = ''
|
||||||
when '<%%'
|
when '<%%'
|
||||||
content << '<%'
|
content << '<%'
|
||||||
@ -632,7 +640,7 @@ class ERB
|
|||||||
out.push(content)
|
out.push(content)
|
||||||
end
|
end
|
||||||
when '<%='
|
when '<%='
|
||||||
out.push("#{@insert_cmd}((#{content}).to_s)")
|
add_insert_cmd(out, content)
|
||||||
when '<%#'
|
when '<%#'
|
||||||
# out.push("# #{content_dump(content)}")
|
# out.push("# #{content_dump(content)}")
|
||||||
end
|
end
|
||||||
@ -645,7 +653,7 @@ class ERB
|
|||||||
end
|
end
|
||||||
end
|
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
|
out.close
|
||||||
return out.script, enc
|
return out.script, enc
|
||||||
end
|
end
|
||||||
@ -785,12 +793,16 @@ class ERB
|
|||||||
#
|
#
|
||||||
def initialize(str, safe_level=nil, trim_mode=nil, eoutvar='_erbout')
|
def initialize(str, safe_level=nil, trim_mode=nil, eoutvar='_erbout')
|
||||||
@safe_level = safe_level
|
@safe_level = safe_level
|
||||||
compiler = ERB::Compiler.new(trim_mode)
|
compiler = make_compiler(trim_mode)
|
||||||
set_eoutvar(compiler, eoutvar)
|
set_eoutvar(compiler, eoutvar)
|
||||||
@src, @enc = *compiler.compile(str)
|
@src, @enc = *compiler.compile(str)
|
||||||
@filename = nil
|
@filename = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def make_compiler(trim_mode)
|
||||||
|
ERB::Compiler.new(trim_mode)
|
||||||
|
end
|
||||||
|
|
||||||
# The Ruby code generated by ERB
|
# The Ruby code generated by ERB
|
||||||
attr_reader :src
|
attr_reader :src
|
||||||
|
|
||||||
@ -806,16 +818,8 @@ class ERB
|
|||||||
def set_eoutvar(compiler, eoutvar = '_erbout')
|
def set_eoutvar(compiler, eoutvar = '_erbout')
|
||||||
compiler.put_cmd = "#{eoutvar}.concat"
|
compiler.put_cmd = "#{eoutvar}.concat"
|
||||||
compiler.insert_cmd = "#{eoutvar}.concat"
|
compiler.insert_cmd = "#{eoutvar}.concat"
|
||||||
|
compiler.pre_cmd = ["#{eoutvar} = ''"]
|
||||||
cmd = []
|
compiler.post_cmd = ["#{eoutvar}.force_encoding(__ENCODING__)"]
|
||||||
cmd.push "#{eoutvar} = ''"
|
|
||||||
|
|
||||||
compiler.pre_cmd = cmd
|
|
||||||
|
|
||||||
cmd = []
|
|
||||||
cmd.push("#{eoutvar}.force_encoding(__ENCODING__)")
|
|
||||||
|
|
||||||
compiler.post_cmd = cmd
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Generate results and print them. (see ERB#result)
|
# Generate results and print them. (see ERB#result)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user