This is the base class for all renderers.
A renderer is responsible for rendering an ItemContainer and its containing items to HTML.
# File lib/simple_navigation/rendering/renderer/base.rb, line 21 def expand_all? !!options[:expand_all] end
# File lib/simple_navigation/rendering/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 determin whether an item's sub_navigation should be rendered or not.
# File lib/simple_navigation/rendering/renderer/base.rb, line 46 def render(item_container) raise 'subclass responsibility' end
# File lib/simple_navigation/rendering/renderer/base.rb, line 29 def skip_if_empty? !!options[:skip_if_empty] end
Extracts the options relevant for the generated link
# File lib/simple_navigation/rendering/renderer/base.rb, line 96 def link_options_for(item) special_options = {:method => item.method, :class => item.selected_class}.reject {|k, v| v.nil? } link_options = item.html_options[:link] return special_options unless link_options opts = special_options.merge(link_options) opts[:class] = [link_options[:class], item.selected_class].flatten.compact.join(' ') opts.delete(:class) if opts[:class].nil? || opts[:class] == '' 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/rendering/renderer/base.rb, line 90 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/rendering/renderer/base.rb, line 73 def suppress_link?(item) item.url.nil? end
determine and return link or static content depending on item/renderer conditions.
# File lib/simple_navigation/rendering/renderer/base.rb, line 79 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