module Roda::RodaPlugins::CaptureERB::InstanceMethods
Public Instance Methods
Source
# File lib/roda/plugins/capture_erb.rb, line 67 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
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.
Options:
- :returns
-
If set to :buffer, returns the value of the template output variable, instead of the return value of the block converted to a string. This is the default behavior if the template output variable supports the
capture
method and is not a String instance.