Sha256: 3ca11f31def6d0bbeeb8a6ba61d140ace9db2836f2ecb90cda97366b968c58c0

Contents?: true

Size: 1.15 KB

Versions: 3

Compression:

Stored size: 1.15 KB

Contents

module ActionView
  module Helpers
    module ErubisHelper
      
      def capture(*args, &block)
        if block_called_from_erb?(block)
          with_output_buffer { block.call(*args) }
        elsif block_called_from_erubis?(block)
          # Thanks Mack
          buffer = eval( "@output_buffer", block.binding, __FILE__, __LINE__) rescue nil 
          if buffer.nil?
            block.call(*args)
          else
            pos = buffer.length
            block.call(*args)
            result = buffer[pos..-1]
            buffer[pos..-1] = ''
            result
          end  
        else
          with_output_buffer { return block.call(*args) }
        end
      end
      
      private
      BLOCK_CALLED_FROM_ERUBIS = 'defined? __in_erubis_template'

      if RUBY_VERSION < '1.9.0'
        def block_called_from_erubis?(block)
          block && eval(BLOCK_CALLED_FROM_ERUBIS, block)
        end
      else
        def block_called_from_erubis?(block)
          block && eval(BLOCK_CALLED_FROM_ERUBIS, block.binding)
        end
      end      
      
    end
  end
end

module ActionView
  class Base
    include ActionView::Helpers::ErubisHelper
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
methodmissing-erubis_template_handler-0.0.0 lib/action_view/helpers/erubis_helper.rb
methodmissing-erubis_template_handler-1.0.0 lib/action_view/helpers/erubis_helper.rb
methodmissing-erubis_template_handler-1.0.2 lib/action_view/helpers/erubis_helper.rb