Feature #1032 » erb.diff
lib/erb.rb (working copy) | ||
---|---|---|
module DefMethod
|
||
public
|
||
# define _methodname_ as instance method of current module, using ERB object or eRuby file
|
||
def def_erb_method(methodname, erb_or_fname)
|
||
def def_erb_method(methodname, erb_or_fname, safe_level=nil, trim_mode=nil, eoutvar='_erbout')
|
||
if erb_or_fname.kind_of? String
|
||
fname = erb_or_fname
|
||
erb = ERB.new(File.read(fname))
|
||
erb = ERB.new(File.read(fname), safe_level, trim_mode, eoutvar)
|
||
erb.def_method(self, methodname, fname)
|
||
else
|
||
erb = erb_or_fname
|
test/erb/trim_hello.erb (revision 0) | ||
---|---|---|
= hello
|
||
<%- 3.times do |n| -%>
|
||
* <%= n %>
|
||
<%- end -%>
|
test/erb/test_erb.rb (working copy) | ||
---|---|---|
def_erb_method('hello_world', erb)
|
||
end
|
||
assert(klass.new.respond_to?('hello_world'))
|
||
klass.module_eval do
|
||
def_erb_method('trim_hello', File.join(File.dirname(File.expand_path(__FILE__)), 'trim_hello.erb'), nil, '-')
|
||
end
|
||
assert(klass.new.respond_to?('trim_hello'))
|
||
end
|
||
def test_escape
|