Browse Source

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
tags/2.0.0
Jean-Philippe Lang 12 years ago
parent
commit
68f8470d4a

+ 4
- 2
app/helpers/application_helper.rb View File

@@ -1065,14 +1065,16 @@ module ApplicationHelper
super sources, options
end

# Overrides Rails' image_tag with plugins support.
# Overrides Rails' image_tag with themes and plugins support.
# 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
#
def image_tag(source, options={})
if plugin = options.delete(:plugin)
source = "/plugin_assets/#{plugin}/images/#{source}"
elsif current_theme && current_theme.images.include?(source)
source = current_theme.image_path(source)
end
super source, options
end

+ 14
- 2
lib/redmine/themes.rb View File

@@ -67,6 +67,10 @@ module Redmine
@stylesheets ||= assets("stylesheets", "css")
end

def images
@images ||= assets("images")
end

def javascripts
@javascripts ||= assets("javascripts", "js")
end
@@ -75,14 +79,22 @@ module Redmine
"/themes/#{dir}/stylesheets/#{source}"
end

def image_path(source)
"/themes/#{dir}/images/#{source}"
end

def javascript_path(source)
"/themes/#{dir}/javascripts/#{source}"
end

private

def assets(dir, ext)
Dir.glob("#{path}/#{dir}/*.#{ext}").collect {|f| File.basename(f).gsub(/\.#{ext}$/, '')}
def assets(dir, ext=nil)
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


+ 12
- 0
test/unit/helpers/application_helper_test.rb View File

@@ -1058,6 +1058,18 @@ RAW
assert_match 'src="/images/image.png"', image_tag("image.png")
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
assert_match 'src="/plugin_assets/foo/images/image.png"', image_tag("image.png", :plugin => :foo)
end

Loading…
Cancel
Save