diff options
author | Nihad Abbasov <narkoz.2008@gmail.com> | 2012-09-25 18:20:13 +0500 |
---|---|---|
committer | Nihad Abbasov <narkoz.2008@gmail.com> | 2012-09-25 21:47:55 +0500 |
commit | 2b9bce88e12c1e23320a6e4733198d1125939c0d (patch) | |
tree | 7b883c6142528a5eecfd6d16525a5ff4a9afed4e | |
parent | c96b20f8d985c6fa87a8efda7a4884e3c35e5739 (diff) | |
download | rails-2b9bce88e12c1e23320a6e4733198d1125939c0d.tar.gz rails-2b9bce88e12c1e23320a6e4733198d1125939c0d.tar.bz2 rails-2b9bce88e12c1e23320a6e4733198d1125939c0d.zip |
allow to pass numerical value to size option in image_tag
This will set image's both width and height attributes to
value passed in size option.
-rw-r--r-- | actionpack/CHANGELOG.md | 5 | ||||
-rw-r--r-- | actionpack/lib/action_view/helpers/asset_tag_helper.rb | 9 | ||||
-rw-r--r-- | actionpack/test/template/asset_tag_helper_test.rb | 2 |
3 files changed, 11 insertions, 5 deletions
diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md index ceaff1a3f4..248677688f 100644 --- a/actionpack/CHANGELOG.md +++ b/actionpack/CHANGELOG.md @@ -1,5 +1,10 @@ ## Rails 4.0.0 (unreleased) ## +* `image_tag` will set the same width and height for image if numerical value + passed to `size` option. + + *Nihad Abbasov* + * Deprecate Mime::Type#verify_request? and Mime::Type.browser_generated_types, since they are no longer used inside of Rails, they will be removed in Rails 4.1 diff --git a/actionpack/lib/action_view/helpers/asset_tag_helper.rb b/actionpack/lib/action_view/helpers/asset_tag_helper.rb index db4da6f9c8..08efc98a50 100644 --- a/actionpack/lib/action_view/helpers/asset_tag_helper.rb +++ b/actionpack/lib/action_view/helpers/asset_tag_helper.rb @@ -364,9 +364,9 @@ module ActionView # # * <tt>:alt</tt> - If no alt text is given, the file name part of the # +source+ is used (capitalized and without the extension) - # * <tt>:size</tt> - Supplied as "{Width}x{Height}", so "30x45" becomes - # width="30" and height="45". <tt>:size</tt> will be ignored if the - # value is not in the correct format. + # * <tt>:size</tt> - Supplied as "{Width}x{Height}" or "{Number}", so "30x45" becomes + # width="30" and height="45", and "50" becomes width="50" and height="50". + # <tt>:size</tt> will be ignored if the value is not in the correct format. # # image_tag("icon") # # => <img src="/assets/icon" alt="Icon" /> @@ -374,7 +374,7 @@ module ActionView # # => <img src="/assets/icon.png" alt="Icon" /> # image_tag("icon.png", :size => "16x10", :alt => "Edit Entry") # # => <img src="/assets/icon.png" width="16" height="10" alt="Edit Entry" /> - # image_tag("/icons/icon.gif", :size => "16x16") + # image_tag("/icons/icon.gif", :size => "16") # # => <img src="/icons/icon.gif" width="16" height="16" alt="Icon" /> # image_tag("/icons/icon.gif", :height => '32', :width => '32') # # => <img alt="Icon" height="32" src="/icons/icon.gif" width="32" /> @@ -391,6 +391,7 @@ module ActionView if size = options.delete(:size) options[:width], options[:height] = size.split("x") if size =~ %r{^\d+x\d+$} + options[:width] = options[:height] = size if size =~ %r{\A\d+\z} end tag("img", options) diff --git a/actionpack/test/template/asset_tag_helper_test.rb b/actionpack/test/template/asset_tag_helper_test.rb index 25d85c47c7..a04694714d 100644 --- a/actionpack/test/template/asset_tag_helper_test.rb +++ b/actionpack/test/template/asset_tag_helper_test.rb @@ -192,9 +192,9 @@ class AssetTagHelperTest < ActionView::TestCase ImageLinkToTag = { %(image_tag("xml.png")) => %(<img alt="Xml" src="/images/xml.png" />), %(image_tag("rss.gif", :alt => "rss syndication")) => %(<img alt="rss syndication" src="/images/rss.gif" />), + %(image_tag("gold.png", :size => "20")) => %(<img alt="Gold" height="20" src="/images/gold.png" width="20" />), %(image_tag("gold.png", :size => "45x70")) => %(<img alt="Gold" height="70" src="/images/gold.png" width="45" />), %(image_tag("gold.png", "size" => "45x70")) => %(<img alt="Gold" height="70" src="/images/gold.png" width="45" />), - %(image_tag("error.png", "size" => "45")) => %(<img alt="Error" src="/images/error.png" />), %(image_tag("error.png", "size" => "45 x 70")) => %(<img alt="Error" src="/images/error.png" />), %(image_tag("error.png", "size" => "x")) => %(<img alt="Error" src="/images/error.png" />), %(image_tag("google.com.png")) => %(<img alt="Google.com" src="/images/google.com.png" />), |