summaryrefslogtreecommitdiffstats
path: root/lib/redmine
diff options
context:
space:
mode:
Diffstat (limited to 'lib/redmine')
-rw-r--r--lib/redmine/menu_manager.rb16
1 files changed, 14 insertions, 2 deletions
diff --git a/lib/redmine/menu_manager.rb b/lib/redmine/menu_manager.rb
index b09e5150a..f8fc5dd8d 100644
--- a/lib/redmine/menu_manager.rb
+++ b/lib/redmine/menu_manager.rb
@@ -72,7 +72,7 @@ module Redmine
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)))
+ link_to(h(caption), url, item.html_options(:selected => selected)))
end
links.empty? ? nil : content_tag('ul', links.join("\n"))
end
@@ -168,7 +168,7 @@ module Redmine
class MenuItem
include GLoc
- attr_reader :name, :url, :param, :condition, :html_options
+ attr_reader :name, :url, :param, :condition
def initialize(name, url, options)
raise "Invalid option :if for menu item '#{name}'" if options[:if] && !options[:if].respond_to?(:call)
@@ -179,6 +179,8 @@ module Redmine
@param = options[:param] || :id
@caption = options[:caption]
@html_options = options[:html] || {}
+ # Adds a unique class to each menu item based on its name
+ @html_options[:class] = [@html_options[:class], @name.to_s.dasherize].compact.join(' ')
end
def caption(project=nil)
@@ -191,6 +193,16 @@ module Redmine
@caption_key ||= (@caption || (l_has_string?("label_#{@name}".to_sym) ? "label_#{@name}".to_sym : @name.to_s.humanize))
end
end
+
+ def html_options(options={})
+ if options[:selected]
+ o = @html_options.dup
+ o[:class] += ' selected'
+ o
+ else
+ @html_options
+ end
+ end
end
end
end