summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Allen <dan.j.allen@gmail.com>2013-08-25 00:55:45 -0600
committerDan Allen <dan.j.allen@gmail.com>2013-08-25 00:57:40 -0600
commit7d5bd9099ad4939bc32686c49e6d875c2212e927 (patch)
tree8484ffb830e0418762235eb7fa04186daef0883b
parent4b2cfe890af2dbac9ef05b089882ac84e7501281 (diff)
update video embed code, allow service as first positional attribute
-rw-r--r--lib/asciidoctor/backends/html5.rb42
-rw-r--r--test/blocks_test.rb12
2 files changed, 32 insertions, 22 deletions
diff --git a/lib/asciidoctor/backends/html5.rb b/lib/asciidoctor/backends/html5.rb
index 09ad945d..e54c2325 100644
--- a/lib/asciidoctor/backends/html5.rb
+++ b/lib/asciidoctor/backends/html5.rb
@@ -915,22 +915,38 @@ class BlockVideoTemplate < BaseTemplate
title_element = node.title? ? %(\n<div class="title">#{node.captioned_title}</div>) : nil
width_attribute = (node.attr? 'width') ? %( width="#{node.attr 'width'}") : nil
height_attribute = (node.attr? 'height') ? %( height="#{node.attr 'height'}") : nil
- poster_attribute = (node.attr? 'poster') ? %( poster="#{node.media_uri(node.attr 'poster')}") : nil
- service_attribute = (node.attr? 'service') ? %(#{node.attr 'service'}) : nil
- if service_attribute == 'vimeo'
+ case node.attr 'poster'
+ when 'vimeo'
+ start_anchor = (node.attr? 'start') ? "#at=#{node.attr 'start'}" : nil
+ delimiter = '?'
+ autoplay_param = (node.option? 'autoplay') ? "#{delimiter}autoplay=1" : nil
+ delimiter = '&amp;' if autoplay_param
+ loop_param = (node.option? 'loop') ? "#{delimiter}loop=1" : nil
%(<div#{id_attribute}#{class_attribute}>#{title_element}
- <div class="content">
- <iframe src="http://player.vimeo.com/video/#{node.attr 'target'}" #{width_attribute} #{height_attribute} frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>
- </div>
- </div>)
+<div class="content">
+<iframe#{width_attribute}#{height_attribute} src="//player.vimeo.com/video/#{node.attr 'target'}#{start_anchor}#{autoplay_param}#{loop_param}" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>
+</div>
+</div>)
+ when 'youtube'
+ start_param = (node.attr? 'start') ? "&amp;start=#{node.attr 'start'}" : nil
+ end_param = (node.attr? 'end') ? "&amp;end=#{node.attr 'end'}" : nil
+ autoplay_param = (node.option? 'autoplay') ? '&amp;autoplay=1' : nil
+ loop_param = (node.option? 'loop') ? '&amp;loop=1' : nil
+ controls_param = (node.option? 'nocontrols') ? '&amp;controls=0' : nil
+ %(<div#{id_attribute}#{class_attribute}>#{title_element}
+<div class="content">
+<iframe#{width_attribute}#{height_attribute} src="//www.youtube.com/embed/#{node.attr 'target'}?rel=0#{start_param}#{end_param}#{autoplay_param}#{loop_param}#{controls_param}" frameborder="0"#{(node.option? 'nofullscreen') ? nil : ' allowfullscreen'}></iframe>
+</div>
+</div>)
else
+ poster_attribute = (node.attr? 'poster') ? %( poster="#{node.media_uri(node.attr 'poster')}") : nil
%(<div#{id_attribute}#{class_attribute}>#{title_element}
- <div class="content">
- <video src="#{node.media_uri(node.attr 'target')}"#{width_attribute}#{height_attribute}#{poster_attribute}#{(node.option? 'autoplay') ? ' autoplay' : nil}#{(node.option? 'nocontrols') ? nil : ' controls'}#{(node.option? 'loop') ? ' loop' : nil}>
- Your browser does not support the video tag.
- </video>
- </div>
- </div>)
+<div class="content">
+<video src="#{node.media_uri(node.attr 'target')}"#{width_attribute}#{height_attribute}#{poster_attribute}#{(node.option? 'autoplay') ? ' autoplay' : nil}#{(node.option? 'nocontrols') ? nil : ' controls'}#{(node.option? 'loop') ? ' loop' : nil}>
+Your browser does not support the video tag.
+</video>
+</div>
+</div>)
end
end
diff --git a/test/blocks_test.rb b/test/blocks_test.rb
index 91b4eb0b..303acfab 100644
--- a/test/blocks_test.rb
+++ b/test/blocks_test.rb
@@ -1371,22 +1371,16 @@ video::http://example.org/videos/cats-vs-dogs.avi[]
assert_css 'video[src="http://example.org/videos/cats-vs-dogs.avi"]', output, 1
end
- test 'video macro should output custom HTML with iFrame for vimeo service' do
+ test 'video macro should output custom HTML with iframe for vimeo service' do
input = <<-EOS
-:imagesdir: assets
-
-video::67480300[service="vimeo", width="400", height="300"]
+video::67480300[vimeo, 400, 300, start=60, options=autoplay]
EOS
- # expected output:
- # <iframe src="http://player.vimeo.com/video/VIDEO_ID" width="WIDTH" height="HEIGHT"
- # frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>
output = render_embedded_string input
assert_css 'video', output, 0
assert_css 'iframe', output, 1
- assert_css 'iframe[src="http://player.vimeo.com/video/67480300"]', output, 1
+ assert_css 'iframe[src="//player.vimeo.com/video/67480300#at=60?autoplay=1"]', output, 1
assert_css 'iframe[width="400"]', output, 1
assert_css 'iframe[height="300"]', output, 1
-
end
test 'should detect and render audio macro' do