Skip to content

Instantly share code, notes, and snippets.

@benphelps
Created January 12, 2017 19:23
Show Gist options
  • Save benphelps/156012f86f7f0c8b9fd6f9ea8e7e93e7 to your computer and use it in GitHub Desktop.
Save benphelps/156012f86f7f0c8b9fd6f9ea8e7e93e7 to your computer and use it in GitHub Desktop.
def sub_heading(content = nil)
@sub_headings ||= []
if content
@sub_headings.push content
elsif block_given?
@sub_headings.each do |sub_heading|
yield sub_heading
end
else
Enumerator.new do |y|
@sub_headings.each do |sub_heading|
y << sub_heading
end
end
end
end
<!-- Add links to the sub heading -->
<% sub_heading link_to('A Link', some_path) %>
<% sub_heading link_to('Another One', some_path) %>
<!-- Use links in a block of HTML -->
<% sub_heading do |heading| %>
<small><%= heading %></small>
<% end %>
<!-- Use links in other ways too -->
<% sub_heading.collect { |l| strip_tags(l) }.join(' - ') %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment