class SimpleNavigation::Renderer::Base
This is the base class for all renderers.
A renderer is responsible for rendering an ItemContainer
and its containing items to HTML.
Attributes
Public Instance Methods
# File lib/simple_navigation/renderer/base.rb, line 21 def expand_all? !!options[:expand_all] end
# File lib/simple_navigation/renderer/base.rb, line 25 def level options[:level] || :all end
Renders the specified ItemContainer
to HTML.
When implementing a renderer, please consider to call include_sub_navigation? to determine whether an item’s sub_navigation should be rendered or not.
# File lib/simple_navigation/renderer/base.rb, line 46 def render(item_container) fail NotImplementedError, 'subclass responsibility' end
# File lib/simple_navigation/renderer/base.rb, line 29 def skip_if_empty? !!options[:skip_if_empty] end
Protected Instance Methods
Extracts the options relevant for the generated link
# File lib/simple_navigation/renderer/base.rb, line 92 def link_options_for(item) special_options = { method: item.method, class: item.selected_class }.reject { |_, v| v.nil? } link_options = item.link_html_options return special_options unless link_options opts = special_options.merge(link_options) classes = [link_options[:class], item.selected_class] classes = classes.flatten.compact.join(' ') opts[:class] = classes unless classes.empty? opts end
to allow overriding when link options should be special-cased (eg. links renderer uses item options for the a-tag rather than an li-tag).
# File lib/simple_navigation/renderer/base.rb, line 87 def options_for(item) link_options_for(item) end
to allow overriding when there is specific logic determining when a link should not be rendered (eg. breadcrumbs renderer does not render the final breadcrumb as a link when instructed not to do so.)
# File lib/simple_navigation/renderer/base.rb, line 70 def suppress_link?(item) item.url.nil? end
determine and return link or static content depending on item/renderer conditions.
# File lib/simple_navigation/renderer/base.rb, line 76 def tag_for(item) if suppress_link?(item) content_tag('span', item.name, link_options_for(item).except(:method)) else link_to(item.name, item.url, options_for(item)) end end