Module: Roda::RodaPlugins::ContentFor::InstanceMethods

Defined in:
lib/roda/plugins/content_for.rb

Instance Method Summary collapse

Instance Method Details

#content_for(key, &block) ⇒ Object

If called with a block, store content enclosed by block under the given key. If called without a block, retrieve stored content with the given key, or return nil if there is no content stored with that key.



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/roda/plugins/content_for.rb', line 29

def content_for(key, &block)
  if block
    @_content_for ||= {}
    buf_was = @_out_buf
    @_out_buf = ''
    yield
    @_content_for[key] = @_out_buf
    @_out_buf = buf_was
  elsif @_content_for
    @_content_for[key]
  end
end