mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
Adds a audio_tag helper for the HTML5 audio tag. Fixed video_path docs. HTML attributes values should be true or false not attribute's name. [#2864 state:resolved]
Signed-off-by: Yehuda Katz <wycats@yehuda-katzs-macbookpro41.local>
This commit is contained in:
committed by
Yehuda Katz
parent
61604feec0
commit
1e2d722960
@@ -462,12 +462,27 @@ module ActionView
|
||||
# video_path("hd") # => /videos/hd
|
||||
# video_path("hd.avi") # => /videos/hd.avi
|
||||
# video_path("trailers/hd.avi") # => /videos/trailers/hd.avi
|
||||
# video_path("/trailers/hd.avi") # => /videos/hd.avi
|
||||
# video_path("/trailers/hd.avi") # => /trailers/hd.avi
|
||||
# video_path("http://www.railsapplication.com/vid/hd.avi") # => http://www.railsapplication.com/vid/hd.avi
|
||||
def video_path(source)
|
||||
compute_public_path(source, 'videos')
|
||||
end
|
||||
alias_method :path_to_video, :video_path # aliased to avoid conflicts with an video_path named route
|
||||
alias_method :path_to_video, :video_path # aliased to avoid conflicts with a video_path named route
|
||||
|
||||
# Computes the path to an audio asset in the public audios directory.
|
||||
# Full paths from the document root will be passed through.
|
||||
# Used internally by +audio_tag+ to build the audio path.
|
||||
#
|
||||
# ==== Examples
|
||||
# audio_path("horse") # => /audios/horse
|
||||
# audio_path("horse.wav") # => /audios/horse.avi
|
||||
# audio_path("sounds/horse.wav") # => /audios/sounds/horse.avi
|
||||
# audio_path("/sounds/horse.wav") # => /sounds/horse.avi
|
||||
# audio_path("http://www.railsapplication.com/sounds/horse.wav") # => http://www.railsapplication.com/sounds/horse.wav
|
||||
def audio_path(source)
|
||||
compute_public_path(source, 'audios')
|
||||
end
|
||||
alias_method :path_to_audio, :audio_path # aliased to avoid conflicts with an audio_path named route
|
||||
|
||||
# Returns an html image tag for the +source+. The +source+ can be a full
|
||||
# path or a file that exists in your public images directory.
|
||||
@@ -542,7 +557,7 @@ module ActionView
|
||||
# video_tag("trailer.ogg") # =>
|
||||
# <video src="/videos/trailer.ogg" />
|
||||
# video_tag("trailer.ogg", :controls => true, :autobuffer => true) # =>
|
||||
# <video autobuffer="autobuffer" controls="controls" src="/videos/trailer.ogg" />
|
||||
# <video autobuffer="true" controls="true" src="/videos/trailer.ogg" />
|
||||
# video_tag("trailer.m4v", :size => "16x10", :poster => "screenshot.png") # =>
|
||||
# <video src="/videos/trailer.m4v" width="16" height="10" poster="/images/screenshot.png" />
|
||||
# video_tag("/trailers/hd.avi", :size => "16x16") # =>
|
||||
@@ -572,6 +587,23 @@ module ActionView
|
||||
end
|
||||
end
|
||||
|
||||
# Returns an html audio tag for the +source+.
|
||||
# The +source+ can be full path or file that exists in
|
||||
# your public audios directory.
|
||||
#
|
||||
# ==== Examples
|
||||
# audio_tag("sound") # =>
|
||||
# <audio src="/audios/sound" />
|
||||
# audio_tag("sound.wav") # =>
|
||||
# <audio src="/audios/sound.wav" />
|
||||
# audio_tag("sound.wav", :autoplay => true, :controls => true) # =>
|
||||
# <audio autoplay="autoplay" controls="controls" src="/audios/sound.wav" />
|
||||
def audio_tag(source, options = {})
|
||||
options.symbolize_keys!
|
||||
options[:src] = path_to_audio(source)
|
||||
tag("audio", options)
|
||||
end
|
||||
|
||||
def self.cache_asset_timestamps
|
||||
@@cache_asset_timestamps
|
||||
end
|
||||
|
||||
@@ -8,8 +8,7 @@ module ActionView
|
||||
module TagHelper
|
||||
include ERB::Util
|
||||
|
||||
BOOLEAN_ATTRIBUTES = %w(disabled readonly multiple checked autobuffer
|
||||
autoplay controls loop).to_set
|
||||
BOOLEAN_ATTRIBUTES = %w(disabled readonly multiple checked).to_set
|
||||
BOOLEAN_ATTRIBUTES.merge(BOOLEAN_ATTRIBUTES.map {|attr| attr.to_sym })
|
||||
|
||||
# Returns an empty HTML tag of type +name+ which by default is XHTML
|
||||
|
||||
@@ -158,8 +158,8 @@ class AssetTagHelperTest < ActionView::TestCase
|
||||
|
||||
VideoLinkToTag = {
|
||||
%(video_tag("xml.ogg")) => %(<video src="/videos/xml.ogg" />),
|
||||
%(video_tag("rss.m4v", :autoplay => true, :controls => true)) => %(<video autoplay="autoplay" controls="controls" src="/videos/rss.m4v" />),
|
||||
%(video_tag("rss.m4v", :autobuffer => true)) => %(<video autobuffer="autobuffer" src="/videos/rss.m4v" />),
|
||||
%(video_tag("rss.m4v", :autoplay => true, :controls => true)) => %(<video autoplay="true" controls="true" src="/videos/rss.m4v" />),
|
||||
%(video_tag("rss.m4v", :autobuffer => true)) => %(<video autobuffer="true" src="/videos/rss.m4v" />),
|
||||
%(video_tag("gold.m4v", :size => "160x120")) => %(<video height="120" src="/videos/gold.m4v" width="160" />),
|
||||
%(video_tag("gold.m4v", "size" => "320x240")) => %(<video height="240" src="/videos/gold.m4v" width="320" />),
|
||||
%(video_tag("trailer.ogg", :poster => "screenshot.png")) => %(<video poster="/images/screenshot.png" src="/videos/trailer.ogg" />),
|
||||
@@ -168,7 +168,27 @@ class AssetTagHelperTest < ActionView::TestCase
|
||||
%(video_tag("error.avi", "size" => "x")) => %(<video src="/videos/error.avi" />),
|
||||
%(video_tag("http://media.rubyonrails.org/video/rails_blog_2.mov")) => %(<video src="http://media.rubyonrails.org/video/rails_blog_2.mov" />),
|
||||
%(video_tag(["multiple.ogg", "multiple.avi"])) => %(<video><source src="multiple.ogg" /><source src="multiple.avi" /></video>),
|
||||
%(video_tag(["multiple.ogg", "multiple.avi"], :size => "160x120", :controls => true)) => %(<video controls="controls" height="120" width="160"><source src="multiple.ogg" /><source src="multiple.avi" /></video>)
|
||||
%(video_tag(["multiple.ogg", "multiple.avi"], :size => "160x120", :controls => true)) => %(<video controls="true" height="120" width="160"><source src="multiple.ogg" /><source src="multiple.avi" /></video>)
|
||||
}
|
||||
|
||||
AudioPathToTag = {
|
||||
%(audio_path("xml")) => %(/audios/xml),
|
||||
%(audio_path("xml.wav")) => %(/audios/xml.wav),
|
||||
%(audio_path("dir/xml.wav")) => %(/audios/dir/xml.wav),
|
||||
%(audio_path("/dir/xml.wav")) => %(/dir/xml.wav)
|
||||
}
|
||||
|
||||
PathToAudioToTag = {
|
||||
%(path_to_audio("xml")) => %(/audios/xml),
|
||||
%(path_to_audio("xml.wav")) => %(/audios/xml.wav),
|
||||
%(path_to_audio("dir/xml.wav")) => %(/audios/dir/xml.wav),
|
||||
%(path_to_audio("/dir/xml.wav")) => %(/dir/xml.wav)
|
||||
}
|
||||
|
||||
AudioLinkToTag = {
|
||||
%(audio_tag("xml.wav")) => %(<audio src="/audios/xml.wav" />),
|
||||
%(audio_tag("rss.wav", :autoplay => true, :controls => true)) => %(<audio autoplay="true" controls="true" src="/audios/rss.wav" />),
|
||||
%(audio_tag("http://media.rubyonrails.org/audio/rails_blog_2.mov")) => %(<audio src="http://media.rubyonrails.org/audio/rails_blog_2.mov" />),
|
||||
}
|
||||
|
||||
def test_auto_discovery_link_tag
|
||||
@@ -311,6 +331,18 @@ class AssetTagHelperTest < ActionView::TestCase
|
||||
VideoLinkToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
|
||||
end
|
||||
|
||||
def test_audio_path
|
||||
AudioPathToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
|
||||
end
|
||||
|
||||
def test_path_to_audio_alias_for_audio_path
|
||||
PathToAudioToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
|
||||
end
|
||||
|
||||
def test_audio_tag
|
||||
AudioLinkToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
|
||||
end
|
||||
|
||||
def test_timebased_asset_id
|
||||
expected_time = File.stat(File.expand_path(File.dirname(__FILE__) + "/../fixtures/public/images/rails.png")).mtime.to_i.to_s
|
||||
assert_equal %(<img alt="Rails" src="/images/rails.png?#{expected_time}" />), image_tag("rails.png")
|
||||
@@ -354,7 +386,7 @@ class AssetTagHelperTest < ActionView::TestCase
|
||||
"#{request.protocol}assets#{source.length}.example.com"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
ActionController::Base.perform_caching = true
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user