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

adapter[R]
options[R]

Public Instance Methods

expand_all?() click to toggle source
# File lib/simple_navigation/renderer/base.rb, line 21
def expand_all?
  !!options[:expand_all]
end
include_sub_navigation?(item) click to toggle source
# File lib/simple_navigation/renderer/base.rb, line 33
def include_sub_navigation?(item)
  consider_sub_navigation?(item) && expand_sub_navigation?(item)
end
level() click to toggle source
# File lib/simple_navigation/renderer/base.rb, line 25
def level
  options[:level] || :all
end
render(item_container) click to toggle source

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
render_sub_navigation_for(item) click to toggle source
# File lib/simple_navigation/renderer/base.rb, line 37
def render_sub_navigation_for(item)
  item.sub_navigation.render(options)
end
skip_if_empty?() click to toggle source
# File lib/simple_navigation/renderer/base.rb, line 29
def skip_if_empty?
  !!options[:skip_if_empty]
end

Protected Instance Methods

consider_sub_navigation?(item) click to toggle source
# File lib/simple_navigation/renderer/base.rb, line 52
def consider_sub_navigation?(item)
  return false unless item.sub_navigation

  case level
  when :all then true
  when Range then item.sub_navigation.level <= level.max
  else false
  end
end
expand_sub_navigation?(item) click to toggle source
# File lib/simple_navigation/renderer/base.rb, line 62
def expand_sub_navigation?(item)
  expand_all? || item.selected?
end
options_for(item) click to toggle source

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
tag_for(item) click to toggle source

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