I am working on implementing support for content_for and yield_content in Hardwired .
The Sinatra :: Contrib implementation does not work, so I tried a simpler version:
module ContentFor def content_for(key, &block) content_blocks[key.to_sym] << block.call return "" end def content_for?(key) content_blocks[key.to_sym].any? end def yield_content(key, *args) content_blocks[key.to_sym].join end private def content_blocks @content_blocks ||= Hash.new {|h,k| h[k] = [] } end end
Unfortunately, this repeats the content (content_for seems to capture everything in the template, not just the child content).
What approach should be used to implement this?
source share