Make favicon themeable (#15689).
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
This commit is contained in:
parent
2db3338ab2
commit
8b999962de
|
@ -1270,7 +1270,8 @@ module ApplicationHelper
|
||||||
end
|
end
|
||||||
|
|
||||||
def favicon
|
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
|
end
|
||||||
|
|
||||||
def robot_exclusion_tag
|
def robot_exclusion_tag
|
||||||
|
|
|
@ -75,6 +75,18 @@ module Redmine
|
||||||
@javascripts ||= assets("javascripts", "js")
|
@javascripts ||= assets("javascripts", "js")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def favicons
|
||||||
|
@favicons ||= assets("favicon")
|
||||||
|
end
|
||||||
|
|
||||||
|
def favicon
|
||||||
|
favicons.first
|
||||||
|
end
|
||||||
|
|
||||||
|
def favicon?
|
||||||
|
favicon.present?
|
||||||
|
end
|
||||||
|
|
||||||
def stylesheet_path(source)
|
def stylesheet_path(source)
|
||||||
"/themes/#{dir}/stylesheets/#{source}"
|
"/themes/#{dir}/stylesheets/#{source}"
|
||||||
end
|
end
|
||||||
|
@ -87,6 +99,10 @@ module Redmine
|
||||||
"/themes/#{dir}/javascripts/#{source}"
|
"/themes/#{dir}/javascripts/#{source}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def favicon_path
|
||||||
|
"/themes/#{dir}/favicon/#{favicon}"
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def assets(dir, ext=nil)
|
def assets(dir, ext=nil)
|
||||||
|
|
|
@ -57,9 +57,40 @@ class ThemesTest < ActionController::IntegrationTest
|
||||||
@theme.javascripts.delete 'theme'
|
@theme.javascripts.delete 'theme'
|
||||||
end
|
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
|
def test_with_sub_uri
|
||||||
Redmine::Utils.relative_url_root = '/foo'
|
Redmine::Utils.relative_url_root = '/foo'
|
||||||
@theme.javascripts << 'theme'
|
@theme.javascripts << 'theme'
|
||||||
|
@theme.favicons << 'a.ico'
|
||||||
get '/'
|
get '/'
|
||||||
|
|
||||||
assert_response :success
|
assert_response :success
|
||||||
|
@ -67,7 +98,7 @@ class ThemesTest < ActionController::IntegrationTest
|
||||||
:attributes => {:href => %r{^/foo/themes/#{@theme.dir}/stylesheets/application.css}}
|
:attributes => {:href => %r{^/foo/themes/#{@theme.dir}/stylesheets/application.css}}
|
||||||
assert_tag :tag => 'script',
|
assert_tag :tag => 'script',
|
||||||
:attributes => {:src => %r{^/foo/themes/#{@theme.dir}/javascripts/theme.js}}
|
: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
|
ensure
|
||||||
Redmine::Utils.relative_url_root = ''
|
Redmine::Utils.relative_url_root = ''
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue