dragonfly_pdf 2.0.0 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b5dab11367b3cdef13ca762005b3a860557f37f2
4
- data.tar.gz: 074c0aebc12f4f39a18f538a1d9e71aff311e396
3
+ metadata.gz: 5f49e3cad532a597767fe058ac6fd8097baf69ff
4
+ data.tar.gz: 765bdcc44c3b5ba7a708476e01548d79d485fcae
5
5
  SHA512:
6
- metadata.gz: 7d20ce89e113cd9023e67b9b48fc72ae93025e25cefe354273ffa68522777840766176ad4a79d799e3deace276c15b9055fd3ec4f9b03a04732c983c479c1a94
7
- data.tar.gz: a91341b7bea0267ea9043eb04118a0fbeec0943274c1c0be80ec9d2780831f649bf041fefe0ad4206e7c0394c1594a7a3ca650d8f94f651d6a4496ad52e2fa23
6
+ metadata.gz: 839040f86f9322c1c190802584eddd8d82ac7ab21d33728f3df8c28290542eb486144bed9ad4f029a5e29412ee5fd85766a8be3657e22725b07b7d475dd9b06e
7
+ data.tar.gz: c3c5b7294bccb265a948e34ad04f1ee66455a7edf0cc20feae4b459f7a777aaec47316f1c47a39a24d1477534c51255ae259032999d07af6a449b95f7ceba491
@@ -12,7 +12,8 @@ before_install:
12
12
  - sudo apt-get update
13
13
  - sudo apt-get install -y pdftk
14
14
  - sudo apt-get install -y ghostscript
15
- - sudo apt-get install -y mupdf-tools
15
+ - curl -OL https://mupdf.com/downloads/mupdf-1.12.0-source.tar.gz
16
+ - tar zvxf mupdf-1.12.0-source.tar.gz && cd mupdf-1.12.0-source && sudo make HAVE_X11=no HAVE_GLUT=no prefix=/usr/local install
16
17
  - sudo apt-get install -y gobject-introspection libgirepository1.0-dev libglib2.0-dev libpoppler-glib-dev
17
18
  - curl -OL https://github.com/jcupitt/libvips/releases/download/v8.5.8/vips-8.5.8.tar.gz
18
19
  - tar zvxf vips-8.5.8.tar.gz && cd vips-8.5.8 && ./configure && sudo make && sudo make install
@@ -1,5 +1,11 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 2.0.1
4
+
5
+ * fixed: a bug in Convert and Page Thumb Processors which caused the url to not include file extension
6
+ * refactored: Page Thumb Processor is now a class
7
+ * added: tests for Convert and Page Thumb Processor
8
+
3
9
  ## 2.0.0
4
10
 
5
11
  * PDF rendering to use `mupdf` which results in siginificant performance boost
@@ -4,6 +4,7 @@ require 'dragonfly_pdf/analysers/pdf_properties'
4
4
 
5
5
  require 'dragonfly_pdf/processors/append'
6
6
  require 'dragonfly_pdf/processors/convert'
7
+ require 'dragonfly_pdf/processors/page_thumb'
7
8
  require 'dragonfly_pdf/processors/page'
8
9
  require 'dragonfly_pdf/processors/remove_password'
9
10
  require 'dragonfly_pdf/processors/rotate'
@@ -49,25 +50,8 @@ module DragonflyPdf
49
50
  app.add_processor :rotate, DragonflyPdf::Processors::Rotate.new
50
51
  app.add_processor :stamp, DragonflyPdf::Processors::Stamp.new
51
52
  app.add_processor :subset_fonts, DragonflyPdf::Processors::SubsetFonts.new
52
-
53
53
  app.add_processor :thumb, DragonflyLibvips::Processors::Thumb.new
54
-
55
- app.add_processor :page_thumb do |content, page, geometry = nil, options = {}|
56
- options = options.deep_symbolize_keys
57
- options[:format] = options.fetch(:format, :jpg)
58
-
59
- convert_options = {}
60
- convert_options[:format] = case options[:format]
61
- when :pdf, :svg then options[:format]
62
- else :png
63
- end
64
-
65
- content.process!(:convert, page, geometry, convert_options)
66
-
67
- unless %i[pdf png svg].include?(options[:format].to_sym)
68
- content.process!(:thumb, geometry, options)
69
- end
70
- end
54
+ app.add_processor :page_thumb, DragonflyPdf::Processors::PageThumb.new
71
55
  end
