Class: SimpleNavigation::Item

Inherits:
Object
  • Object
show all
Defined in:
lib/simple_navigation/item.rb

Overview

Represents an item in your navigation. Gets generated by the item method in the config-file.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, name, url, options, sub_nav_block) ⇒ Item

see ItemContainer#item



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/simple_navigation/item.rb', line 9

def initialize(key, name, url, options, sub_nav_block)
  @key = key
  @method = options.delete(:method)
  @name = name
  @url = url
  @html_options = options
  if sub_nav_block
    @sub_navigation = ItemContainer.new
    sub_nav_block.call @sub_navigation
  end
end

Instance Attribute Details

#html_options(current_navigation) ⇒ Object

Returns the html-options hash for the item, i.e. the options specified for this item in the config-file. It also adds the ‘selected’ class to the list of classes if necessary.



28
29
30
31
32
33
34
# File 'lib/simple_navigation/item.rb', line 28

def html_options(current_navigation)
  default_options = self.autogenerate_item_ids? ? {:id => key.to_s} : {}
  options = default_options.merge(@html_options)
  options[:class] = [@html_options[:class], self.selected_class(current_navigation)].flatten.compact.join(' ')
  options.delete(:class) if options[:class].blank? 
  options
end

#keyObject (readonly)

Returns the value of attribute key.



5
6
7
# File 'lib/simple_navigation/item.rb', line 5

def key
  @key
end

#methodObject (readonly)

Returns the value of attribute method.



5
6
7
# File 'lib/simple_navigation/item.rb', line 5

def method
  @method
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/simple_navigation/item.rb', line 5

def name
  @name
end

Returns the value of attribute sub_navigation.



5
6
7
# File 'lib/simple_navigation/item.rb', line 5

def sub_navigation
  @sub_navigation
end

#urlObject (readonly)

Returns the value of attribute url.



5
6
7
# File 'lib/simple_navigation/item.rb', line 5

def url
  @url
end

Instance Method Details

#selected?(current_navigation) ⇒ Boolean

Returns true if this navigation item should be rendered as ‘selected’ for the specified current_navigation.

Returns:

  • (Boolean)


22
23
24
# File 'lib/simple_navigation/item.rb', line 22

def selected?(current_navigation)
  key == current_navigation
end

#selected_class(current_navigation) ⇒ Object

:nodoc:



36
37
38
# File 'lib/simple_navigation/item.rb', line 36

def selected_class(current_navigation) #:nodoc:
  selected?(current_navigation) ? SimpleNavigation.config.selected_class : nil
end