]> source.dussan.org Git - redmine.git/commitdiff
Adds support for :plugin option to image_tag helper.
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 28 Apr 2012 09:18:12 +0000 (09:18 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 28 Apr 2012 09:18:12 +0000 (09:18 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@9559 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/helpers/application_helper.rb
test/unit/helpers/application_helper_test.rb

index 743bc34e3aca333eddbcafa5732cb9fb202871f7..f54a85a02cdf2dcf61d482b8bfcdbf0df8f616cc 100644 (file)
@@ -1065,6 +1065,18 @@ module ApplicationHelper
     super sources, options
   end
 
+  # Overrides Rails' image_tag with plugins support.
+  # Examples:
+  #   image_tag('image.png') # => picks defaults image.png
+  #   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}"
+    end
+    super source, options
+  end
+
   # Overrides Rails' javascript_include_tag with plugins support
   # Examples:
   #   javascript_include_tag('scripts') # => picks scripts.js from defaults
index f09d6664631381df77d84fd0faf75f47f3a03884..9bf25e605a3268f1ed3a8087006cecd3382a31ab 100644 (file)
@@ -1054,6 +1054,14 @@ RAW
     assert_match 'href="/plugin_assets/foo/stylesheets/styles.css"', stylesheet_link_tag("styles", :plugin => :foo)
   end
 
+  def test_image_tag_should_pick_the_default_image
+    assert_match 'src="/images/image.png"', image_tag("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
+
   def test_javascript_include_tag_should_pick_the_default_javascript
     assert_match 'src="/javascripts/scripts.js"', javascript_include_tag("scripts")
   end