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 %>
# <ul>
# <li><%= link "Home" %></li>
# <li><%= link "Product Info", "product-info" %></li>
# </ul>
# <% end %>
#
# Passing content as an argument
# <title><%= content_default(:title, "Default Title") %></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 %>
# <ul>
# <li><%= link "Super Special Home" %></li>
# <li><%= link "Different Product Info", "product-info" %></li>
# </ul>
# <% end %>
#
# Passing content as an argument
# <title><%= content_block(:title, "Custom Title") %></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