class Padrino::Helpers::OutputHelpers::ErbHandler
def block_is_type?(block)
can't take an <% end %> later on, so we have to use <% ... %>
We'd return a string in any other case, but erb <%= ... %>
Check whether we're called from an erb template.
def block_is_type?(block) self.is_type? || (block && eval('defined? __in_erb_template', block)) end
def block_is_type?(block)
def block_is_type?(block) self.is_type? || (block && eval('defined? __in_erb_template', block.binding)) end
def capture_from_template(*args, &block)
@handler.capture_from_template(&block) => "...html..."
==== Examples
Captures the html from a block of template code for this handler
def capture_from_template(*args, &block) erb_with_output_buffer { block_given? && block.call(*args) } end
def concat_to_template(text="")
@handler.concat_to_template("This will be output to the template buffer")
==== Examples
Outputs the given text to the templates buffer directly
#
def concat_to_template(text="") self.output_buffer << text if self.is_type? && text nil end
def erb_with_output_buffer(buf = '')
Used to direct the buffer for the erb capture
#
def erb_with_output_buffer(buf = '') self.output_buffer, old_buffer = buf, self.output_buffer yield buf ensure self.output_buffer = old_buffer end
def initialize(template)
def initialize(template) super @output_buffer = template.instance_variable_get(:@_out_buf) end
def is_type?
@handler.is_type? => true
==== Examples
Returns true if the current template type is same as this handlers; false otherwise.
#
def is_type? self.output_buffer.present? end
def output_buffer=(val)
def output_buffer=(val) template.instance_variable_set(:@_out_buf, val) end