Module: Redmine::MenuManager::MenuHelper

Defined in:
lib/redmine/menu_manager.rb

Instance Method Summary collapse

Instance Method Details

#current_menu_itemObject

Returns the current menu item name



71
72
73
# File 'lib/redmine/menu_manager.rb', line 71

def current_menu_item
  @controller.current_menu_item
end


89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/redmine/menu_manager.rb', line 89

def menu_items_for(menu, project=nil)
  items = []
  Redmine::MenuManager.allowed_items(menu, User.current, project).each do |item|
    unless item.condition && !item.condition.call(project)
      url = case item.url
      when Hash
        project.nil? ? item.url : {item.param => project}.merge(item.url)
      when Symbol
        send(item.url)
      else
        item.url
      end
      caption = item.caption(project)
      if block_given?
        yield item, caption, url, (current_menu_item == item.name)
      else
        items << [item, caption, url, (current_menu_item == item.name)]
      end
    end
  end
  return block_given? ? nil : items
end

#render_main_menu(project) ⇒ Object

Renders the application main menu



76
77
78
# File 'lib/redmine/menu_manager.rb', line 76

def render_main_menu(project)
  render_menu((project && !project.new_record?) ? :project_menu : :application_menu, project)
end

#render_menu(menu, project = nil) ⇒ Object



80
81
82
83
84
85
86
87
# File 'lib/redmine/menu_manager.rb', line 80

def render_menu(menu, project=nil)
  links = []
  menu_items_for(menu, project) do |item, caption, url, selected|
    links << ('li', 
      link_to(h(caption), url, item.html_options(:selected => selected)))
  end
  links.empty? ? nil : ('ul', links.join("\n"))
end