Public Instance methods
capture_erb(&block)
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.
[show source]
# File lib/roda/plugins/capture_erb.rb 33 def capture_erb(&block) 34 outvar = render_opts[:template_opts][:outvar] 35 buf_was = instance_variable_get(outvar) 36 37 if buf_was.respond_to?(:capture) 38 buf_was.capture(&block) 39 else 40 begin 41 instance_variable_set(outvar, String.new) 42 yield.to_s 43 ensure 44 instance_variable_set(outvar, buf_was) if outvar && buf_was 45 end 46 end 47 end