1
+ require 'active_support/core_ext/array/extract_options'
2
+ require 'active_support/core_ext/hash/keys'
1
3
require 'action_view/helpers/asset_tag_helpers/javascript_tag_helpers'
2
4
require 'action_view/helpers/asset_tag_helpers/stylesheet_tag_helpers'
3
5
require 'action_view/helpers/asset_tag_helpers/asset_paths'
@@ -407,25 +409,28 @@ def image_alt(src)
407
409
# <video src="/trailers/hd.avi" width="16" height="16" />
408
410
# video_tag("/trailers/hd.avi", :height => '32', :width => '32') # =>
409
411
# <video height="32" src="/trailers/hd.avi" width="32" />
412
+ # video_tag("trailer.ogg", "trailer.flv") # =>
413
+ # <video><source src="/videos/trailer.ogg" /><source src="/videos/trailer.flv" /></video>
410
414
# video_tag(["trailer.ogg", "trailer.flv"]) # =>
411
- # <video><source src="http://github.com/%3Cspan%20class="x x-first x-last">trailer.ogg" /><source src="http://github.com/%3C/span%3Etrailer.ogg" /><source src="http://github.com/trailer.flv" /></video>
415
+ # <video><source src="http://github.com/%3Cspan%20class="x x-first x-last">/videos/ trailer.ogg" /><source src="http://github.com/%3Cspan%20class="x x-first x-last">/videos/trailer.flv" /></video>
412
416
# video_tag(["trailer.ogg", "trailer.flv"] :size => "160x120") # =>
413
- # <video height="120" width="160"><source src="trailer.ogg" /><source src="trailer.flv" /></video>
414
- def video_tag ( sources , options = { } )
415
- options . symbolize_keys!
417
+ # <video height="120" width="160"><source src="/videos/trailer.ogg" /><source src="/videos/trailer.flv" /></video>
418
+ def video_tag ( *sources )
419
+ options = sources . extract_options! . symbolize_keys!
420
+ sources . flatten!
416
421
417
422
options [ :poster ] = path_to_image ( options [ :poster ] ) if options [ :poster ]
418
423
419
424
if size = options . delete ( :size )
420
425
options [ :width ] , options [ :height ] = size . split ( "x" ) if size =~ %r{^\d +x\d +$}
421
426
end
422
427
423
- if sources . is_a? ( Array )
428
+ if sources . size > 1
424
429
content_tag ( "video" , options ) do
425
- sources . map { |source | tag ( "source" , :src => path_to_video ( source ) ) } . join . html_safe
430
+ safe_join sources . map { |source | tag ( "source" , :src => path_to_video ( source ) ) }
426
431
end
427
432
else
428
- options [ :src ] = path_to_video ( sources )
433
+ options [ :src ] = path_to_video ( sources . first )
429
434
tag ( "video" , options )
430
435
end
431
436
end
@@ -441,15 +446,18 @@ def video_tag(sources, options = {})
441
446
# <audio src="/audios/sound.wav" />
442
447
# audio_tag("sound.wav", :autoplay => true, :controls => true) # =>
443
448
# <audio autoplay="autoplay" controls="controls" src="/audios/sound.wav" />
444
- def audio_tag ( sources , options = { } )
445
- options . symbolize_keys!
449
+ # audio_tag("sound.wav", "sound.mid") # =>
450
+ # <audio><source src="/audios/sound.wav" /><source src="/audios/sound.mid" /></audio>
451
+ def audio_tag ( *sources )
452
+ options = sources . extract_options! . symbolize_keys!
453
+ sources . flatten!
446
454
447
- if sources . is_a? ( Array )
455
+ if sources . size > 1
448
456
content_tag ( "audio" , options ) do
449
- sources . collect { |source | tag ( "source" , :src => path_to_audio ( source ) ) } . join . html_safe
457
+ safe_join sources . collect { |source | tag ( "source" , :src => path_to_audio ( source ) ) }
450
458
end
451
459
else
452
- options [ :src ] = path_to_audio ( sources )
460
+ options [ :src ] = path_to_audio ( sources . first )
453
461
tag ( "audio" , options )
454
462
end
455
463
end
0 commit comments