]> source.dussan.org Git - redmine.git/commitdiff
Make favicon themeable (#15689).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 11 Jan 2014 11:22:46 +0000 (11:22 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 11 Jan 2014 11:22:46 +0000 (11:22 +0000)
Patch by Felix Schäfer modified by Jean-Philippe Lang.

git-svn-id: http://svn.redmine.org/redmine/trunk@12646 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/helpers/application_helper.rb
lib/redmine/themes.rb
test/integration/lib/redmine/themes_test.rb

index cf7c11740fa9fec92fc2e18ba1d554a95e6fbf0f..617a9029bc69d8c674cd6fdcf9ab3bd8c3130cf9 100644 (file)
@@ -1270,7 +1270,8 @@ module ApplicationHelper
   end
 
   def favicon
-    "<link rel='shortcut icon' href='#{image_path('/favicon.ico')}' />".html_safe
+    fav_path = (current_theme && current_theme.favicon?) ? current_theme.favicon_path : '/favicon.ico'
+    "<link rel='shortcut icon' href='#{image_path(fav_path)}' />".html_safe
   end
 
   def robot_exclusion_tag
index eb2ba91515257b7df34de2fb3d24151b4c2f77a1..c69244f7ef52eafdd54f8bf2555ab16d683a3ecf 100644 (file)
@@ -75,6 +75,18 @@ module Redmine
         @javascripts ||= assets("javascripts", "js")
       end
 
+      def favicons
+        @favicons ||= assets("favicon")
+      end
+
+      def favicon
+        favicons.first
+      end
+
+      def favicon?
+        favicon.present?
+      end
+
       def stylesheet_path(source)
         "/themes/#{dir}/stylesheets/#{source}"
       end
@@ -87,6 +99,10 @@ module Redmine
         "/themes/#{dir}/javascripts/#{source}"
       end
 
+      def favicon_path
+        "/themes/#{dir}/favicon/#{favicon}"
+      end
+
       private
 
       def assets(dir, ext=nil)
index 6d286ef10c8ffdc67073c7df4bcba8b692de0e41..da413db351ffa16aa2e26bb9ed231c0463f4e039 100644 (file)
@@ -57,9 +57,40 @@ class ThemesTest < ActionController::IntegrationTest
     @theme.javascripts.delete 'theme'
   end
 
+  def test_use_default_favicon_if_theme_provides_none
+    get '/'
+
+    assert_response :success
+    assert_select 'link[rel=shortcut icon][href^=/favicon.ico]'
+  end
+
+  def test_use_theme_favicon_if_theme_provides_one
+    # Simulate a theme favicon
+    @theme.favicons << 'a.ico'
+    get '/'
+
+    assert_response :success
+    assert_select "link[rel=shortcut icon][href^=/themes/#{@theme.dir}/favicon/a.ico]"
+  ensure
+    @theme.favicons.delete 'a.ico'
+  end
+
+  def test_use_only_one_theme_favicon_if_theme_provides_many
+    @theme.favicons.concat %w{b.ico a.png}
+    get '/'
+
+    assert_response :success
+    assert_select "link[rel=shortcut icon]", 1
+    assert_select "link[rel=shortcut icon][href^=/themes/#{@theme.dir}/favicon/b.ico]"
+  ensure
+    @theme.favicons.delete("b.ico")
+    @theme.favicons.delete("a.png")
+  end
+
   def test_with_sub_uri
     Redmine::Utils.relative_url_root = '/foo'
     @theme.javascripts << 'theme'
+    @theme.favicons << 'a.ico'
     get '/'
 
     assert_response :success
@@ -67,7 +98,7 @@ class ThemesTest < ActionController::IntegrationTest
       :attributes => {:href => %r{^/foo/themes/#{@theme.dir}/stylesheets/application.css}}
     assert_tag :tag => 'script',
       :attributes => {:src => %r{^/foo/themes/#{@theme.dir}/javascripts/theme.js}}
-
+    assert_select "link[rel=shortcut icon][href^=/foo/themes/#{@theme.dir}/favicon/a.ico]"
   ensure
     Redmine::Utils.relative_url_root = ''
   end