Class: SimpleNavigation::ItemAdapter
- Inherits:
-
Object
- Object
- SimpleNavigation::ItemAdapter
- Extended by:
- Forwardable
- Defined in:
- lib/simple_navigation/item_adapter.rb
Overview
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:
-
key -
name -
url
and optionally
-
options -
items- if one of your items has a subnavigation it must respondto <tt>items</tt> providing the subnavigation.
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.
Defined Under Namespace
Classes: Item
Instance Attribute Summary collapse
-
#item ⇒ Object
readonly
Returns the value of attribute item.
Instance Method Summary collapse
-
#initialize(item) ⇒ ItemAdapter
constructor
A new instance of ItemAdapter.
-
#items ⇒ Object
Returns the items (subnavigation) for this item if it responds to :items and the items-collection is not empty.
-
#options ⇒ Object
Returns the options for this item.
-
#to_simple_navigation_item(item_container) ⇒ Object
Converts this Item into a SimpleNavigation::Item.
Constructor Details
#initialize(item) ⇒ ItemAdapter
Returns a new instance of ItemAdapter.
44 45 46 |
# File 'lib/simple_navigation/item_adapter.rb', line 44 def initialize(item) @item = item.is_a?(Hash) ? Item.new(item) : item end |
Instance Attribute Details
#item ⇒ Object (readonly)
Returns the value of attribute item.
30 31 32 |
# File 'lib/simple_navigation/item_adapter.rb', line 30 def item @item end |
Instance Method Details
#items ⇒ Object
Returns the items (subnavigation) for this item if it responds to :items and the items-collection is not empty. Returns nil otherwise.
56 57 58 |
# File 'lib/simple_navigation/item_adapter.rb', line 56 def items item.items if item.items&.any? end |
#options ⇒ Object
Returns the options for this item. If the wrapped item does not implement an options method, an empty hash is returned.
50 51 52 |
# File 'lib/simple_navigation/item_adapter.rb', line 50 def item. end |
#to_simple_navigation_item(item_container) ⇒ Object
Converts this Item into a SimpleNavigation::Item
61 62 63 |
# File 'lib/simple_navigation/item_adapter.rb', line 61 def (item_container) SimpleNavigation::Item.new(item_container, key, name, url, ) end |