lib/roda/plugins/content_for.rb in roda-2.8.0 vs lib/roda/plugins/content_for.rb in roda-2.9.0

- old
+ new

@@ -12,10 +12,15 @@ # # <% content_for :foo do %> # Some content here. # <% end %> # + # You can also set the raw content as the second argument, + # instead of passing a block: + # + # <% content_for :foo, "Some content" %> + # # In the template in which you want to retrieve content, # call content_for without the block: # # <%= content_for :foo %> module ContentFor @@ -28,20 +33,23 @@ module InstanceMethods # 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. - def content_for(key, &block) + 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, '') @_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 end