72
56
  end
73
57
  end
@@ -50,14 +50,16 @@ module DragonflyPdf
50
50
  `mv #{content.path.sub(".#{format}", "1.#{format}")} #{content.path}`
51
51
  end
52
52
 
53
+ content.meta['format'] = format.to_s
53
54
  content.ext = format
55
+ content.meta['mime_type'] = nil # don't need it as we have ext now
54
56
  end
55
57
 
56
- def update_url(url_attributes, _, options = {})
58
+ def update_url(attrs, page, geometry=nil, options = {})
57
59
  options = options.deep_symbolize_keys
58
60
  format = options.fetch(:format, :png)
59
61
 
60
- url_attributes.ext = format
62
+ attrs.ext = format.to_s
61
63
  end
62
64
 
63
65
  private
@@ -0,0 +1,40 @@
1
+ module DragonflyPdf
2
+ module Processors
3
+ class PageThumb
4
+ def call(content, page, geometry = nil, options = {})
5
+ options = options.deep_symbolize_keys
6
+ format = options.delete(:format) { :jpg }
7
+
8
+ convert(content, page, geometry, format)
9
+
10
+ unless %i[pdf png svg].include?(format.to_sym)
11
+ thumb(content, geometry, format, options)
12
+ end
13
+
14
+ content.meta['format'] = format.to_s
15
+ content.ext = format
16
+ content.meta['mime_type'] = nil # don't need it as we have ext now
17
+ end
18
+
19
+ def update_url(attrs, page, geometry=nil, options = {})
20
+ options = options.deep_symbolize_keys
21
+ format = options.fetch(:format, :jpg)
22
+ attrs.ext = format.to_s
23
+ end
24
+
25
+ private # =============================================================
26
+
27
+ def convert(content, page, geometry, format)
28
+ convert_format = case format
29
+ when :pdf, :svg then format
30
+ else :png
31
+ end
32
+ content.process!(:convert, page, geometry, { format: convert_format })
33
+ end
34
+
35
+ def thumb(content, geometry, format, options)
36
+ content.process!(:thumb, geometry, options.merge(format: format))
37
+ end
38
+ end
39
+ end
40
+ end
@@ -1,3 +1,3 @@
1
1
  module DragonflyPdf
2
- VERSION = '2.0.0'.freeze
2
+ VERSION = '2.0.1'.freeze
3
3
  end
@@ -63,22 +63,9 @@ module DragonflyPdf
63
63
  end
64
64
  end
65
65
 
66
- describe 'DragonflyLibvips proxy' do
67
- describe 'page_thumb' do
68
- it 'converts PDF to JPG format' do
69
- pdf.page_thumb!(1, '600x')
70
- `file --mime-type #{pdf.path}`.must_include 'image/jpeg'
71
- end
72
-
73
- # it 'converts PDF page to SVG format' do
74
- # pdf.page_thumb!(1, nil, format: :svg)
75
- # `file --mime-type #{pdf.path}`.must_include 'image/svg+xml'
76
- # end
77
- #
78
- # it 'converts PDF page to PDF format' do
79
- # pdf.page_thumb!(1, nil, format: :pdf)
80
- # `file --mime-type #{pdf.path}`.must_include 'application/pdf'
81
- # end
66
+ describe '#convert' do
67
+ it 'adds the correct extension to resulting url' do
68
+ pdf.convert(1, '600x').url.must_match /\.png/
82
69
  end
83
70
  end
84
71
  end
