Project

General

Profile

Feature #1032 » erb.diff

babie (babie tanaka), 01/21/2009 07:22 PM

View differences:

lib/erb.rb (working copy)
847 847
  module DefMethod
848 848
    public
849 849
  # define _methodname_ as instance method of current module, using ERB object or eRuby file
850
    def def_erb_method(methodname, erb_or_fname)
850
    def def_erb_method(methodname, erb_or_fname, safe_level=nil, trim_mode=nil, eoutvar='_erbout')
851 851
      if erb_or_fname.kind_of? String
852 852
        fname = erb_or_fname
853
        erb = ERB.new(File.read(fname))
853
        erb = ERB.new(File.read(fname), safe_level, trim_mode, eoutvar)
854 854
        erb.def_method(self, methodname, fname)
855 855
      else
856 856
        erb = erb_or_fname
test/erb/trim_hello.erb (revision 0)
1
= hello
2
<%- 3.times do |n| -%>
3
* <%= n %>
4
<%- end -%>
test/erb/test_erb.rb (working copy)
235 235
      def_erb_method('hello_world', erb)
236 236
    end
237 237
    assert(klass.new.respond_to?('hello_world'))    
238

  
239
    klass.module_eval do
240
      def_erb_method('trim_hello', File.join(File.dirname(File.expand_path(__FILE__)), 'trim_hello.erb'), nil, '-')
241
    end
242
    assert(klass.new.respond_to?('trim_hello'))    
238 243
  end
239 244

  
240 245
  def test_escape