Module: Roda::RodaPlugins::CaptureERB::InstanceMethods
- Defined in:
- lib/roda/plugins/capture_erb.rb
Instance Method Summary collapse
-
#capture_erb(&block) ⇒ Object
Temporarily replace the ERB output buffer with an empty string, and then yield to the block.
Instance Method Details
#capture_erb(&block) ⇒ Object
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.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/roda/plugins/capture_erb.rb', line 33 def capture_erb(&block) outvar = render_opts[:template_opts][:outvar] buf_was = instance_variable_get(outvar) if buf_was.respond_to?(:capture) buf_was.capture(&block) else begin instance_variable_set(outvar, String.new) yield.to_s ensure instance_variable_set(outvar, buf_was) if outvar && buf_was end end end |