Makes image_tag pick the image from the current theme if it exists.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@9560 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
da43f785be
commit
68f8470d4a
|
@ -1065,14 +1065,16 @@ module ApplicationHelper
|
||||||
super sources, options
|
super sources, options
|
||||||
end
|
end
|
||||||
|
|
||||||
# Overrides Rails' image_tag with plugins support.
|
# Overrides Rails' image_tag with themes and plugins support.
|
||||||
# Examples:
|
# Examples:
|
||||||
# image_tag('image.png') # => picks defaults image.png
|
# image_tag('image.png') # => picks image.png from the current theme or defaults
|
||||||
# image_tag('image.png', :plugin => 'foo) # => picks image.png from plugin's assets
|
# image_tag('image.png', :plugin => 'foo) # => picks image.png from plugin's assets
|
||||||
#
|
#
|
||||||
def image_tag(source, options={})
|
def image_tag(source, options={})
|
||||||
if plugin = options.delete(:plugin)
|
if plugin = options.delete(:plugin)
|
||||||
source = "/plugin_assets/#{plugin}/images/#{source}"
|
source = "/plugin_assets/#{plugin}/images/#{source}"
|
||||||
|
elsif current_theme && current_theme.images.include?(source)
|
||||||
|
source = current_theme.image_path(source)
|
||||||
end
|
end
|
||||||
super source, options
|
super source, options
|
||||||
end
|
end
|
||||||
|
|
|
@ -67,6 +67,10 @@ module Redmine
|
||||||
@stylesheets ||= assets("stylesheets", "css")
|
@stylesheets ||= assets("stylesheets", "css")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def images
|
||||||
|
@images ||= assets("images")
|
||||||
|
end
|
||||||
|
|
||||||
def javascripts
|
def javascripts
|
||||||
@javascripts ||= assets("javascripts", "js")
|
@javascripts ||= assets("javascripts", "js")
|
||||||
end
|
end
|
||||||
|
@ -75,14 +79,22 @@ module Redmine
|
||||||
"/themes/#{dir}/stylesheets/#{source}"
|
"/themes/#{dir}/stylesheets/#{source}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def image_path(source)
|
||||||
|
"/themes/#{dir}/images/#{source}"
|
||||||
|
end
|
||||||
|
|
||||||
def javascript_path(source)
|
def javascript_path(source)
|
||||||
"/themes/#{dir}/javascripts/#{source}"
|
"/themes/#{dir}/javascripts/#{source}"
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def assets(dir, ext)
|
def assets(dir, ext=nil)
|
||||||
Dir.glob("#{path}/#{dir}/*.#{ext}").collect {|f| File.basename(f).gsub(/\.#{ext}$/, '')}
|
if ext
|
||||||
|
Dir.glob("#{path}/#{dir}/*.#{ext}").collect {|f| File.basename(f).gsub(/\.#{ext}$/, '')}
|
||||||
|
else
|
||||||
|
Dir.glob("#{path}/#{dir}/*").collect {|f| File.basename(f)}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1058,6 +1058,18 @@ RAW
|
||||||
assert_match 'src="/images/image.png"', image_tag("image.png")
|
assert_match 'src="/images/image.png"', image_tag("image.png")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_image_tag_should_pick_the_theme_image_if_it_exists
|
||||||
|
theme = Redmine::Themes.themes.last
|
||||||
|
theme.images << 'image.png'
|
||||||
|
|
||||||
|
with_settings :ui_theme => theme.id do
|
||||||
|
assert_match %|src="/themes/#{theme.dir}/images/image.png"|, image_tag("image.png")
|
||||||
|
assert_match %|src="/images/other.png"|, image_tag("other.png")
|
||||||
|
end
|
||||||
|
ensure
|
||||||
|
theme.images.delete 'image.png'
|
||||||
|
end
|
||||||
|
|
||||||
def test_image_tag_sfor_plugin_should_pick_the_plugin_image
|
def test_image_tag_sfor_plugin_should_pick_the_plugin_image
|
||||||
assert_match 'src="/plugin_assets/foo/images/image.png"', image_tag("image.png", :plugin => :foo)
|
assert_match 'src="/plugin_assets/foo/images/image.png"', image_tag("image.png", :plugin => :foo)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue