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
@stylesheets ||= assets("stylesheets", "css")
end
+ def images
+ @images ||= assets("images")
+ end
+
def javascripts
@javascripts ||= assets("javascripts", "js")
end
"/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
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