pdfunite 0.3.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 29e5d158cd6b9da9c8492fffbd17a1ed0bd2045f
4
- data.tar.gz: e0089aa79fea511177dcce053b6f866cff2f801d
2
+ SHA256:
3
+ metadata.gz: 5cd07900239253b89f736e0bc2afaa4dfddf82b295c40727cc6db334af7b7422
4
+ data.tar.gz: 4a11eb86bdf95d083a835a42639bb840a7fe372e3e9377dde1e0fb6e37f440c0
5
5
  SHA512:
6
- metadata.gz: 469e1202c596ba22cd4a238f4070395dfc200582c05363bb8fe6355526d087f2056f0bf794af63745d0ed9e9754324afbb429a8b9916978b3abaf4a4ee0ba77c
7
- data.tar.gz: a6c5dc3dff1d243d3ed43e377ff2304a756b0f0079ddb5021416ee488a028c959385b1b16dd55450c04f883d17b1971319309cd8198f18e797223df3d566393a
6
+ metadata.gz: 42098f2bd77ce44e2ad7cc9a1446e9d31e2f506beaa0b0604613d9eb3cde43912118b79890ea431b901c3d63e95b4e1a14f5478115ec2c9059d7eb69c0f7f8e7
7
+ data.tar.gz: 72ef4ee8e99caad4de5ef4fb4c62ba406c04565c4241d2067006bf935cf9589146d587405b80a25d91dfdd1dbfa799281805041b6c9dc7eb68a0e943bdd909a4
data/CHANGELOG CHANGED
@@ -1,3 +1,7 @@
1
+ 0.5.0 - Jul 4, 2019
2
+
3
+ * Drop cocaine dependency
4
+
1
5
  0.3.0 - Dec 6, 2014
2
6
 
3
7
  * Do not read existing files, use paths instead
@@ -5,5 +9,3 @@
5
9
  0.2.0 - Nov 27, 2014
6
10
 
7
11
  * added Pdfunite.binary configuration option
8
-
9
-
data/README.md CHANGED
@@ -1,3 +1,4 @@
1
+ [![Gem Version](https://badge.fury.io/rb/pdfunite.svg)](http://badge.fury.io/rb/pdfunite) [![Build Status](https://travis-ci.org/mtgrosser/pdfunite.svg)](https://travis-ci.org/mtgrosser/pdfunite)
1
2
  # Pdfunite
2
3
 
3
4
  Merge PDF files with Ruby.
@@ -30,7 +31,7 @@ gem 'pdfunite'
30
31
  ```ruby
31
32
  # Join existing PDF files
32
33
  pdf_data = Pdfunite.join('file1.pdf', 'file2.pdf', 'file3.pdf')
33
- File.open('joined.pdf', 'wb') { f << pdf_data }
34
+ File.open('joined.pdf', 'wb') { |f| f << pdf_data }
34
35
 
35
36
  # Join PDF binary data provided by a collection of objects
36
37
  pdf_data = Pdfunite.join(objects) { |obj| obj.to_pdf }
@@ -1,7 +1,8 @@
1
1
  require 'pdfunite/version'
2
2
  require 'tmpdir'
3
3
  require 'pathname'
4
- require 'cocaine'
4
+ require 'open3'
5
+ require 'shellwords'
5
6
  require 'logger'
6
7
 
7
8
  module Pdfunite
@@ -42,8 +43,7 @@ module Pdfunite
42
43
  output = nil
43
44
  Dir.mktmpdir do |dir|
44
45
  tmpdir = Pathname.new(dir).realpath
45
- files = args.flatten(1).inject({}) do |hsh, arg|
46
- idx = hsh.size
46
+ files = args.flatten(1).collect.with_index do |arg, idx|
47
47
  realpath = if block_given?
48
48
  data = yield(arg)
49
49
  file = tmpdir.join("#{idx}.pdf")
@@ -52,19 +52,29 @@ module Pdfunite
52
52
  else
53
53
  Pathname.new(arg).realpath
54
54
  end
55
- hsh.update(:"f_#{idx}" => realpath.to_s)
55
+ realpath.to_s
56
56
  end
57
- cmdline = Cocaine::CommandLine.new(binary, "#{files.keys.map(&:inspect).join(' ')} :outfile", logger: Pdfunite.logger || Logger.new(STDOUT))
58
57
  outfile = tmpdir.join('output.pdf')
59
- begin
60
- cmdline.run(files.merge(outfile: outfile.to_s))
61
- rescue Cocaine::CommandNotFoundError
62
- raise BinaryNotFound, "The pdfunite executable could not be found at #{binary.inspect}. Check the pdfunite README for more info."
63
- end
64
- output = outfile.binread
58
+ cmdline = [binary.to_s, *files, outfile.to_s]
59
+ output = outfile.binread if run_command(cmdline.shelljoin)
65
60
  end
66
61
  output
67
62
  end
68
- end
69
63
 
64
+ private
65
+
66
+ def run_command(cmdline)
67
+ logger = Pdfunite.logger || Logger.new(STDOUT)
68
+ stdout, stderr, status = Open3.capture3(cmdline)
69
+ logger.info "Pdfunite: #{cmdline}"
70
+ raise unless status.success?
71
+ true
72
+ rescue Errno::ENOENT
73
+ raise BinaryNotFound, "The pdfunite executable could not be found at #{binary.inspect}. Check the pdfunite README for more info."
74
+ rescue => e
75
+ logger.error "Pdfunite error: #{e}\ncommand: #{cmdline}\nerror: #{stderr}"
76
+ false
77
+ end
78
+
79
+ end
70
80
  end
@@ -1,3 +1,3 @@
1
1
  module Pdfunite
2
- VERSION = '0.3.0'
2
+ VERSION = '0.5.0'
3
3
  end
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pdfunite
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthias Grosser
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-06 00:00:00.000000000 Z
11
+ date: 2019-07-04 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: cocaine
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '0.5'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '0.5'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: bundler
29
15
  requirement: !ruby/object:Gem::Requirement
@@ -126,8 +112,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
126
112
  - !ruby/object:Gem::Version
127
113
  version: '0'
128
114
  requirements: []
129
- rubyforge_project:
130
- rubygems_version: 2.2.2
115
+ rubygems_version: 3.0.3
131
116
  signing_key:
132
117
  specification_version: 4
133
118
  summary: Merge PDF files with Ruby - no Java required