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

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

Instance Method Summary collapse

Instance Method Details

#content_for(key, value = nil, &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.



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/roda/plugins/content_for.rb', line 41

def content_for(key, value=nil, &block)
  if block
    outvar = render_opts[:template_opts][:outvar]
    buf_was = instance_variable_get(outvar)
    # clean the output buffer for ERB-based rendering systems
    instance_variable_set(outvar, String.new)

    @_content_for ||= {}
    @_content_for[key] = Tilt[render_opts[:engine]].new(&block).render

    instance_variable_set(outvar, buf_was)
  elsif value
    @_content_for ||= {}
    @_content_for[key] = value
  elsif @_content_for
    @_content_for[key]
  end
end