Module: Merb::Template::Erubis::Mixin

Defined in:
lib/merb-core/controller/template.rb

Instance Method Summary collapse

Instance Method Details

#_erb_buffer(the_binding) ⇒ Object

Provides direct acccess to the buffer for this view context

Parameters

the_binding<Binding>

The binding to pass to the buffer.

Returns

DOC



143
144
145
# File 'lib/merb-core/controller/template.rb', line 143

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

#capture_erb(*args, &block) ⇒ Object

Parameters

*args

Arguments to pass to the block.

&block

The template block to call.

Returns

String

The output of the block.

Examples

Capture being used in a .html.erb page:

<% @foo = capture do %>
  <p>Some Foo content!</p> 
<% end %>


160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# File 'lib/merb-core/controller/template.rb', line 160

def capture_erb(*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_erb(string, binding) ⇒ Object

DOC



183
184
185
# File 'lib/merb-core/controller/template.rb', line 183

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