Module: AlacarteHelper

Defined in:
app/helpers/alacarte_helper.rb

Instance Method Summary collapse

Instance Method Details

#elements_for(menu, current_element) ⇒ Object



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
# File 'app/helpers/alacarte_helper.rb', line 13

def elements_for(menu, current_element)
  result = ''
  
  menu.items.each do |item|
    if item.valid?
      _html_options = item.html_options || {}
      _html_options[:class] = _html_options[:class].to_s.insert(0, 'active ').strip if (current_element == item.as)
    
      _item = case item.type
        when :link
          _path = item.path.respond_to?(:call) ? item.path.call : item.path
          link_to(item.label.html_safe, _path, _html_options)
        when :text
          item.label.html_safe
        else
          (item.type, item.label, _html_options)
      end
      
      if item.items.size > 0
        _item << elements_for(item, current_element)
      end
    
      result << (:li, _item, item.wrapper_options)
    end
  end
  
  result.blank? ? '' : (:ul, result.html_safe, menu.group_options)
end


3
4
5
6
7
8
9
10
11
# File 'app/helpers/alacarte_helper.rb', line 3

def navigation_for(menu, current_element = nil)
  current_element = controller_name if current_element.blank?
  
  if current_menu = Alacarte.menus[menu]
    current_menu.build(self)
    
    return elements_for(current_menu, current_element.to_sym)
  end
end