diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2008-11-11 18:10:21 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2008-11-11 18:10:21 +0000 |
commit | d7718470785c67aaede689a3651dfe2b2fd53bfb (patch) | |
tree | b90d7f07bee68e78f257d2963c13214bc26cf4f5 /lib/redmine/menu_manager.rb | |
parent | 3f4defe48215c460933343fffdb6888603e62492 (diff) | |
download | redmine-d7718470785c67aaede689a3651dfe2b2fd53bfb.tar.gz redmine-d7718470785c67aaede689a3651dfe2b2fd53bfb.zip |
Pluggable admin menu (patch #2031 by Yuki Sonoda with slight changes).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2022 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'lib/redmine/menu_manager.rb')
-rw-r--r-- | lib/redmine/menu_manager.rb | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/lib/redmine/menu_manager.rb b/lib/redmine/menu_manager.rb index 730097d74..b09e5150a 100644 --- a/lib/redmine/menu_manager.rb +++ b/lib/redmine/menu_manager.rb @@ -70,6 +70,15 @@ module Redmine def render_menu(menu, project=nil) links = [] + menu_items_for(menu, project) do |item, caption, url, selected| + links << content_tag('li', + link_to(h(caption), url, (selected ? item.html_options.merge(:class => 'selected') : item.html_options))) + end + links.empty? ? nil : content_tag('ul', links.join("\n")) + end + + 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 @@ -82,11 +91,14 @@ module Redmine end caption = item.caption(project) caption = l(caption) if caption.is_a?(Symbol) - links << content_tag('li', - link_to(h(caption), url, (current_menu_item == item.name ? item.html_options.merge(:class => 'selected') : item.html_options))) + 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 - links.empty? ? nil : content_tag('ul', links.join("\n")) + return block_given? ? nil : items end end |