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
This commit is contained in:
Jean-Philippe Lang 2008-11-27 18:04:48 +00:00
parent 7a441c1bc4
commit 546b98a118
4 changed files with 32 additions and 17 deletions

View File

@ -106,18 +106,18 @@ Redmine::AccessControl.map do |map|
end
Redmine::MenuManager.map :top_menu do |menu|
menu.push :home, :home_path, :html => { :class => 'home' }
menu.push :my_page, { :controller => 'my', :action => 'page' }, :html => { :class => 'mypage' }, :if => Proc.new { User.current.logged? }
menu.push :projects, { :controller => 'projects', :action => 'index' }, :caption => :label_project_plural, :html => { :class => 'projects' }
menu.push :administration, { :controller => 'admin', :action => 'index' }, :html => { :class => 'admin' }, :if => Proc.new { User.current.admin? }, :last => true
menu.push :help, Redmine::Info.help_url, :html => { :class => 'help' }, :last => true
menu.push :home, :home_path
menu.push :my_page, { :controller => 'my', :action => 'page' }, :if => Proc.new { User.current.logged? }
menu.push :projects, { :controller => 'projects', :action => 'index' }, :caption => :label_project_plural
menu.push :administration, { :controller => 'admin', :action => 'index' }, :if => Proc.new { User.current.admin? }, :last => true
menu.push :help, Redmine::Info.help_url, :last => true
end
Redmine::MenuManager.map :account_menu do |menu|
menu.push :login, :signin_path, :html => { :class => 'login' }, :if => Proc.new { !User.current.logged? }
menu.push :register, { :controller => 'account', :action => 'register' }, :html => { :class => 'register' }, :if => Proc.new { !User.current.logged? && Setting.self_registration? }
menu.push :my_account, { :controller => 'my', :action => 'account' }, :html => { :class => 'myaccount' }, :if => Proc.new { User.current.logged? }
menu.push :logout, :signout_path, :html => { :class => 'logout' }, :if => Proc.new { User.current.logged? }
menu.push :login, :signin_path, :if => Proc.new { !User.current.logged? }
menu.push :register, { :controller => 'account', :action => 'register' }, :if => Proc.new { !User.current.logged? && Setting.self_registration? }
menu.push :my_account, { :controller => 'my', :action => 'account' }, :if => Proc.new { User.current.logged? }
menu.push :logout, :signout_path, :if => Proc.new { User.current.logged? }
end
Redmine::MenuManager.map :application_menu do |menu|

View File

@ -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

View File

@ -26,7 +26,7 @@ h2, h3, h4, .wiki h1, .wiki h2, .wiki h3 { border-bottom: 0px; color:#606060; fo
h2, .wiki h1 { letter-spacing:-1px; }
h4 { border-bottom: dotted 1px #c0c0c0; }
#top-menu a.home, #top-menu a.mypage, #top-menu a.projects, #top-menu a.admin, #top-menu a.help {
#top-menu a.home, #top-menu a.my-page, #top-menu a.projects, #top-menu a.administration, #top-menu a.help {
background-position: 0% 40%;
background-repeat: no-repeat;
padding-left: 20px;
@ -35,7 +35,7 @@ h4 { border-bottom: dotted 1px #c0c0c0; }
}
#top-menu a.home { background-image: url(../../../images/home.png); }
#top-menu a.mypage { background-image: url(../../../images/user_page.png); }
#top-menu a.my-page { background-image: url(../../../images/user_page.png); }
#top-menu a.projects { background-image: url(../../../images/projects.png); }
#top-menu a.admin { background-image: url(../../../images/admin.png); }
#top-menu a.administration { background-image: url(../../../images/admin.png); }
#top-menu a.help { background-image: url(../../../images/help.png); }

View File

@ -234,14 +234,17 @@ class ProjectsControllerTest < Test::Unit::TestCase
get :show, :id => 1
assert_tag :div, :attributes => { :id => 'main-menu' },
:descendant => { :tag => 'li', :child => { :tag => 'a', :content => 'Foo' } }
:descendant => { :tag => 'li', :child => { :tag => 'a', :content => 'Foo',
:attributes => { :class => 'foo' } } }
assert_tag :div, :attributes => { :id => 'main-menu' },
:descendant => { :tag => 'li', :child => { :tag => 'a', :content => 'Bar' },
:descendant => { :tag => 'li', :child => { :tag => 'a', :content => 'Bar',
:attributes => { :class => 'bar' } },
:before => { :tag => 'li', :child => { :tag => 'a', :content => 'ECOOKBOOK' } } }
assert_tag :div, :attributes => { :id => 'main-menu' },
:descendant => { :tag => 'li', :child => { :tag => 'a', :content => 'ECOOKBOOK' },
:descendant => { :tag => 'li', :child => { :tag => 'a', :content => 'ECOOKBOOK',
:attributes => { :class => 'hello' } },
:before => { :tag => 'li', :child => { :tag => 'a', :content => 'Activity' } } }
# Remove the menu items