diff options
| author | Dan Allen <dan.j.allen@gmail.com> | 2020-02-07 23:37:19 -0700 |
|---|---|---|
| committer | Dan Allen <dan.j.allen@gmail.com> | 2020-02-08 02:37:59 -0700 |
| commit | 52b056f0063555f30a3c0e92d4cd7e1f02adaf7a (patch) | |
| tree | ec0d942bc7b2f153b04b79f272619ca587c2082f | |
| parent | dd3949fa9912e71a1eb83c43e0dc53322ba0d8a9 (diff) | |
add tests for using data URI as title logo image
| -rw-r--r-- | spec/title_page_spec.rb | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/spec/title_page_spec.rb b/spec/title_page_spec.rb index 7b4754fd..3c6a4ac8 100644 --- a/spec/title_page_spec.rb +++ b/spec/title_page_spec.rb @@ -84,7 +84,7 @@ describe 'Asciidoctor::PDF::Converter - Title Page' do (expect images[0].hash[:Height]).to be 240 end - it 'should use remote logo specified by title-logo-image document attribute to title page' do + it 'should add remote logo specified by title-logo-image document attribute to title page' do with_local_webserver do |base_url| [%(#{base_url}/tux.png), %(image:#{base_url}/tux.png[])].each do |image_url| pdf = to_pdf <<~EOS, attribute_overrides: { 'allow-uri-read' => '' } @@ -101,6 +101,22 @@ describe 'Asciidoctor::PDF::Converter - Title Page' do end end + it 'should add logo specified by title-logo-image document attribute with data URI to title page' do + image_data = File.binread fixture_file 'tux.png' + encoded_image_data = Base64.strict_encode64 image_data + image_url = %(image:data:image/jpg;base64,#{encoded_image_data}[]) + pdf = to_pdf <<~EOS + = Document Title + :doctype: book + :title-logo-image: #{image_url} + EOS + + images = get_images pdf, 1 + (expect images).to have_size 1 + (expect images[0].hash[:Width]).to be 204 + (expect images[0].hash[:Height]).to be 240 + end + it 'should position logo using value of top attribute on image macro in title-logo-image attribute' do pdf = to_pdf <<~'EOS', analyze: :image = Document Title @@ -376,7 +392,7 @@ describe 'Asciidoctor::PDF::Converter - Title Page' do (expect images[0].hash[:Height]).to be 240 end - it 'should use remote logo specified by title_page_logo_image theme key to title page' do + it 'should add remote logo specified by title_page_logo_image theme key to title page' do with_local_webserver do |base_url| [%(#{base_url}/tux.png), %(image:#{base_url}/tux.png[])].each do |image_url| pdf = to_pdf <<~'EOS', pdf_theme: { title_page_logo_image: image_url }, attribute_overrides: { 'allow-uri-read' => '' } @@ -392,6 +408,21 @@ describe 'Asciidoctor::PDF::Converter - Title Page' do end end + it 'should add logo specified by title-logo-image document attribute with data URI to title page' do + image_data = File.binread fixture_file 'tux.png' + encoded_image_data = Base64.strict_encode64 image_data + image_url = %(image:data:image/jpg;base64,#{encoded_image_data}[]) + pdf = to_pdf <<~EOS, pdf_theme: { title_page_logo_image: image_url } + = Document Title + :doctype: book + EOS + + images = get_images pdf, 1 + (expect images).to have_size 1 + (expect images[0].hash[:Width]).to be 204 + (expect images[0].hash[:Height]).to be 240 + end + it 'should resolve title page logo image from theme relative to themedir' do pdf_theme = { __dir__: examples_dir, |
