diff options
author | Mehdi Lahmam <mehdi@craftsmen.io> | 2015-02-15 21:38:27 +0100 |
---|---|---|
committer | Mehdi Lahmam <mehdi@craftsmen.io> | 2015-02-16 12:58:34 +0100 |
commit | ab5f119ac62cdbcc3c9d5c4fd36dafd187b038ca (patch) | |
tree | d112b9e216513e3aad6f8b161f432bbcd918252a /actionview | |
parent | 1747c4e2cea811cbf04fccc9f57256c80112d9ce (diff) | |
download | rails-ab5f119ac62cdbcc3c9d5c4fd36dafd187b038ca.tar.gz rails-ab5f119ac62cdbcc3c9d5c4fd36dafd187b038ca.tar.bz2 rails-ab5f119ac62cdbcc3c9d5c4fd36dafd187b038ca.zip |
Allow to pass a string value to size option in `image_tag` and `video_tag`
This makes the behavior more consistent with `width` or `height` options
Diffstat (limited to 'actionview')
-rw-r--r-- | actionview/CHANGELOG.md | 6 | ||||
-rw-r--r-- | actionview/lib/action_view/helpers/asset_tag_helper.rb | 1 | ||||
-rw-r--r-- | actionview/test/template/asset_tag_helper_test.rb | 2 |
3 files changed, 9 insertions, 0 deletions
diff --git a/actionview/CHANGELOG.md b/actionview/CHANGELOG.md index 7fc32a3b5c..f227275941 100644 --- a/actionview/CHANGELOG.md +++ b/actionview/CHANGELOG.md @@ -1,3 +1,9 @@ +* Allow to pass a string value to `size` option in `image_tag` and `video_tag` + + This makes the behavior more consistent with `width` or `height` options. + + *Mehdi Lahmam* + * Partial template name does no more have to be a valid Ruby identifier. There used to be a naming rule that the partial name should start with diff --git a/actionview/lib/action_view/helpers/asset_tag_helper.rb b/actionview/lib/action_view/helpers/asset_tag_helper.rb index b7fdc16a9d..5c28043f8a 100644 --- a/actionview/lib/action_view/helpers/asset_tag_helper.rb +++ b/actionview/lib/action_view/helpers/asset_tag_helper.rb @@ -318,6 +318,7 @@ module ActionView end def extract_dimensions(size) + size = size.to_s if size =~ %r{\A\d+x\d+\z} size.split('x') elsif size =~ %r{\A\d+\z} diff --git a/actionview/test/template/asset_tag_helper_test.rb b/actionview/test/template/asset_tag_helper_test.rb index dac1c7024d..a15c6fac90 100644 --- a/actionview/test/template/asset_tag_helper_test.rb +++ b/actionview/test/template/asset_tag_helper_test.rb @@ -180,6 +180,7 @@ class AssetTagHelperTest < ActionView::TestCase %(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 => 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 x 70")) => %(<img alt="Error" src="/images/error.png" />), @@ -238,6 +239,7 @@ class AssetTagHelperTest < ActionView::TestCase %(video_tag("gold.m4v", "size" => "320x240")) => %(<video height="240" src="/videos/gold.m4v" width="320"></video>), %(video_tag("trailer.ogg", :poster => "screenshot.png")) => %(<video poster="/images/screenshot.png" src="/videos/trailer.ogg"></video>), %(video_tag("error.avi", "size" => "100")) => %(<video height="100" src="/videos/error.avi" width="100"></video>), + %(video_tag("error.avi", "size" => 100)) => %(<video height="100" src="/videos/error.avi" width="100"></video>), %(video_tag("error.avi", "size" => "100 x 100")) => %(<video src="/videos/error.avi"></video>), %(video_tag("error.avi", "size" => "x")) => %(<video src="/videos/error.avi"></video>), %(video_tag("http://media.rubyonrails.org/video/rails_blog_2.mov")) => %(<video src="http://media.rubyonrails.org/video/rails_blog_2.mov"></video>), |