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 34 def capture_erb(&block) 35 outvar = render_opts[:template_opts][:outvar] 36 buf_was = instance_variable_get(outvar) 37 38 if buf_was.respond_to?(:capture) && !buf_was.instance_of?(String) 39 buf_was.capture(&block) 40 else 41 begin 42 instance_variable_set(outvar, String.new) 43 yield.to_s 44 ensure 45 instance_variable_set(outvar, buf_was) if outvar && buf_was 46 end 47 end 48 end