dragonfly_pdf 0.0.1 → 0.0.2
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 +4 -4
- data/README.md +31 -8
- data/lib/dragonfly_pdf/analysers/pdf_properties.rb +3 -1
- data/lib/dragonfly_pdf/errors.rb +3 -0
- data/lib/dragonfly_pdf/plugin.rb +3 -0
- data/lib/dragonfly_pdf/processors/page.rb +50 -0
- data/lib/dragonfly_pdf/processors/page_thumb.rb +5 -7
- data/lib/dragonfly_pdf/version.rb +1 -1
- data/samples/sample_pages.pdf +0 -0
- data/samples/sample_spreads.pdf +0 -0
- data/samples/sample_spreads_back.pdf +0 -0
- data/samples/sample_spreads_cover.pdf +0 -0
- data/samples/sample_spreads_cover_back.pdf +0 -0
- data/test/dragonfly_pdf/analysers/pdf_properties_test.rb +24 -24
- data/test/dragonfly_pdf/plugin_test.rb +12 -0
- data/test/dragonfly_pdf/processors/page_test.rb +84 -0
- data/test/dragonfly_pdf/processors/page_thumb_test.rb +6 -1
- metadata +5 -1
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 5e969fb6354ce699bbdad681ffacfbfd465ad47a
         | 
| 4 | 
            +
              data.tar.gz: 975403373d406f38f528fce2a0c411adf58c9d4b
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: a5a235d8b1bef8fad59fe522472f674c93636cddfff4b6f24dfbe4b40210aec31d2fa4ef674be22eff4c41153f3fa241b43a6f94c65f8ae9c936924ed2f9de5b
         | 
| 7 | 
            +
              data.tar.gz: ec751387a15c6110c006c1680be1ecf255698865d1e5e6de8d5146b4e13549aee4714366e9da51041aeaedda0dc199d51ff02d253d0611ae0615f9fd5e1f1306
         | 
    
        data/README.md
    CHANGED
    
    | @@ -4,6 +4,11 @@ | |