@@ -0,0 +1,46 @@
1
+ require 'test_helper'
2
+
3
+ describe DragonflyPdf::Processors::Convert do
4
+ let(:app) { test_app.configure_with(:pdf) }
5
+ let(:sample) { Dragonfly::Content.new(app, SAMPLES_DIR.join('sample_pages.pdf')) }
6
+
7
+ let(:processor) { DragonflyPdf::Processors::Convert.new }
8
+
9
+ describe 'formats' do
10
+ let (:url_attributes) { OpenStruct.new }
11
+
12
+ describe 'default' do
13
+ before { processor.call(sample, 1, '600x') }
14
+
15
+ it 'converts the PDF to a PNG by default' do
16
+ sample.ext.must_equal 'png'
17
+ end
18
+
19
+ it 'updates the file meta format to PNG by default' do
20
+ sample.meta['format'].must_equal 'png'
21
+ end
22
+
23
+ it 'updates the url extension to PNG by default' do
24
+ processor.update_url(url_attributes, 1)
25
+ url_attributes.ext.must_equal 'png'
26
+ end
27
+ end
28
+
29
+ describe 'svg' do
30
+ before { processor.call(sample, 1, '600x', format: :svg) }
31
+
32
+ it 'converts the PDF to an SVG' do
33
+ sample.ext.must_equal 'svg'
34
+ end
35
+
36
+ it 'updates the file meta format to SVG' do
37
+ sample.meta['format'].must_equal 'svg'
38
+ end
39
+
40
+ it 'updates the url extension to SVG' do
41
+ processor.update_url(url_attributes, 1, '', format: :svg)
42
+ url_attributes.ext.must_equal 'svg'
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,29 @@
1
+ require 'test_helper'
2
+
3
+ describe DragonflyPdf::Processors::PageThumb do
4
+ let(:app) { test_app.configure_with(:pdf) }
5
+ let(:sample) { Dragonfly::Content.new(app, SAMPLES_DIR.join('sample_pages.pdf')) }
6
+
7
+ let(:processor) { DragonflyPdf::Processors::PageThumb.new }
8
+
9
+ describe 'formats' do
10
+ let (:url_attributes) { OpenStruct.new }
11
+
12
+ describe 'default' do
13
+ before { processor.call(sample, 1, '600x') }
14
+
15
+ it 'converts the PDF to a JPG by default' do
16
+ sample.ext.must_equal 'jpg'
17
+ end
18
+
19
+ it 'updates the file meta format to JPG by default' do
20
+ sample.meta['format'].must_equal 'jpg'
21
+ end
22
+
23
+ it 'updates the url extension to JPG by default' do
24
+ processor.update_url(url_attributes, 1)
25
+ url_attributes.ext.must_equal 'jpg'
26
+ end
27
+ end
28
+ end
29
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dragonfly_pdf
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomas Celizna
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-02-02 00:00:00.000000000 Z
11
+ date: 2018-02-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dragonfly
@@ -159,6 +159,7 @@ files:
159
159
  - lib/dragonfly_pdf/processors/append.rb
160
160
  - lib/dragonfly_pdf/processors/convert.rb
161
161
  - lib/dragonfly_pdf/processors/page.rb
162
+ - lib/dragonfly_pdf/processors/page_thumb.rb
162
163
  - lib/dragonfly_pdf/processors/remove_password.rb
163
164
  - lib/dragonfly_pdf/processors/rotate.rb
164
165
  - lib/dragonfly_pdf/processors/stamp.rb
@@ -172,7 +173,9 @@ files:
172
173
  - test/dragonfly_pdf/analysers/pdf_properties_test.rb
173
174
  - test/dragonfly_pdf/plugin_test.rb
174
175
  - test/dragonfly_pdf/processors/append_test.rb
176
+ - test/dragonfly_pdf/processors/convert_test.rb
175
177
  - test/dragonfly_pdf/processors/page_test.rb
178
+ - test/dragonfly_pdf/processors/page_thumb_test.rb
176
179
  - test/dragonfly_pdf/processors/remove_password_test.rb
177
180
  - test/dragonfly_pdf/processors/rotate_test.rb
178
181
  - test/dragonfly_pdf/processors/stamp_test.rb
@@ -206,7 +209,9 @@ test_files:
206
209
  - test/dragonfly_pdf/analysers/pdf_properties_test.rb
207
210
  - test/dragonfly_pdf/plugin_test.rb
208
211
  - test/dragonfly_pdf/processors/append_test.rb
212
+ - test/dragonfly_pdf/processors/convert_test.rb
209
213
  - test/dragonfly_pdf/processors/page_test.rb
214
+ - test/dragonfly_pdf/processors/page_thumb_test.rb
210
215
  - test/dragonfly_pdf/processors/remove_password_test.rb
211
216
  - test/dragonfly_pdf/processors/rotate_test.rb
212
217
  - test/dragonfly_pdf/processors/stamp_test.rb