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.



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/roda/plugins/content_for.rb', line 75

def content_for(key, value=nil, &block)
  append = opts[:append_content_for]

  if block || value
    if block
      value = capture_erb(&block)
    end

    @_content_for ||= {}

    if append
      (@_content_for[key] ||= []) << value
    else
      @_content_for[key] = value
    end
  elsif @_content_for && (value = @_content_for[key])
    if append
      value = value.join
    end

    value
  end
end