Sha256: e78e108db60bc2bd3c5b90297cb69355387c054eee1a76f13580287ad7bd663b

Contents?: true

Size: 806 Bytes

Versions: 8

Compression:

Stored size: 806 Bytes

Contents

module Munge
  module Helpers
    module Capture
      def capture(&block)
        if block.binding.local_variable_defined?(:_erbout)
          original_erbout = block.binding.local_variable_get(:_erbout)
          block.binding.local_variable_set(:_erbout, "")

          captured_text = block.call

          block.binding.local_variable_set(:_erbout, original_erbout)

          captured_text
        else
          block.call
        end
      end

      def append_to_erbout(block_binding, text)
        if block_binding.local_variable_defined?(:_erbout)
          original_erbout = block_binding.local_variable_get(:_erbout)

          updated_erbout = original_erbout + text

          block_binding.local_variable_set(:_erbout, updated_erbout)
        end

        text
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
munge-0.11.1 lib/munge/helpers/capture.rb
munge-0.11.0 lib/munge/helpers/capture.rb
munge-0.10.0 lib/munge/helpers/capture.rb
munge-0.9.0 lib/munge/helpers/capture.rb
munge-0.8.0 lib/munge/helpers/capture.rb
munge-0.7.1 lib/munge/helpers/capture.rb
munge-0.7.0 lib/munge/helpers/capture.rb
munge-0.6.0 lib/munge/helpers/capture.rb