diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2008-11-27 18:04:48 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2008-11-27 18:04:48 +0000 |
commit | 546b98a1186dc070abff388b7baa20d27b9d8278 (patch) | |
tree | 6b97cc0e996b0e46ab93c872df053c9cc618a0b7 /lib/redmine | |
parent | 7a441c1bc4a2a9415b0d306f763d54fda43ce176 (diff) | |
download | redmine-546b98a1186dc070abff388b7baa20d27b9d8278.tar.gz redmine-546b98a1186dc070abff388b7baa20d27b9d8278.zip |
Adds a css class on menu items in order to apply item specific styles (eg. icons).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2059 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'lib/redmine')
-rw-r--r-- | lib/redmine/menu_manager.rb | 16 |
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 |