class SimpleNavigation::ItemAdapter

This class acts as an adapter to items that are not defined using the DSL in the config/navigation.rb, but directly provided inside the application. When defining the items that way, every item you provide needs to define the following methods:

and optionally

You can also specify your items as a list of hashes. The hashes will be converted to objects automatically. The hashes representing the items obviously must have the keys :key, :name and :url and optionally the keys :options and :items.

See SimpleNavigation::ItemContainer#item for the purpose of these methods.

Attributes

item[R]

Public Class Methods

new(item) click to toggle source
# File lib/simple_navigation/item_adapter.rb, line 33
def initialize(item)
  @item = item.is_a?(Hash) ? OpenStruct.new(item) : item
end

Public Instance Methods

items() click to toggle source

Returns the items (subnavigation) for this item if it responds to :items and the items-collection is not empty. Returns nil otherwise.

# File lib/simple_navigation/item_adapter.rb, line 45
def items
  item.items if item.respond_to?(:items) && item.items && item.items.any?
end
options() click to toggle source

Returns the options for this item. If the wrapped item does not implement an options method, an empty hash is returned.

# File lib/simple_navigation/item_adapter.rb, line 39
def options
  item.respond_to?(:options) ? item.options : {}
end
to_simple_navigation_item(item_container) click to toggle source

Converts this Item into a SimpleNavigation::Item

# File lib/simple_navigation/item_adapter.rb, line 50
def to_simple_navigation_item(item_container)
  SimpleNavigation::Item.new(item_container, key, name, url, options)
end