From ab5f119ac62cdbcc3c9d5c4fd36dafd187b038ca Mon Sep 17 00:00:00 2001 From: Mehdi Lahmam Date: Sun, 15 Feb 2015 21:38:27 +0100 Subject: 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 --- actionview/CHANGELOG.md | 6 ++++++ actionview/lib/action_view/helpers/asset_tag_helper.rb | 1 + actionview/test/template/asset_tag_helper_test.rb | 2 ++ 3 files changed, 9 insertions(+) (limited to 'actionview') 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")) => %(Xml), %(image_tag("rss.gif", :alt => "rss syndication")) => %(rss syndication), %(image_tag("gold.png", :size => "20")) => %(Gold), + %(image_tag("gold.png", :size => 20)) => %(Gold), %(image_tag("gold.png", :size => "45x70")) => %(Gold), %(image_tag("gold.png", "size" => "45x70")) => %(Gold), %(image_tag("error.png", "size" => "45 x 70")) => %(Error), @@ -238,6 +239,7 @@ class AssetTagHelperTest < ActionView::TestCase %(video_tag("gold.m4v", "size" => "320x240")) => %(), %(video_tag("trailer.ogg", :poster => "screenshot.png")) => %(), %(video_tag("error.avi", "size" => "100")) => %(), + %(video_tag("error.avi", "size" => 100)) => %(), %(video_tag("error.avi", "size" => "100 x 100")) => %(), %(video_tag("error.avi", "size" => "x")) => %(), %(video_tag("http://media.rubyonrails.org/video/rails_blog_2.mov")) => %(), -- cgit v1.2.3