Module: SimpleNavigation::Helper

Defined in:
lib/simple_navigation.rb

Overview

Simple Navigation helper methods module

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#current_menu_idObject

Returns the value of attribute current_menu_id.



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

def current_menu_id
  @current_menu_id
end

#custom_titlesObject

Returns the value of attribute custom_titles.



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

def custom_titles
  @custom_titles
end

Instance Method Details

#simple_navigation(name, options = {}) ⇒ Object

Renders simple navigation menu by key name



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/simple_navigation.rb', line 9

def simple_navigation(name, options = {})

  # Load navigation hash
  navigation = SimpleNavigation::Builder.navigation[name.to_sym]

  # Reset current menu
  self.current_menu_id = nil

  settings = {
    :id            => navigation[:id],
    :class         => options[:class] || 'simple_navigation',
  }

  self.custom_titles = options[:custom_titles] || {}

  # Set CSS class that user may added
  if navigation.has_key?(:options) && navigation[:options].has_key?(:class)
    settings[:class] << " #{navigation[:options][:class]}"
  end

  # Render root menus
  if navigation.has_key?(:menus) && !navigation[:menus].empty?
    menus = navigation[:menus].enum_with_index.collect do |item, index|
      item_options = { :class => item[:options][:class].clone || '' }
      item_options[:class] << ' first' if index == 0
      item_options[:class] << ' last'  if index == navigation[:menus].size - 1
      render_menu(item, item_options)
    end
  end

  (:ul, menus || '', settings)

end