diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2008-07-13 11:02:42 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2008-07-13 11:02:42 +0000 |
commit | c4eef6314e0e7030d002a2f40f1d4cee993afae6 (patch) | |
tree | 0fae6b8a65999087b80666ae3e14d90e20147321 | |
parent | 591407c5c81028eb3b5feeeabf7474adca626e29 (diff) | |
download | redmine-c4eef6314e0e7030d002a2f40f1d4cee993afae6.tar.gz redmine-c4eef6314e0e7030d002a2f40f1d4cee993afae6.zip |
Menu item caption can be a Proc.
git-svn-id: http://redmine.rubyforge.org/svn/trunk@1659 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r-- | lib/redmine/menu_manager.rb | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/lib/redmine/menu_manager.rb b/lib/redmine/menu_manager.rb index af54b41fe..01c14083e 100644 --- a/lib/redmine/menu_manager.rb +++ b/lib/redmine/menu_manager.rb @@ -80,9 +80,10 @@ module Redmine else item.url end - #url = (project && item.url.is_a?(Hash)) ? {item.param => project}.merge(item.url) : (item.url.is_a?(Symbol) ? send(item.url) : item.url) + caption = item.caption(project) + caption = l(caption) if caption.is_a?(Symbol) links << content_tag('li', - link_to(l(item.caption), url, (current_menu_item == item.name ? item.html_options.merge(:class => 'selected') : item.html_options))) + link_to(h(caption), url, (current_menu_item == item.name ? item.html_options.merge(:class => 'selected') : item.html_options))) end end links.empty? ? nil : content_tag('ul', links.join("\n")) @@ -110,8 +111,11 @@ module Redmine class Mapper # Adds an item at the end of the menu. Available options: # * param: the parameter name that is used for the project id (default is :id) - # * if: a proc that is called before rendering the item, the item is displayed only if it returns true - # * caption: the localized string key that is used as the item label + # * if: a Proc that is called before rendering the item, the item is displayed only if it returns true + # * caption that can be: + # * a localized string Symbol + # * a String + # * a Proc that can take the project as argument # * html_options: a hash of html options that are passed to link_to def push(name, url, options={}) items << MenuItem.new(name, url, options) @@ -133,13 +137,17 @@ module Redmine @url = url @condition = options[:if] @param = options[:param] || :id - @caption_key = options[:caption] + @caption = options[:caption] @html_options = options[:html] || {} end - def caption - # check if localized string exists on first render (after GLoc strings are loaded) - @caption ||= (@caption_key || (l_has_string?("label_#{@name}".to_sym) ? "label_#{@name}".to_sym : @name.to_s.humanize)) + def caption(project=nil) + if @caption.is_a?(Proc) + @caption.call(project) + else + # check if localized string exists on first render (after GLoc strings are loaded) + @caption_key ||= (@caption || (l_has_string?("label_#{@name}".to_sym) ? "label_#{@name}".to_sym : @name.to_s.humanize)) + end end end end |