]> source.dussan.org Git - redmine.git/commitdiff
Adds a css class on menu items in order to apply item specific styles (eg. icons).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Thu, 27 Nov 2008 18:04:48 +0000 (18:04 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Thu, 27 Nov 2008 18:04:48 +0000 (18:04 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2059 e93f8b46-1217-0410-a6f0-8f06a7374b81

lib/redmine.rb
lib/redmine/menu_manager.rb
public/themes/classic/stylesheets/application.css
test/functional/projects_controller_test.rb

index 45cfcbddf4f8208815cc3a58a334efc5e48b041a..42b074a511419c8dad7681724859d55b0dee88e7 100644 (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|
index b09e5150a13322d5830628fba5b2132c261cfc8c..f8fc5dd8d9234051ea4c00cc44f16c092507c12f 100644 (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
index 57f911da6e7e41845be565c8922a4710fc0b1146..280b86eddd3372f58f3a0c9121f6d554469ee144 100644 (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); }
index 371bd834fcaba02a475c7869f3059be672a752ba..1b36a9d6b714a4d1ab9191038e6de0113b9f35b1 100644 (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