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
123
124
125
126
127
128
129
130
131
132
|
# 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', attributes: { 'imagesdir' => 'path/to/images' }, analyze: true
:icons: font
video::asciidoctor.mp4[]
EOS
(expect pdf.lines).to eql [%(\uf04b\u00a0path/to/images/asciidoctor.mp4 (video))]
end
it 'should wrap text for video if it exceeds width of content area' do
pdf = to_pdf <<~'EOS', analyze: true, attribute_overrides: { 'imagesdir' => '' }
video::a-video-with-an-excessively-long-and-descriptive-name-as-they-often-are-that-causes-the-text-to-wrap.mp4[]
EOS
(expect pdf.pages).to have_size 1
lines = pdf.lines pdf.find_text page_number: 1
(expect lines).to eql [%(\u25ba\u00a0a-video-with-an-excessively-long-and-descriptive-name-as-they-often-are-that-causes-the-text-to-), 'wrap.mp4 (video)']
end
it 'should show caption for video with no poster if title is specified' do
pdf = to_pdf <<~'EOS', attributes: { 'imagesdir' => '' }, analyze: true
:icons: font
.Asciidoctor training
video::asciidoctor.mp4[]
EOS
(expect pdf.lines).to eql [%(\uf04b\u00a0asciidoctor.mp4 (video)), 'Asciidoctor training']
end
end
context 'YouTube' do
it 'should replace video with poster image if allow-uri-read attribute is set', network: true, visual: 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', network: true, visual: 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
|