@@ -416,22 +416,12 @@ def image_alt(src)
416
416
# video_tag(["trailer.ogg", "trailer.flv"] :size => "160x120") # =>
417
417
# <video height="120" width="160"><source src="/videos/trailer.ogg" /><source src="/videos/trailer.flv" /></video>
418
418
def video_tag ( *sources )
419
- options = sources . extract_options! . symbolize_keys!
420
- sources . flatten!
419
+ multiple_sources_tag ( 'video' , sources ) do | options |
420
+ options [ :poster ] = path_to_image ( options [ :poster ] ) if options [ :poster ]
421
421
422
- options [ :poster ] = path_to_image ( options [ :poster ] ) if options [ :poster ]
423
-
424
- if size = options . delete ( :size )
425
- options [ :width ] , options [ :height ] = size . split ( "x" ) if size =~ %r{^\d +x\d +$}
426
- end
427
-
428
- if sources . size > 1
429
- content_tag ( "video" , options ) do
430
- safe_join sources . map { |source | tag ( "source" , :src => path_to_video ( source ) ) }
422
+ if size = options . delete ( :size )
423
+ options [ :width ] , options [ :height ] = size . split ( "x" ) if size =~ %r{^\d +x\d +$}
431
424
end
432
- else
433
- options [ :src ] = path_to_video ( sources . first )
434
- tag ( "video" , options )
435
425
end
436
426
end
437
427
@@ -449,24 +439,30 @@ def video_tag(*sources)
449
439
# audio_tag("sound.wav", "sound.mid") # =>
450
440
# <audio><source src="/audios/sound.wav" /><source src="/audios/sound.mid" /></audio>
451
441
def audio_tag ( *sources )
452
- options = sources . extract_options! . symbolize_keys!
453
- sources . flatten!
454
-
455
- if sources . size > 1
456
- content_tag ( "audio" , options ) do
457
- safe_join sources . collect { |source | tag ( "source" , :src => path_to_audio ( source ) ) }
458
- end
459
- else
460
- options [ :src ] = path_to_audio ( sources . first )
461
- tag ( "audio" , options )
462
- end
442
+ multiple_sources_tag ( 'audio' , sources )
463
443
end
464
444
465
445
private
466
446
467
447
def asset_paths
468
448
@asset_paths ||= AssetTagHelper ::AssetPaths . new ( config , controller )
469
449
end
450
+
451
+ def multiple_sources_tag ( type , sources )
452
+ options = sources . extract_options! . dup . symbolize_keys!
453
+ sources . flatten!
454
+
455
+ yield options if block_given?
456
+
457
+ if sources . size > 1
458
+ content_tag ( type , options ) do
459
+ safe_join sources . map { |source | tag ( "source" , :src => send ( "path_to_#{ type } " , source ) ) }
460
+ end
461
+ else
462
+ options [ :src ] = send ( "path_to_#{ type } " , sources . first )
463
+ tag ( type , options )
464
+ end
465
+ end
470
466
end
471
467
end
472
468
end
0 commit comments