1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
# frozen_string_literal: true
require_relative 'spec_helper'
describe 'Asciidoctor::PDF::Converter - Video' do
context 'Local' do
it 'should replace video with poster image if specified', visual: true do
to_file = to_pdf_file <<~'EOS', 'video-local-file-poster.pdf'
video::asciidoctor.mp4[logo.png,200,200]
EOS
(expect to_file).to visually_match 'video-local-file-poster.pdf'
end
it 'should replace video with video path and play icon if poster not specified' do
pdf = to_pdf <<~'EOS', analyze: true
:icons: font
video::asciidoctor.mp4[]
EOS
(expect pdf.lines).to eql [%(\uf04b\u00a0#{fixture_file 'asciidoctor.mp4'} (video))]
end
it 'should show caption for video with no poster if title is specified' do
pdf = to_pdf <<~'EOS', analyze: true
:icons: font
.Asciidoctor training
video::asciidoctor.mp4[]
EOS
(expect pdf.lines).to eql [%(\uf04b\u00a0#{fixture_file 'asciidoctor.mp4'} (video)), 'Asciidoctor training']
end
end
context 'YouTube' do
it 'should replace video with poster image if allow-uri-read attribute is set', visual: true, network: true do
video_id = 'EJ09pSuA9hw'
to_file = to_pdf_file <<~EOS, 'video-youtube-poster.pdf', attribute_overrides: { 'allow-uri-read' => '' }
video::#{video_id}[youtube,pdfwidth=100%]
EOS
pdf = PDF::Reader.new to_file
annotations = get_annotations pdf, 1
(expect annotations).to have_size 1
link_annotation = annotations[0]
(expect link_annotation[:Subtype]).to be :Link
(expect link_annotation[:A][:URI]).to eql %(https://www.youtube.com/watch?v=#{video_id})
(expect to_file).to visually_match 'video-youtube-poster.pdf'
end
it 'should replace video with link if allow-uri-read attribute is not set' do
video_id = 'EJ09pSuA9hw'
input = %(video::#{video_id}[youtube])
pdf = to_pdf input
annotations = get_annotations pdf, 1
(expect annotations).to have_size 1
link_annotation = annotations[0]
(expect link_annotation[:Subtype]).to be :Link
(expect link_annotation[:A][:URI]).to eql %(https://www.youtube.com/watch?v=#{video_id})
pdf = to_pdf input, analyze: true
expected_strings = [%(\u25ba\u00a0), %(https://www.youtube.com/watch?v=#{video_id}), ' ', '(YouTube video)']
(expect pdf.text.map {|it| it[:string] }).to eql expected_strings
end
end
context 'Vimeo' do
it 'should replace video with poster image if allow-uri-read attribute is set', visual: true, network: true do
video_id = '77477140'
to_file = to_pdf_file <<~EOS, 'video-vimeo-poster.pdf', attribute_overrides: { 'allow-uri-read' => '' }
video::#{video_id}[vimeo,pdfwidth=100%]
EOS
pdf = PDF::Reader.new to_file
annotations = get_annotations pdf, 1
(expect annotations).to have_size 1
link_annotation = annotations[0]
(expect link_annotation[:Subtype]).to be :Link
(expect link_annotation[:A][:URI]).to eql %(https://vimeo.com/#{video_id})
(expect to_file).to visually_match 'video-vimeo-poster.pdf'
end
it 'should replace video with link if allow-uri-read attribute is not set' do
video_id = '77477140'
input = %(video::#{video_id}[vimeo])
pdf = to_pdf input
annotations = get_annotations pdf, 1
(expect annotations).to have_size 1
link_annotation = annotations[0]
(expect link_annotation[:Subtype]).to be :Link
(expect link_annotation[:A][:URI]).to eql %(https://vimeo.com/#{video_id})
pdf = to_pdf input, analyze: true
expected_strings = [%(\u25ba\u00a0), %(https://vimeo.com/#{video_id}), ' ', '(Vimeo video)']
(expect pdf.text.map {|it| it[:string] }).to eql expected_strings
end
it 'should replace video with link if allow-uri-read attribute is set and video is not found' do
video_id = '0'
input = %(video::#{video_id}[vimeo])
pdf = to_pdf input, attribute_overrides: { 'allow-uri-read' => '' }
annotations = get_annotations pdf, 1
(expect annotations).to have_size 1
link_annotation = annotations[0]
(expect link_annotation[:Subtype]).to be :Link
(expect link_annotation[:A][:URI]).to eql %(https://vimeo.com/#{video_id})
pdf = to_pdf input, attribute_overrides: { 'allow-uri-read' => '' }, analyze: true
expected_strings = [%(\u25ba\u00a0), %(https://vimeo.com/#{video_id}), ' ', '(Vimeo video)']
(expect pdf.text.map {|it| it[:string] }).to eql expected_strings
end
end
end
|