0
@@ -156,24 +156,13 @@ module Merb::Template
0
# name<String>:: The name of the method that will be created.
0
# mod<Module>:: The module that the compiled method will be placed into.
0
def self.compile_template(io, name, mod)
0
- template = ::Erubis::
Eruby.new(io.read)
0
+ template = ::Erubis::
BlockAwareEruby.new(io.read)
0
template.def_method(mod, name, File.expand_path(io.path))
0
- # Provides direct acccess to the buffer for this view context
0
- # the_binding<Binding>:: The binding to pass to the buffer.
0
- def _erb_buffer( the_binding )
0
- @_buffer = eval( "_buf", the_binding, __FILE__, __LINE__)
0
# *args:: Arguments to pass to the block.
0
# &block:: The template block to call.
0
@@ -188,30 +177,16 @@ module Merb::Template
0
# <p>Some Foo content!</p>
0
def capture_erb(*args, &block)
0
- # get the buffer from the block's binding
0
- buffer = _erb_buffer( block.binding ) rescue nil
0
- # If there is no buffer, just call the block and get the contents
0
- # If there is a buffer, execute the block, then extract its contents
0
- data = buffer[pos..-1]
0
- # replace it in the original with empty string
0
+ _old_buf, @_erb_buf = @_erb_buf, ""
0
def concat_erb(string, binding)
0
-
_erb_buffer(binding) << string
0
@@ -222,14 +197,46 @@ module Merb::Template
0
+ module BlockAwareEnhancer
0
+ src << "_old_buf, @_erb_buf = @_erb_buf, ''; "
0
+ src << "@_engine = 'erb'; "
0
- def def_method(object, method_name, filename=nil)
0
- m = object.is_a?(Module) ? :module_eval : :instance_eval
0
- setup = "@_engine = 'erb'"
0
- object.__send__(m, "def #{method_name}(locals={}); #{setup}; #{@src}; end", filename || @filename || '(erubis)')
0
+ def add_postamble(src)
0
+ src << "\n" unless src[-1] == ?\n
0
+ src << "_ret = @_erb_buf; @_erb_buf = _old_buf; _ret.to_s\n"
0
+ def add_text(src, text)
0
+ src << " @_erb_buf << '" << escape_text(text) << "'; "
0
+ def add_expr_escaped(src, code)
0
+ src << ' @_erb_buf << ' << escaped_expr(code) << ';'
0
+ def add_expr_literal(src, code)
0
+ unless code =~ /(do|\{)(\s*|[^|]*|)?\s*$/
0
+ src << ' @_erb_buf << (' << code << ').to_s;'
0
+ src << ' @_erb_buf << ' << code << "; "
0
+ class BlockAwareEruby < Eruby
0
+ include BlockAwareEnhancer
0
+ # module RubyEvaluator
0
+ # def def_method(object, method_name, filename=nil)
0
+ # m = object.is_a?(Module) ? :module_eval : :instance_eval
0
+ # setup = "@_engine = 'erb'"
0
+ # object.__send__(m, "def #{method_name}(locals={}); #{setup}; #{@src}; end", filename || @filename || '(erubis)')
0
\ No newline at end of file
Comments
No one has commented yet.