module Roda::RodaPlugins::Chunked::InstanceMethods

def each_chunk

Yield each chunk of the template rendering separately.
def each_chunk
  response.body.each{|s| yield s}
  template, opts, block = @_each_chunk_args
  # Use a lambda for the flusher, so that a call to flush
  # by a template can result in this method yielding a chunk
  # of the response.
  @_flusher = lambda do
    yield @_out_buf
    @_out_buf = ''
  end
  if layout =  opts.fetch(:layout, render_opts[:layout])
    if layout_opts = opts[:layout_opts]
      layout_opts = render_opts[:layout_opts].merge(layout_opts)
    end
    @_out_buf = render(layout, layout_opts||OPTS) do
      flush
      block.call if block
      yield opts[:content] || render(template, opts)
      nil
    end
  else
    yield if block
    yield view(template, opts)
  end
  flush
rescue => e
  handle_chunk_error(e)
end