Skip to content

Instantly share code, notes, and snippets.

@scarfacedeb
Last active August 29, 2015 13:59
Show Gist options
  • Select an option

  • Save scarfacedeb/10705679 to your computer and use it in GitHub Desktop.

Select an option

Save scarfacedeb/10705679 to your computer and use it in GitHub Desktop.
Custom simple-nav renderer for foundation 5
# Renders an ItemContainer as a <ul> element and its containing items as
# <li><a> elements.
# It only renders 'selected' elements.
#
# It's suited to work with foundation 5 out of the box
class FoundationBreadcrumbs < SimpleNavigation::Renderer::Base
# logic from SimpleNavigation::Renderer::List
def render(item_container)
if skip_if_empty? && item_container.empty?
''
else
tag = options[:ordered] ? :ol : :ul
dom_attributes = item_container.dom_attributes
if dom_attributes[:class]
dom_attributes[:class] += " breadcrumbs"
else
dom_attributes[:class] = "breadcrumbs"
end
content = list_content(item_container)
content_tag(tag, content, dom_attributes)
end
end
private
def list_content(item_container)
li_tags(item_container).join
end
# logic from SimpleNavigation::Renderer::Breadcrumbs
def li_tags(item_container)
item_container.items.each_with_object([]) do |item, list|
next unless item.selected?
li_options = item.html_options.except(:link)
li_content = tag_for(item)
list << content_tag(:li, li_content, li_options)
if include_sub_navigation?(item)
list.concat li_tags(item.sub_navigation)
end
end
end
protected
# from SimpleNavigation::Renderer::Breadcrumbs
def suppress_link?(item)
super || (options[:static_leaf] && item.active_leaf_class)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment