module OverrideHelper # Call this method to setup a default content block by name. This content will be rendered into the page # unless a content_block with the same name also exists somewhere else in the rendered response. # # === Examples # Using a block for complex, or lengthy content # <% content_default(:navigation) do %> # # <% end %> # # Passing content as an argument # <%= content_default(:title, "Default Title") %> def content_default(name, content = nil, &block) if override_content[name].blank? # default content = capture(&block) if block_given? else # override content = override_content[name] end if block_given? concat(content) else return content end end # Call this method to override a call to content_default. If no call to content_default with # a matching name exists then this block will not get rendered into the response. # # === Examples # Using a block for complex, or lengthy content # <% content_block(:navigation) do %> # # <% end %> # # Passing content as an argument # <%= content_block(:title, "Custom Title") %> def content_block(name, content = nil, &block) content = capture(&block) if block_given? override_content[name] = content nil end private def override_content # :nodoc: @override_content ||= {} end end