mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
allow video_tag to accept size
as Number
for square shaped videos
This commit is contained in:
parent
83e4dde41a
commit
cd58745a7d
2 changed files with 11 additions and 5 deletions
|
@ -251,9 +251,9 @@ module ActionView
|
|||
#
|
||||
# * <tt>:poster</tt> - Set an image (like a screenshot) to be shown
|
||||
# before the video loads. The path is calculated like the +src+ of +image_tag+.
|
||||
# * <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.
|
||||
#
|
||||
# ==== Examples
|
||||
#
|
||||
|
@ -267,6 +267,8 @@ module ActionView
|
|||
# # => <video src="/videos/trailer.m4v" width="16" height="10" poster="/assets/screenshot.png" />
|
||||
# video_tag("/trailers/hd.avi", size: "16x16")
|
||||
# # => <video src="/trailers/hd.avi" width="16" height="16" />
|
||||
# video_tag("/trailers/hd.avi", size: "16")
|
||||
# # => <video height="16" src="/trailers/hd.avi" width="16" />
|
||||
# video_tag("/trailers/hd.avi", height: '32', width: '32')
|
||||
# # => <video height="32" src="/trailers/hd.avi" width="32" />
|
||||
# video_tag("trailer.ogg", "trailer.flv")
|
||||
|
@ -280,7 +282,11 @@ module ActionView
|
|||
options[:poster] = path_to_image(options[:poster]) if options[:poster]
|
||||
|
||||
if size = options.delete(:size)
|
||||
options[:width], options[:height] = size.split("x") if size =~ %r{^\d+x\d+$}
|
||||
if size =~ %r{\A\d+x\d+\z}
|
||||
options[:width], options[:height] = size.split('x')
|
||||
elsif size =~ %r{\A\d+\z}
|
||||
options[:width] = options[:height] = size
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -245,7 +245,7 @@ class AssetTagHelperTest < ActionView::TestCase
|
|||
%(video_tag("gold.m4v", :size => "160x120")) => %(<video height="120" src="/videos/gold.m4v" width="160"></video>),
|
||||
%(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 src="/videos/error.avi"></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>),
|
||||
|
|
Loading…
Reference in a new issue