Module: Roda::RodaPlugins::CaptureERB::InstanceMethods

Defined in:
lib/roda/plugins/capture_erb.rb

Instance Method Summary collapse

Instance Method Details

#capture_erbObject

Temporarily replace the ERB output buffer with an empty string, and then yield to the block. Return the value of the block, converted to a string. Restore the previous ERB output buffer before returning.



28
29
30
31
32
33
34
35
# File 'lib/roda/plugins/capture_erb.rb', line 28

def capture_erb
  outvar = render_opts[:template_opts][:outvar]
  buf_was = instance_variable_get(outvar)
  instance_variable_set(outvar, String.new)
  yield.to_s
ensure
  instance_variable_set(outvar, buf_was) if outvar && buf_was
end