| 4 4 |  | 
| 5 5 | 
             
            [Dragonfly](https://github.com/markevans/dragonfly) PDF analysers and processors.
         | 
| 6 6 |  | 
| 7 | 
            +
            ## Dependencies
         | 
| 8 | 
            +
             | 
| 9 | 
            +
            * [ImageMagick](http://www.imagemagick.org)
         | 
| 10 | 
            +
            * [GhostScript](http://www.ghostscript.com)
         | 
| 11 | 
            +
             | 
| 7 12 | 
             
            ## Installation
         | 
| 8 13 |  | 
| 9 14 | 
             
            Add this line to your application's Gemfile:
         | 
| @@ -34,7 +39,15 @@ end | |
| 34 39 | 
             
            This processor has argument `spreads` (by default set to `false`). When `true`, the analyser assumes the PDF might contain 2 real pages per one PDF page (as when saving with the spreads option in InDesign) and recalculates the PDF properties accordingly (including situations when PDF starts or ends with single page).
         | 
| 35 40 |  | 
| 36 41 | 
             
            ```ruby
         | 
| 37 | 
            -
            pdf.pdf_properties( | 
| 42 | 
            +
            pdf.pdf_properties(opts={})
         | 
| 43 | 
            +
            ```
         | 
| 44 | 
            +
             | 
| 45 | 
            +
            The available options and their default values are:
         | 
| 46 | 
            +
             | 
| 47 | 
            +
            ```ruby
         | 
| 48 | 
            +
            {
         | 
| 49 | 
            +
                spreads: false
         | 
| 50 | 
            +
            }
         | 
| 38 51 | 
             
            ```
         | 
| 39 52 |  | 
| 40 53 | 
             
            Returns Hash of PDF properties:
         | 
| @@ -55,12 +68,28 @@ When the `spreads` argument is set to true, all page arrays (page_numbers, width | |
| 55 68 |  | 
| 56 69 | 
             
            ## Processors
         | 
| 57 70 |  | 
| 71 | 
            +
            ### Page
         | 
| 72 | 
            +
             | 
| 73 | 
            +
            Extracts page from PDF.
         | 
| 74 | 
            +
             | 
| 75 | 
            +
            ```ruby
         | 
| 76 | 
            +
            pdf.page(page_number=1, opts={})
         | 
| 77 | 
            +
            ```
         | 
| 78 | 
            +
             | 
| 79 | 
            +
            The available options and their default values are:
         | 
| 80 | 
            +
             | 
| 81 | 
            +
            ```ruby
         | 
| 82 | 
            +
            {
         | 
| 83 | 
            +
                spreads: false
         | 
| 84 | 
            +
            }
         | 
| 85 | 
            +
            ```
         | 
| 86 | 
            +
             | 
| 58 87 | 
             
            ### Page Thumb
         | 
| 59 88 |  | 
| 60 89 | 
             
            Generates thumbnail of a specified page, in defined density (dpi) and format.
         | 
| 61 90 |  | 
| 62 91 | 
             
            ```ruby
         | 
| 63 | 
            -
            pdf.page_thumb(page_number= | 
| 92 | 
            +
            pdf.page_thumb(page_number=1, opts={})
         | 
| 64 93 | 
             
            ```
         | 
| 65 94 |  | 
| 66 95 | 
             
            The available options and their default values are:
         | 
| @@ -73,12 +102,6 @@ The available options and their default values are: | |
| 73 102 | 
             
            }
         | 
| 74 103 | 
             
            ```
         | 
| 75 104 |  | 
| 76 | 
            -
            Similarly to the `#pdf_properties`, the `#page_thumb` processor takes into account the `spreads` option.
         | 
| 77 | 
            -
             | 
| 78 | 
            -
            ## TODO
         | 
| 79 | 
            -
             | 
| 80 | 
            -
            * Add more tests for `#page_thumb`
         | 
| 81 | 
            -
             | 
| 82 105 | 
             
            ## Contributing
         | 
| 83 106 |  | 
| 84 107 | 
             
            1. Fork it ( https://github.com/tomasc/dragonfly_pdf/fork )
         | 
    
        data/lib/dragonfly_pdf/plugin.rb
    CHANGED
    
    | @@ -1,4 +1,6 @@ | |
| 1 1 | 
             
            require 'dragonfly_pdf/analysers/pdf_properties'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            require 'dragonfly_pdf/processors/page'
         | 
| 2 4 | 
             
            require 'dragonfly_pdf/processors/page_thumb'
         | 
| 3 5 |  | 
| 4 6 | 
             
            module DragonflyPdf
         | 
| @@ -38,6 +40,7 @@ module DragonflyPdf | |
| 38 40 | 
             
                  # ---------------------------------------------------------------------
         | 
| 39 41 |  | 
| 40 42 | 
             
                  app.add_processor :page_thumb, DragonflyPdf::Processors::PageThumb.new
         | 
| 43 | 
            +
                  app.add_processor :page, DragonflyPdf::Processors::Page.new
         | 
| 41 44 | 
             
                end
         | 
| 42 45 |  | 
| 43 46 | 
             
              end
         | 
| @@ -0,0 +1,50 @@ | |
| 1 | 
            +
            require 'pdf-reader'
         | 
| 2 | 
            +
            require_relative '../errors'
         | 
| 3 | 
            +
            require_relative '../analysers/pdf_properties'
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            module DragonflyPdf
         | 
| 6 | 
            +
              module Processors
         | 
| 7 | 
            +
                class Page
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                  def call content, page_number=1, opts={}
         | 
| 10 | 
            +
                    spreads = opts.fetch(:spreads, false)
         | 
| 11 | 
            +
                    pdf_page_number = page_number
         | 
| 12 | 
            +
                    crop_args = ''
         | 
| 13 | 
            +
             | 
| 14 | 
            +
                    pdf_properties = DragonflyPdf::Analysers::PdfProperties.new.call(content, spreads: spreads)
         | 
| 15 | 
            +
             | 
| 16 | 
            +
                    raise DragonflyPdf::PageNotFound unless pdf_properties[:page_numbers].flatten.include?(page_number)
         | 
| 17 | 
            +
             | 
| 18 | 
            +
                    if spreads
         | 
| 19 | 
            +
                      spread = pdf_properties[:page_numbers].detect{ |s| s.include?(page_number) }
         | 
| 20 | 
            +
                      spread_number = pdf_properties[:page_numbers].index(spread)
         | 
| 21 | 
            +
                      spread_side = spread.index(page_number)
         | 
| 22 | 
            +
             | 
| 23 | 
            +
                      pdf_page_number = spread_number+1
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                      pdf = PDF::Reader.new(content.path)
         | 
| 26 | 
            +
                      box = pdf.pages[spread_number].attributes[:MediaBox] || pdf.pages[spread_number].attributes[:CropBox]
         | 
| 27 | 
            +
             | 
| 28 | 
            +
                      crop_box = box
         | 
| 29 | 
            +
                      crop_box[2] = crop_box[2]/2
         | 
| 30 | 
            +
                      crop_box[0] += crop_box[2] * spread_side
         | 
| 31 | 
            +
                      crop_box[2] += crop_box[2] * spread_side
         | 
| 32 | 
            +
             | 
| 33 | 
            +
                      crop_args = "-c '[/CropBox [#{crop_box.join(' ')}] /PAGES pdfmark'"
         | 
| 34 | 
            +
                    end
         | 
| 35 | 
            +
             | 
| 36 | 
            +
                    content.shell_update(ext: :pdf) do |old_path, new_path|
         | 
| 37 | 
            +
                      "#{gs_command} -sDEVICE=pdfwrite -dNOPAUSE -dBATCH -dFirstPage=#{pdf_page_number} -dLastPage=#{pdf_page_number} -o #{new_path} #{crop_args} -f #{old_path}"
         | 
| 38 | 
            +
                    end
         | 
| 39 | 
            +
                  end
         | 
| 40 | 
            +
             | 
| 41 | 
            +
             | 
| 42 | 
            +
                  private # =============================================================
         | 
| 43 | 
            +
                  
         | 
| 44 | 
            +
                  def gs_command
         | 
| 45 | 
            +
                    'gs'
         | 
| 46 | 
            +
                  end
         | 
| 47 | 
            +
             | 
| 48 | 
            +
                end
         | 
| 49 | 
            +
              end
         | 
| 50 | 
            +
            end
         | 
| @@ -4,19 +4,17 @@ module DragonflyPdf | |
| 4 4 | 
             
              module Processors
         | 
| 5 5 | 
             
                class PageThumb
         | 
| 6 6 |  | 
| 7 | 
            -
                   | 
| 8 | 
            -
             | 
| 9 | 
            -
                  def call content, page_number=0, opts={}
         | 
| 7 | 
            +
                  def call content, page_number=1, opts={}
         | 
| 10 8 | 
             
                    format = opts.fetch(:format, :png)
         | 
| 11 | 
            -
                    # raise UnsupportedFormat unless %w(tif jpg jpeg png gif).include?(format.to_s)
         | 
| 12 | 
            -
             | 
| 13 9 | 
             
                    density = opts.fetch(:density, 600)
         | 
| 14 10 | 
             
                    spreads = opts.fetch(:spreads, false)
         | 
| 15 11 |  | 
| 16 12 | 
             
                    args = "-alpha deactivate -background white -colorspace sRGB -density #{density}x#{density} -define pdf:use-cropbox=true -define pdf:use-trimbox=true"
         | 
| 17 13 | 
             
                    crop_args = ''
         | 
| 18 14 |  | 
| 19 | 
            -
                    pdf_properties = DragonflyPdf::Analysers::PdfProperties.new.call(content, spreads)
         | 
| 15 | 
            +
                    pdf_properties = DragonflyPdf::Analysers::PdfProperties.new.call(content, spreads: spreads)
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                    raise DragonflyPdf::PageNotFound unless pdf_properties[:page_numbers].flatten.include?(page_number)
         | 
| 20 18 |  | 
| 21 19 | 
             
                    if spreads
         | 
| 22 20 | 
             
                      spread = pdf_properties[:page_numbers].detect{ |s| s.include?(page_number) }
         | 
| @@ -27,7 +25,7 @@ module DragonflyPdf | |
| 27 25 | 
             
                      pdf_page_number = spread_number
         | 
| 28 26 | 
             
                      crop_args = "-crop 50%x100% -delete #{page_to_delete}"
         | 
| 29 27 | 
             
                    else
         | 
| 30 | 
            -
                      pdf_page_number = page_number
         | 
| 28 | 
            +
                      pdf_page_number = page_number-1
         | 
| 31 29 | 
             
                    end
         | 
| 32 30 |  | 
| 33 31 | 
             
                    content.shell_update(ext: format) do |old_path, new_path|
         | 
    
        data/samples/sample_pages.pdf
    CHANGED
    
    | Binary file | 
    
        data/samples/sample_spreads.pdf
    CHANGED
    
    | Binary file | 
| Binary file | 
| Binary file | 
| Binary file | 
| @@ -32,25 +32,25 @@ module DragonflyPdf | |
| 32 32 |  | 
| 33 33 | 
             
                    describe 'for PDF with spreads' do
         | 
| 34 34 | 
             
                      it 'returns two-dimensional array' do
         | 
| 35 | 
            -
                        analyser.call(spreads, true)[:page_numbers].must_equal [[1,2],[3,4],[5,6],[7,8]]
         | 
| 35 | 
            +
                        analyser.call(spreads, spreads: true)[:page_numbers].must_equal [[1,2],[3,4],[5,6],[7,8]]
         | 
| 36 36 | 
             
                      end
         | 
| 37 37 | 
             
                    end
         | 
| 38 38 |  | 
| 39 39 | 
             
                    describe 'for PDF with spreads and a cover' do
         | 
| 40 40 | 
             
                      it 'returns two-dimensional array' do
         | 
| 41 | 
            -
                        analyser.call(spreads_cover, true)[:page_numbers].must_equal [[1],[2,3],[4,5],[6,7],[8,9]]
         | 
| 41 | 
            +
                        analyser.call(spreads_cover, spreads: true)[:page_numbers].must_equal [[1],[2,3],[4,5],[6,7],[8,9]]
         | 
| 42 42 | 
             
                      end
         | 
| 43 43 | 
             
                    end
         | 
| 44 44 |  | 
| 45 45 | 
             
                    describe 'for PDF with spreads and a back cover' do
         | 
| 46 46 | 
             
                      it 'returns two-dimensional array' do
         | 
| 47 | 
            -
                        analyser.call(spreads_back, true)[:page_numbers].must_equal [[1,2],[3,4],[5,6],[7,8],[9]]
         | 
| 47 | 
            +
                        analyser.call(spreads_back, spreads: true)[:page_numbers].must_equal [[1,2],[3,4],[5,6],[7,8],[9]]
         | 
| 48 48 | 
             
                      end
         | 
| 49 49 | 
             
                    end
         | 
| 50 50 |  | 
| 51 51 | 
             
                    describe 'for PDF with spreads and a front and a back cover' do
         | 
| 52 52 | 
             
                      it 'returns two-dimensional array' do
         | 
| 53 | 
            -
                        analyser.call(spreads_cover_back, true)[:page_numbers].must_equal [[1],[2,3],[4,5],[6,7],[8,9],[10]]
         | 
| 53 | 
            +
                        analyser.call(spreads_cover_back, spreads: true)[:page_numbers].must_equal [[1],[2,3],[4,5],[6,7],[8,9],[10]]
         | 
| 54 54 | 
             
                      end
         | 
| 55 55 | 
             
                    end
         | 
| 56 56 | 
             
                  end
         | 
| @@ -66,25 +66,25 @@ module DragonflyPdf | |
| 66 66 |  | 
| 67 67 | 
             
                    describe 'for PDF with spreads' do
         | 
| 68 68 | 
             
                      it 'returns correct page count' do
         | 
| 69 | 
            -
                        analyser.call(spreads, true)[:page_count].must_equal 8
         | 
| 69 | 
            +
                        analyser.call(spreads, spreads: true)[:page_count].must_equal 8
         | 
| 70 70 | 
             
                      end
         | 
| 71 71 | 
             
                    end
         | 
| 72 72 |  | 
| 73 73 | 
             
                    describe 'for PDF with spreads and a cover' do
         | 
| 74 74 | 
             
                      it 'returns correct page count' do
         | 
| 75 | 
            -
                        analyser.call(spreads_cover, true)[:page_count].must_equal 9
         | 
| 75 | 
            +
                        analyser.call(spreads_cover, spreads: true)[:page_count].must_equal 9
         | 
| 76 76 | 
             
                      end
         | 
| 77 77 | 
             
                    end
         | 
| 78 78 |  | 
| 79 79 | 
             
                    describe 'for PDF with spreads and a back cover' do
         | 
| 80 80 | 
             
                      it 'returns correct page count' do
         | 
| 81 | 
            -
                        analyser.call(spreads_back, true)[:page_count].must_equal 9
         | 
| 81 | 
            +
                        analyser.call(spreads_back, spreads: true)[:page_count].must_equal 9
         | 
| 82 82 | 
             
                      end
         | 
| 83 83 | 
             
                    end
         | 
| 84 84 |  | 
| 85 85 | 
             
                    describe 'for PDF with spreads and a front and a back cover' do
         | 
| 86 86 | 
             
                      it 'returns correct page count' do
         | 
| 87 | 
            -
                        analyser.call(spreads_cover_back, true)[:page_count].must_equal 10
         | 
| 87 | 
            +
                        analyser.call(spreads_cover_back, spreads: true)[:page_count].must_equal 10
         | 
| 88 88 | 
             
                      end
         | 
| 89 89 | 
             
                    end
         | 
| 90 90 | 
             
                  end
         | 
| @@ -100,25 +100,25 @@ module DragonflyPdf | |
| 100 100 |  | 
| 101 101 | 
             
                    describe 'for PDF with spreads' do
         | 
| 102 102 | 
             
                      it 'returns correct page count' do
         | 
| 103 | 
            -
                        analyser.call(spreads, true)[:spread_count].must_equal 4
         | 
| 103 | 
            +
                        analyser.call(spreads, spreads: true)[:spread_count].must_equal 4
         | 
| 104 104 | 
             
                      end
         | 
| 105 105 | 
             
                    end
         | 
| 106 106 |  | 
| 107 107 | 
             
                    describe 'for PDF with spreads and a cover' do
         | 
| 108 108 | 
             
                      it 'returns correct page count' do
         | 
| 109 | 
            -
                        analyser.call(spreads_cover, true)[:spread_count].must_equal 5
         | 
| 109 | 
            +
                        analyser.call(spreads_cover, spreads: true)[:spread_count].must_equal 5
         | 
| 110 110 | 
             
                      end
         | 
| 111 111 | 
             
                    end
         | 
| 112 112 |  | 
| 113 113 | 
             
                    describe 'for PDF with spreads and a back cover' do
         | 
| 114 114 | 
             
                      it 'returns correct page count' do
         | 
| 115 | 
            -
                        analyser.call(spreads_back, true)[:spread_count].must_equal 5
         | 
| 115 | 
            +
                        analyser.call(spreads_back, spreads: true)[:spread_count].must_equal 5
         | 
| 116 116 | 
             
                      end
         | 
| 117 117 | 
             
                    end
         | 
| 118 118 |  | 
| 119 119 | 
             
                    describe 'for PDF with spreads and a front and a back cover' do
         | 
| 120 120 | 
             
                      it 'returns correct page count' do
         | 
| 121 | 
            -
                        analyser.call(spreads_cover_back, true)[:spread_count].must_equal 6
         | 
| 121 | 
            +
                        analyser.call(spreads_cover_back, spreads: true)[:spread_count].must_equal 6
         | 
| 122 122 | 
             
                      end
         | 
| 123 123 | 
             
                    end
         | 
| 124 124 | 
             
                  end
         | 
| @@ -134,25 +134,25 @@ module DragonflyPdf | |
| 134 134 |  | 
| 135 135 | 
             
                    describe 'for PDF with spreads' do
         | 
| 136 136 | 
             
                      it 'returns widths' do
         | 
| 137 | 
            -
                        analyser.call(spreads, true)[:widths].must_equal [[210.0, 210.0], [210.0, 210.0], [210.0, 210.0], [210.0, 210.0]]
         | 
| 137 | 
            +
                        analyser.call(spreads, spreads: true)[:widths].must_equal [[210.0, 210.0], [210.0, 210.0], [210.0, 210.0], [210.0, 210.0]]
         | 
| 138 138 | 
             
                      end
         | 
| 139 139 | 
             
                    end
         | 
| 140 140 |  | 
| 141 141 | 
             
                    describe 'for PDF with spreads and a cover' do
         | 
| 142 142 | 
             
                      it 'returns correct widths' do
         | 
| 143 | 
            -
                        analyser.call(spreads_cover, true)[:widths].must_equal [[210.0], [210.0, 210.0], [210.0, 210.0], [210.0, 210.0], [210.0, 210.0]]
         | 
| 143 | 
            +
                        analyser.call(spreads_cover, spreads: true)[:widths].must_equal [[210.0], [210.0, 210.0], [210.0, 210.0], [210.0, 210.0], [210.0, 210.0]]
         | 
| 144 144 | 
             
                      end
         | 
| 145 145 | 
             
                    end
         | 
| 146 146 |  | 
| 147 147 | 
             
                    describe 'for PDF with spreads and a back cover' do
         | 
| 148 148 | 
             
                      it 'returns correct widths' do
         | 
| 149 | 
            -
                        analyser.call(spreads_back, true)[:widths].must_equal [[210.0, 210.0], [210.0, 210.0], [210.0, 210.0], [210.0, 210.0], [210.0]]
         | 
| 149 | 
            +
                        analyser.call(spreads_back, spreads: true)[:widths].must_equal [[210.0, 210.0], [210.0, 210.0], [210.0, 210.0], [210.0, 210.0], [210.0]]
         | 
| 150 150 | 
             
                      end
         | 
| 151 151 | 
             
                    end
         | 
| 152 152 |  | 
| 153 153 | 
             
                    describe 'for PDF with spreads and a front and a back cover' do
         | 
| 154 154 | 
             
                      it 'returns correct widths' do
         | 
| 155 | 
            -
                        analyser.call(spreads_cover_back, true)[:widths].must_equal [[210.0], [210.0, 210.0], [210.0, 210.0], [210.0, 210.0], [210.0, 210.0], [210.0]]
         | 
| 155 | 
            +
                        analyser.call(spreads_cover_back, spreads: true)[:widths].must_equal [[210.0], [210.0, 210.0], [210.0, 210.0], [210.0, 210.0], [210.0, 210.0], [210.0]]
         | 
| 156 156 | 
             
                      end
         | 
| 157 157 | 
             
                    end
         | 
| 158 158 | 
             
                  end
         | 
| @@ -168,25 +168,25 @@ module DragonflyPdf | |
| 168 168 |  | 
| 169 169 | 
             
                    describe 'for PDF with spreads' do
         | 
| 170 170 | 
             
                      it 'returns heights' do
         | 
| 171 | 
            -
                        analyser.call(spreads, true)[:heights].must_equal [[297.0, 297.0], [297.0, 297.0], [297.0, 297.0], [297.0, 297.0]]
         | 
| 171 | 
            +
                        analyser.call(spreads, spreads: true)[:heights].must_equal [[297.0, 297.0], [297.0, 297.0], [297.0, 297.0], [297.0, 297.0]]
         | 
| 172 172 | 
             
                      end
         | 
| 173 173 | 
             
                    end
         | 
| 174 174 |  | 
| 175 175 | 
             
                    describe 'for PDF with spreads and a cover' do
         | 
| 176 176 | 
             
                      it 'returns correct heights' do
         | 
| 177 | 
            -
                        analyser.call(spreads_cover, true)[:heights].must_equal [[297.0], [297.0, 297.0], [297.0, 297.0], [297.0, 297.0], [297.0, 297.0]]
         | 
| 177 | 
            +
                        analyser.call(spreads_cover, spreads: true)[:heights].must_equal [[297.0], [297.0, 297.0], [297.0, 297.0], [297.0, 297.0], [297.0, 297.0]]
         | 
| 178 178 | 
             
                      end
         | 
| 179 179 | 
             
                    end
         | 
| 180 180 |  | 
| 181 181 | 
             
                    describe 'for PDF with spreads and a back cover' do
         | 
| 182 182 | 
             
                      it 'returns correct heights' do
         | 
| 183 | 
            -
                        analyser.call(spreads_back, true)[:heights].must_equal [[297.0, 297.0], [297.0, 297.0], [297.0, 297.0], [297.0, 297.0], [297.0]]
         | 
| 183 | 
            +
                        analyser.call(spreads_back, spreads: true)[:heights].must_equal [[297.0, 297.0], [297.0, 297.0], [297.0, 297.0], [297.0, 297.0], [297.0]]
         | 
| 184 184 | 
             
                      end
         | 
| 185 185 | 
             
                    end
         | 
| 186 186 |  | 
| 187 187 | 
             
                    describe 'for PDF with spreads and a front and a back cover' do
         | 
| 188 188 | 
             
                      it 'returns correct heights' do
         | 
| 189 | 
            -
                        analyser.call(spreads_cover_back, true)[:heights].must_equal [[297.0], [297.0, 297.0], [297.0, 297.0], [297.0, 297.0], [297.0, 297.0], [297.0]]
         | 
| 189 | 
            +
                        analyser.call(spreads_cover_back, spreads: true)[:heights].must_equal [[297.0], [297.0, 297.0], [297.0, 297.0], [297.0, 297.0], [297.0, 297.0], [297.0]]
         | 
| 190 190 | 
             
                      end
         | 
| 191 191 | 
             
                    end
         | 
| 192 192 | 
             
                  end
         | 
| @@ -202,25 +202,25 @@ module DragonflyPdf | |
| 202 202 |  | 
| 203 203 | 
             
                    describe 'for PDF with spreads' do
         | 
| 204 204 | 
             
                      it 'returns aspect ratios' do
         | 
| 205 | 
            -
                        analyser.call(spreads, true)[:aspect_ratios].map{ |i| i.is_a?(Array) ? i.map{ |j| j.round(2) } : i.round(2) }.must_equal [[0.71, 0.71], [0.71, 0.71], [0.71, 0.71], [0.71, 0.71]]
         | 
| 205 | 
            +
                        analyser.call(spreads, spreads: true)[:aspect_ratios].map{ |i| i.is_a?(Array) ? i.map{ |j| j.round(2) } : i.round(2) }.must_equal [[0.71, 0.71], [0.71, 0.71], [0.71, 0.71], [0.71, 0.71]]
         | 
| 206 206 | 
             
                      end
         | 
| 207 207 | 
             
                    end
         | 
| 208 208 |  | 
| 209 209 | 
             
                    describe 'for PDF with spreads and a cover' do
         | 
| 210 210 | 
             
                      it 'returns correct aspect ratios' do
         | 
| 211 | 
            -
                        analyser.call(spreads_cover, true)[:aspect_ratios].map{ |i| i.is_a?(Array) ? i.map{ |j| j.round(2) } : i.round(2) }.must_equal [[0.71], [0.71, 0.71], [0.71, 0.71], [0.71, 0.71], [0.71, 0.71]]
         | 
| 211 | 
            +
                        analyser.call(spreads_cover, spreads: true)[:aspect_ratios].map{ |i| i.is_a?(Array) ? i.map{ |j| j.round(2) } : i.round(2) }.must_equal [[0.71], [0.71, 0.71], [0.71, 0.71], [0.71, 0.71], [0.71, 0.71]]
         | 
| 212 212 | 
             
                      end
         | 
| 213 213 | 
             
                    end
         | 
| 214 214 |  | 
| 215 215 | 
             
                    describe 'for PDF with spreads and a back cover' do
         | 
| 216 216 | 
             
                      it 'returns correct aspect ratios' do
         | 
| 217 | 
            -
                        analyser.call(spreads_back, true)[:aspect_ratios].map{ |i| i.is_a?(Array) ? i.map{ |j| j.round(2) } : i.round(2) }.must_equal [[0.71, 0.71], [0.71, 0.71], [0.71, 0.71], [0.71, 0.71], [0.71]]
         | 
| 217 | 
            +
                        analyser.call(spreads_back, spreads: true)[:aspect_ratios].map{ |i| i.is_a?(Array) ? i.map{ |j| j.round(2) } : i.round(2) }.must_equal [[0.71, 0.71], [0.71, 0.71], [0.71, 0.71], [0.71, 0.71], [0.71]]
         | 
| 218 218 | 
             
                      end
         | 
| 219 219 | 
             
                    end
         | 
| 220 220 |  | 
| 221 221 | 
             
                    describe 'for PDF with spreads and a front and a back cover' do
         | 
| 222 222 | 
             
                      it 'returns correct aspect ratios' do
         | 
| 223 | 
            -
                        analyser.call(spreads_cover_back, true)[:aspect_ratios].map{ |i| i.is_a?(Array) ? i.map{ |j| j.round(2) } : i.round(2) }.must_equal [[0.71], [0.71, 0.71], [0.71, 0.71], [0.71, 0.71], [0.71, 0.71], [0.71]]
         | 
| 223 | 
            +
                        analyser.call(spreads_cover_back, spreads: true)[:aspect_ratios].map{ |i| i.is_a?(Array) ? i.map{ |j| j.round(2) } : i.round(2) }.must_equal [[0.71], [0.71, 0.71], [0.71, 0.71], [0.71, 0.71], [0.71, 0.71], [0.71]]
         | 
| 224 224 | 
             
                      end
         | 
| 225 225 | 
             
                    end
         | 
| 226 226 | 
             
                  end
         | 
| @@ -32,5 +32,17 @@ module DragonflyPdf | |
| 32 32 | 
             
                  end
         | 
| 33 33 | 
             
                end
         | 
| 34 34 |  | 
| 35 | 
            +
             | 
| 36 | 
            +
                # ---------------------------------------------------------------------
         | 
| 37 | 
            +
                
         | 
| 38 | 
            +
                describe 'processors' do
         | 
| 39 | 
            +
                  it 'adds #page' do
         | 
| 40 | 
            +
                    pdf.must_respond_to :page
         | 
| 41 | 
            +
                  end
         | 
| 42 | 
            +
                  it 'adds #page_thumb' do
         | 
| 43 | 
            +
                    pdf.must_respond_to :page_thumb
         | 
| 44 | 
            +
                  end
         | 
| 45 | 
            +
                end
         | 
| 46 | 
            +
             | 
| 35 47 | 
             
              end
         | 
| 36 48 | 
             
            end
         | 
| @@ -0,0 +1,84 @@ | |
| 1 | 
            +
            require 'test_helper'
         | 
| 2 | 
            +
            require 'pdf-reader'
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            module DragonflyPdf
         | 
| 5 | 
            +
              module Processors
         | 
| 6 | 
            +
                describe Page do
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                  let(:app) { test_app.configure_with(:pdf) }
         | 
| 9 | 
            +
                  let(:processor) { DragonflyPdf::Processors::Page.new }
         | 
| 10 | 
            +
             | 
| 11 | 
            +
                  let(:single_pages) { Dragonfly::Content.new(app, SAMPLES_DIR.join('sample_pages.pdf')) }
         | 
| 12 | 
            +
                  let(:spreads) { Dragonfly::Content.new(app, SAMPLES_DIR.join('sample_spreads.pdf')) }
         | 
| 13 | 
            +
                  let(:spreads_back) { Dragonfly::Content.new(app, SAMPLES_DIR.join('sample_spreads_back.pdf')) }
         | 
| 14 | 
            +
                  let(:spreads_cover) { Dragonfly::Content.new(app, SAMPLES_DIR.join('sample_spreads_cover.pdf')) }
         | 
| 15 | 
            +
                  let(:spreads_cover_back) { Dragonfly::Content.new(app, SAMPLES_DIR.join('sample_spreads_cover_back.pdf')) }
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                  # =====================================================================
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                  it 'returns PDF by default' do
         | 
| 20 | 
            +
                    processor.call(single_pages, 1)
         | 
| 21 | 
            +
                    get_mime_type(single_pages.path).must_include "application/pdf"
         | 
| 22 | 
            +
                  end
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                  it 'raises PageNotFound error' do
         | 
| 25 | 
            +
                    proc { processor.call(single_pages, 0) }.must_raise DragonflyPdf::PageNotFound
         | 
| 26 | 
            +
                    proc { processor.call(single_pages, 11) }.must_raise DragonflyPdf::PageNotFound
         | 
| 27 | 
            +
                  end
         | 
| 28 | 
            +
             | 
| 29 | 
            +
                  # ---------------------------------------------------------------------
         | 
| 30 | 
            +
             | 
| 31 | 
            +
                  describe 'single pages' do
         | 
| 32 | 
            +
                    it 'renders page' do
         | 
| 33 | 
            +
                      processor.call(single_pages, 1)
         | 
| 34 | 
            +
                      pdf = PDF::Reader.new(single_pages.path)
         | 
| 35 | 
            +
                      pdf.pages.count.must_equal 1
         | 
| 36 | 
            +
                      pdf.pages.first.text.must_equal '1'
         | 
| 37 | 
            +
                    end
         | 
| 38 | 
            +
                  end
         | 
| 39 | 
            +
             | 
| 40 | 
            +
                  describe 'spreads' do
         | 
| 41 | 
            +
                    it 'recalculates the page number correctly' do
         | 
| 42 | 
            +
                      processor.call(spreads, 8, spreads: true)
         | 
| 43 | 
            +
                      pdf = PDF::Reader.new(spreads.path)
         | 
| 44 | 
            +
                      pdf.pages.count.must_equal 1
         | 
| 45 | 
            +
                      pdf.pages.first.text.must_include '8'
         | 
| 46 | 
            +
                    end
         | 
| 47 | 
            +
                  end
         | 
| 48 | 
            +
             | 
| 49 | 
            +
                  describe 'spreads_back' do
         | 
| 50 | 
            +
                    it 'recalculates the page number correctly' do
         | 
| 51 | 
            +
                      processor.call(spreads_back, 9, spreads: true)
         | 
| 52 | 
            +
                      pdf = PDF::Reader.new(spreads_back.path)
         | 
| 53 | 
            +
                      pdf.pages.count.must_equal 1
         | 
| 54 | 
            +
                      pdf.pages.first.text.must_include '9'
         | 
| 55 | 
            +
                    end
         | 
| 56 | 
            +
                  end
         | 
| 57 | 
            +
             | 
| 58 | 
            +
                  describe 'spreads_cover' do
         | 
| 59 | 
            +
                    it 'recalculates the page number correctly' do
         | 
| 60 | 
            +
                      processor.call(spreads_cover, 9, spreads: true)
         | 
| 61 | 
            +
                      pdf = PDF::Reader.new(spreads_cover.path)
         | 
| 62 | 
            +
                      pdf.pages.count.must_equal 1
         | 
| 63 | 
            +
                      pdf.pages.first.text.must_include '9'
         | 
| 64 | 
            +
                    end
         | 
| 65 | 
            +
                  end
         | 
| 66 | 
            +
             | 
| 67 | 
            +
                  describe 'spreads_cover_back' do
         | 
| 68 | 
            +
                    it 'recalculates the page number correctly' do
         | 
| 69 | 
            +
                      processor.call(spreads_cover_back, 10, spreads: true)
         | 
| 70 | 
            +
                      pdf = PDF::Reader.new(spreads_cover_back.path)
         | 
| 71 | 
            +
                      pdf.pages.count.must_equal 1
         | 
| 72 | 
            +
                      pdf.pages.first.text.must_include '10'
         | 
| 73 | 
            +
                    end
         | 
| 74 | 
            +
                  end
         | 
| 75 | 
            +
             | 
| 76 | 
            +
                  # ---------------------------------------------------------------------
         | 
| 77 | 
            +
             | 
| 78 | 
            +
                  def get_mime_type file_path
         | 
| 79 | 
            +
                    `file --mime-type #{file_path}`.gsub(/\n/, "")
         | 
| 80 | 
            +
                  end
         | 
| 81 | 
            +
             | 
| 82 | 
            +
                end
         | 
| 83 | 
            +
              end
         | 
| 84 | 
            +
            end
         | 
| @@ -15,10 +15,15 @@ module DragonflyPdf | |
| 15 15 | 
             
                  let(:spreads_cover_back) { Dragonfly::Content.new(app, SAMPLES_DIR.join('sample_spreads_cover_back.pdf')) }
         | 
| 16 16 |  | 
| 17 17 | 
             
                  it 'returns PNG by default' do
         | 
| 18 | 
            -
                    processor.call(single_pages,  | 
| 18 | 
            +
                    processor.call(single_pages, 1, density: 72)
         | 
| 19 19 | 
             
                    get_mime_type(single_pages.path).must_include "image/png"
         | 
| 20 20 | 
             
                  end
         | 
| 21 21 |  | 
| 22 | 
            +
                  it 'raises PageNotFound error' do
         | 
| 23 | 
            +
                    proc { processor.call(single_pages, 0) }.must_raise DragonflyPdf::PageNotFound
         | 
| 24 | 
            +
                    proc { processor.call(single_pages, 11) }.must_raise DragonflyPdf::PageNotFound
         | 
| 25 | 
            +
                  end
         | 
| 26 | 
            +
             | 
| 22 27 | 
             
                  # ---------------------------------------------------------------------
         | 
| 23 28 |  | 
| 24 29 | 
             
                  describe 'single pages' do
         | 
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: dragonfly_pdf
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.0. | 
| 4 | 
            +
              version: 0.0.2
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Tomas Celizna
         | 
| @@ -124,7 +124,9 @@ files: | |
| 124 124 | 
             
            - dragonfly_pdf.gemspec
         | 
| 125 125 | 
             
            - lib/dragonfly_pdf.rb
         | 
| 126 126 | 
             
            - lib/dragonfly_pdf/analysers/pdf_properties.rb
         | 
| 127 | 
            +
            - lib/dragonfly_pdf/errors.rb
         | 
| 127 128 | 
             
            - lib/dragonfly_pdf/plugin.rb
         | 
| 129 | 
            +
            - lib/dragonfly_pdf/processors/page.rb
         | 
| 128 130 | 
             
            - lib/dragonfly_pdf/processors/page_thumb.rb
         | 
| 129 131 | 
             
            - lib/dragonfly_pdf/version.rb
         | 
| 130 132 | 
             
            - samples/sample_pages.pdf
         | 
| @@ -134,6 +136,7 @@ files: | |
| 134 136 | 
             
            - samples/sample_spreads_cover_back.pdf
         | 
| 135 137 | 
             
            - test/dragonfly_pdf/analysers/pdf_properties_test.rb
         | 
| 136 138 | 
             
            - test/dragonfly_pdf/plugin_test.rb
         | 
| 139 | 
            +
            - test/dragonfly_pdf/processors/page_test.rb
         | 
| 137 140 | 
             
            - test/dragonfly_pdf/processors/page_thumb_test.rb
         | 
| 138 141 | 
             
            - test/test_helper.rb
         | 
| 139 142 | 
             
            homepage: https://github.com/tomasc/dragonfly_pdf
         | 
| @@ -163,5 +166,6 @@ summary: Dragonfly PDF analysers and processors. | |
| 163 166 | 
             
            test_files:
         | 
| 164 167 | 
             
            - test/dragonfly_pdf/analysers/pdf_properties_test.rb
         | 
| 165 168 | 
             
            - test/dragonfly_pdf/plugin_test.rb
         | 
| 169 | 
            +
            - test/dragonfly_pdf/processors/page_test.rb
         | 
| 166 170 | 
             
            - test/dragonfly_pdf/processors/page_thumb_test.rb
         | 
| 167 171 | 
             
            - test/test_helper.rb
         |