Permalink
Browse files

Add video tag helper

hanami/hanami#396

This commit exposes a `video` method to the view
which can be used to generate HTML5 video tags.
It accepts options to generate HTML attributes along
with a block for creating fallback content and/or
`source` and `track` tags.
  • Loading branch information...
leighhalliday authored and jodosha committed Dec 1, 2015
1 parent 0d35cf3 commit d2cf740c80a8643f5d8d87dbaf020c18a0502fa9
Showing with 43 additions and 0 deletions.
  1. +43 −0 asset_tag_helpers_test.rb
View
@@ -27,4 +27,47 @@ def initialize(params)
view.image('application.jpg', 'data-user-id' => 5).to_s.must_equal %(<img data-user-id=\"5\" src=\"/assets/application.jpg\" alt=\"Application\">)
end
end
describe '#video' do
it 'renders' do
tag = view.video('movie.mp4')
tag.to_s.must_equal %(<video src="/assets/movie.mp4"></video>)
end
it 'renders with html attributes' do
tag = view.video('movie.mp4', autoplay: true, controls: true)
tag.to_s.must_equal %(<video autoplay="autoplay" controls="controls" src="/assets/movie.mp4"></video>)
end
it 'renders with fallback content' do
tag = view.video('movie.mp4') do
"Your browser does not support the video tag"
end
tag.to_s.must_equal %(<video src="/assets/movie.mp4">\nYour browser does not support the video tag\n</video>)
end
it 'renders with tracks' do
tag = view.video('movie.mp4') do
track kind: 'captions', src: view.asset_path('movie.en.vtt'), srclang: 'en', label: 'English'
end
tag.to_s.must_equal %(<video src="/assets/movie.mp4">\n<track kind="captions" src="/assets/movie.en.vtt" srclang="en" label="English">\n</video>)
end
it 'renders with sources' do
tag = view.video do
text "Your browser does not support the video tag"
source src: view.asset_path('movie.mp4'), type: 'video/mp4'
source src: view.asset_path('movie.ogg'), type: 'video/ogg'
end
tag.to_s.must_equal %(<video>\nYour browser does not support the video tag\n<source src="/assets/movie.mp4" type="video/mp4">\n<source src="/assets/movie.ogg" type="video/ogg">\n</video>)
end
it 'raises an exception when no arguments' do
-> {view.video()}.must_raise ArgumentError
end
it 'raises an exception when no src and no block' do
-> {view.video(content: true)}.must_raise ArgumentError
end
end
end

0 comments on commit d2cf740

Please sign in to comment.