module Roda::RodaPlugins::CaptureERB::InstanceMethods

def capture_erb(opts=OPTS, &block)

a String instance.
variable supports the +capture+ method and is not
is the default behavior if the template output
value of the block converted to a string. This
template output variable, instead of the return
:returns :: If set to :buffer, returns the value of the
Options:

Restore the previous ERB output buffer before returning.
Return the value of the block, converted to a string.
with an empty string, and then yield to the block.
Temporarily replace the ERB output buffer
def capture_erb(opts=OPTS, &block)
  outvar = render_opts[:template_opts][:outvar]
  buf_was = instance_variable_get(outvar)
  if buf_was.respond_to?(:capture) && !buf_was.instance_of?(String)
    buf_was.capture(&block)
  else
    returns = opts.fetch(:returns) { self.opts[:capture_erb_returns] }
    begin
      instance_variable_set(outvar, String.new)
      if returns == :buffer
        yield
        instance_variable_get(outvar).to_s
      else
        yield.to_s
      end
    ensure
      instance_variable_set(outvar, buf_was) if outvar && buf_was
    end
  end
end