Class: SimpleNavigation::ItemContainer
- Inherits:
-
Object
- Object
- SimpleNavigation::ItemContainer
- Defined in:
- lib/simple_navigation/item_container.rb
Overview
Holds the Items for a navigation ‘level’ (either the primary_navigation or a sub_navigation).
Instance Attribute Summary collapse
-
#dom_class ⇒ Object
Returns the value of attribute dom_class.
-
#dom_id ⇒ Object
Returns the value of attribute dom_id.
-
#items ⇒ Object
readonly
Returns the value of attribute items.
-
#renderer ⇒ Object
Returns the value of attribute renderer.
Instance Method Summary collapse
-
#[](navi_key) ⇒ Object
Returns the Item with the specified key, nil otherwise.
-
#initialize ⇒ ItemContainer
constructor
:nodoc:.
-
#item(key, name, url, options = {}, &block) ⇒ Object
Creates a new navigation item.
-
#render(current_navigation, include_sub_navigation = false, current_sub_navigation = nil) ⇒ Object
Renders the items in this ItemContainer using the configured renderer.
Constructor Details
#initialize ⇒ ItemContainer
:nodoc:
9 10 11 12 |
# File 'lib/simple_navigation/item_container.rb', line 9 def initialize #:nodoc: @items = [] @renderer = Configuration.instance.renderer end |
Instance Attribute Details
#dom_class ⇒ Object
Returns the value of attribute dom_class.
7 8 9 |
# File 'lib/simple_navigation/item_container.rb', line 7 def dom_class @dom_class end |
#dom_id ⇒ Object
Returns the value of attribute dom_id.
7 8 9 |
# File 'lib/simple_navigation/item_container.rb', line 7 def dom_id @dom_id end |
#items ⇒ Object (readonly)
Returns the value of attribute items.
6 7 8 |
# File 'lib/simple_navigation/item_container.rb', line 6 def items @items end |
#renderer ⇒ Object
Returns the value of attribute renderer.
7 8 9 |
# File 'lib/simple_navigation/item_container.rb', line 7 def renderer @renderer end |
Instance Method Details
#[](navi_key) ⇒ Object
Returns the Item with the specified key, nil otherwise.
37 38 39 |
# File 'lib/simple_navigation/item_container.rb', line 37 def [](navi_key) items.find {|i| i.key == navi_key} end |
#item(key, name, url, options = {}, &block) ⇒ Object
Creates a new navigation item.
The key is a symbol which uniquely defines your navigation item in the scope of the primary_navigation or the sub_navigation.
The name will be displayed in the rendered navigation. This can also be a call to your I18n-framework.
The url is the address that the generated item points to. You can also use url_helpers (named routes, restful routes helper, url_for etc.)
The options can be used to specify the following things:
-
html_attributes- will be included in the rendered navigation item (e.g. id, class etc.) -
:if- Specifies a proc to call to determine if the item should be rendered (e.g.:if => Proc.new { current_user.admin? }). The proc should evaluate to a true or false value and is evaluated in the context of the view. -
:unless- Specifies a proc to call to determine if the item should not be rendered (e.g.:unless => Proc.new { current_user.admin? }). The proc should evaluate to a true or false value and is evaluated in the context of the view.
The block - if specified - will hold the item’s sub_navigation.
32 33 34 |
# File 'lib/simple_navigation/item_container.rb', line 32 def item(key, name, url, ={}, &block) (@items << Item.new(key, name, url, , block)) if should_add_item?() end |
#render(current_navigation, include_sub_navigation = false, current_sub_navigation = nil) ⇒ Object
Renders the items in this ItemContainer using the configured renderer.
Set include_sub_navigation to true if you want to nest the sub_navigation into the active primary_navigation
44 45 46 |
# File 'lib/simple_navigation/item_container.rb', line 44 def render(, =false, =nil) self.renderer.new(, ).render(self, ) end |