Module: Templater::CaptureHelpers

Included in:
Generator
Defined in:
lib/templater/capture_helpers.rb

Overview

TODO: this should be specced in some way.

Instance Method Summary collapse

Instance Method Details

#_erb_buffer(the_binding) ⇒ Object

:nodoc:



29
30
31
# File 'lib/templater/capture_helpers.rb', line 29

def _erb_buffer( the_binding )
  @_buffer = eval( "_erbout", the_binding, __FILE__, __LINE__)
end

#capture(*args, &block) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/templater/capture_helpers.rb', line 33

def capture(*args, &block)
  # get the buffer from the block's binding
  buffer = _erb_buffer( block.binding ) rescue nil

  # If there is no buffer, just call the block and get the contents
  if buffer.nil?
    block.call(*args)
  # If there is a buffer, execute the block, then extract its contents
  else
    pos = buffer.length
    block.call(*args)

    # extract the block
    data = buffer[pos..-1]

    # replace it in the original with empty string
    buffer[pos..-1] = ''

    data
  end
end

#concat(string, binding) ⇒ Object

DOC



56
57
58
# File 'lib/templater/capture_helpers.rb', line 56

def concat(string, binding)
  _erb_buffer(binding) << string
end