| Class | Mack::Rendering::Engine::Erubis |
| In: |
lib/mack/rendering/engine/erubis.rb
|
| Parent: | Mack::Rendering::Engine::Base |
Allows use of the Builder::XmlMarkup engine to be used with rendering.
See Mack::Rendering::ViewTemplate content_for for more details. Thanks Merb.
# File lib/mack/rendering/engine/erubis.rb, line 50
50: def capture(*args, &block)
51: # get the buffer from the block's binding
52: buffer = _erb_buffer( block.binding ) rescue nil
53:
54: # If there is no buffer, just call the block and get the contents
55: if buffer.nil?
56: block.call(*args)
57: # If there is a buffer, execute the block, then extract its contents
58: else
59: pos = buffer.length
60: block.call(*args)
61:
62: # extract the block
63: data = buffer[pos..-1]
64:
65: # replace it in the original with empty string
66: buffer[pos..-1] = ''
67:
68: data
69: end
70: end
# File lib/mack/rendering/engine/erubis.rb, line 44
44: def concat(txt, b)
45: eval( "_buf", b) << txt
46: end
# File lib/mack/rendering/engine/erubis.rb, line 8
8: def render(io, binding)
9: io_src = io
10: file_name = nil
11: if io.is_a?(File)
12: io_src = io.read
13: file_name = io.path
14: end
15:
16: eruby = nil
17:
18: eruby = ::Erubis::Eruby.new(io_src)
19:
20: eruby.filename = file_name
21: begin
22: eruby.result(binding)
23: rescue NoMethodError => e
24: if file_name
25: m = NoMethodError.new("undefined method `#{e.name}' for #{e.backtrace[0].match(/(^.+:\d+)/).captures.first}")
26: m.set_backtrace(e.backtrace)
27: raise m
28: end
29: raise e
30: rescue NameError => e
31: if file_name
32: m = NameError.new("undefined local variable or method `#{e.name}' for #{e.backtrace[0].match(/(^.+:\d+)/).captures.first}")
33: m.set_backtrace(e.backtrace)
34: raise m
35: end
36: raise e
37: end
38: end