libreconv 0.9.0 → 0.9.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 14a16a3e394c4ba9f9d7f69656286f2cdd309a07
4
- data.tar.gz: f2768dd2c7905a798f24b62e107270430f37dd57
2
+ SHA256:
3
+ metadata.gz: 6c15c8557e480e6dff15a4c3fe8f3e5d9a9c6a46c43203df1def06fd7ddbb7fe
4
+ data.tar.gz: 41c3505b47c3de9dfe6ead9b965d0462fdc38e2afcf56b2454f9c2b3a583cfb6
5
5
  SHA512:
6
- metadata.gz: 07d5b921a16008271f6a4eaf5ed074279e3ab47199fe694ab5b96d9608e8f322f4c4297a1f3119c436bb2701c16a691050a29ce9efbeca4fa24c4991e2a9b676
7
- data.tar.gz: 04805b8bf5fd94960161f22c2d9635ddb8361990059e18fdfb2d61758ead3030292c16b261550c28ece1531739e930dbf564bd7da39400c3eb4aa56a7b605c17
6
+ metadata.gz: 2d28320784b82c47670bdde73138e664b073c94455327403dcd3e444157bdb093b0a2f3f93f8335703010c3237cae80c154cee42605842e7dd8275f877197758
7
+ data.tar.gz: 911898a953f283f81d957ab6aabf8a273038e0856f446baa5e9c133eaa0b6163cee24e968c7c03ccbd600677426680fc5ff49b54bd6161913081c91f79256913
data/.gitignore CHANGED
@@ -3,7 +3,6 @@
3
3
  .bundle
4
4
  .config
5
5
  .yardoc
6
- Gemfile.lock
7
6
  InstalledFiles
8
7
  _yardoc
9
8
  coverage
@@ -15,6 +14,7 @@ spec/reports
15
14
  test/tmp
16
15
  test/version_tmp
17
16
  tmp
17
+ .idea/
18
18
 
19
19
  TODO.md
20
20
 
data/.rubocop.yml ADDED
@@ -0,0 +1,25 @@
1
+ require: rubocop-rspec
2
+
3
+ Metrics/AbcSize:
4
+ # Max: 25
5
+ Enabled: false
6
+
7
+ Metrics/MethodLength:
8
+ # Max: 20
9
+ Enabled: false
10
+
11
+ Metrics/CyclomaticComplexity:
12
+ # Max: 10
13
+ Enabled: false
14
+
15
+ Metrics/BlockLength:
16
+ Enabled: false
17
+
18
+ Metrics/PerceivedComplexity:
19
+ Enabled: false
20
+
21
+ RSpec/ExampleLength:
22
+ Enabled: false
23
+
24
+ Style/Documentation:
25
+ Enabled: false
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.5.3
data/.travis.yml CHANGED
@@ -1,12 +1,7 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 1.9.3
4
- - 2.0.0
5
- - 2.1.1
6
- - jruby-19mode
7
- - jruby-head
8
- notifications:
9
- recipients:
10
- - ricny046@gmail.com
3
+ - 2.2.0
4
+ - 2.5.3
11
5
  before_install:
6
+ - sudo apt-get update -qq
12
7
  - sudo apt-get install libreoffice
data/Gemfile CHANGED
@@ -1,4 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in libreconv.gemspec
4
6
  gemspec
7
+
8
+ group :development, :test do
9
+ gem 'pry-byebug'
10
+ gem 'rubocop', require: false
11
+ gem 'rubocop-rspec', require: false
12
+ gem 'webmock'
13
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,78 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ libreconv (0.9.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ addressable (2.5.2)
10
+ public_suffix (>= 2.0.2, < 4.0)
11
+ ast (2.4.0)
12
+ byebug (10.0.2)
13
+ coderay (1.1.2)
14
+ crack (0.4.3)
15
+ safe_yaml (~> 1.0.0)
16
+ diff-lcs (1.3)
17
+ hashdiff (0.3.7)
18
+ jaro_winkler (1.5.1)
19
+ method_source (0.9.2)
20
+ parallel (1.12.1)
21
+ parser (2.5.3.0)
22
+ ast (~> 2.4.0)
23
+ powerpack (0.1.2)
24
+ pry (0.12.2)
25
+ coderay (~> 1.1.0)
26
+ method_source (~> 0.9.0)
27
+ pry-byebug (3.6.0)
28
+ byebug (~> 10.0)
29
+ pry (~> 0.10)
30
+ public_suffix (3.0.3)
31
+ rainbow (3.0.0)
32
+ rake (12.3.2)
33
+ rspec (3.8.0)
34
+ rspec-core (~> 3.8.0)
35
+ rspec-expectations (~> 3.8.0)
36
+ rspec-mocks (~> 3.8.0)
37
+ rspec-core (3.8.0)
38
+ rspec-support (~> 3.8.0)
39
+ rspec-expectations (3.8.2)
40
+ diff-lcs (>= 1.2.0, < 2.0)
41
+ rspec-support (~> 3.8.0)
42
+ rspec-mocks (3.8.0)
43
+ diff-lcs (>= 1.2.0, < 2.0)
44
+ rspec-support (~> 3.8.0)
45
+ rspec-support (3.8.0)
46
+ rubocop (0.61.1)
47
+ jaro_winkler (~> 1.5.1)
48
+ parallel (~> 1.10)
49
+ parser (>= 2.5, != 2.5.1.1)
50
+ powerpack (~> 0.1)
51
+ rainbow (>= 2.2.2, < 4.0)
52
+ ruby-progressbar (~> 1.7)
53
+ unicode-display_width (~> 1.4.0)
54
+ rubocop-rspec (1.30.1)
55
+ rubocop (>= 0.60.0)
56
+ ruby-progressbar (1.10.0)
57
+ safe_yaml (1.0.4)
58
+ unicode-display_width (1.4.0)
59
+ webmock (3.4.2)
60
+ addressable (>= 2.3.6)
61
+ crack (>= 0.3.2)
62
+ hashdiff
63
+
64
+ PLATFORMS
65
+ ruby
66
+
67
+ DEPENDENCIES
68
+ bundler
69
+ libreconv!
70
+ pry-byebug
71
+ rake
72
+ rspec (~> 3.8.0)
73
+ rubocop
74
+ rubocop-rspec
75
+ webmock
76
+
77
+ BUNDLED WITH
78
+ 1.17.1
data/README.md CHANGED
@@ -1,9 +1,9 @@
1
1
  # Libreconv
2
2
 
3
- Convert office documents to PDF using LibreOffice / OpenOffice.
3
+ Convert office documents using LibreOffice / OpenOffice to one of their supported formats.
4
4
 
5
- [![Code Climate](https://codeclimate.com/github/ricn/libreconv.png)](https://codeclimate.com/github/ricn/libreconv)
6
- [![Build Status](https://travis-ci.org/ricn/libreconv.png?branch=master)](https://travis-ci.org/ricn/libreconv)
5
+ [![Build Status](https://travis-ci.org/FormAPI/libreconv.png?branch=master)](https://travis-ci.org/FormAPI/libreconv)
6
+ [![Gem Version](https://badge.fury.io/rb/libreconv.svg)](http://badge.fury.io/rb/libreconv)
7
7
 
8
8
  ## Installation
9
9
 
@@ -21,7 +21,7 @@ Or install it yourself as:
21
21
 
22
22
  ## Usage
23
23
 
24
- You need to install Libreoffice or Openoffice on your system to use this gem. The code has been tested with Libreoffice 4.2.
24
+ You need to install Libreoffice or Openoffice on your system to use this gem. The code has been tested with Libreoffice 6.1.3.
25
25
 
26
26
  ```ruby
27
27
  require 'libreconv'
@@ -37,10 +37,19 @@ Libreconv.convert('document.docx', '/Users/ricn/pdf_documents')
37
37
  # You can also convert a source file directly from an URL
38
38
  Libreconv.convert('http://myserver.com/123/document.docx', '/Users/ricn/pdf_documents/doc.pdf')
39
39
 
40
+ # You cal pass a URL with GET params like this S3 example
41
+ Libreconv.convert('https://mybucket.s3.amazonaws.com/myserver/123/document.docx?X-Amz-Expires=456&X-Amz-Signature=abc', '/Users/ricn/pdf_documents/doc.pdf')
42
+
40
43
  # Converts document.docx to document.pdf
41
44
  # If you for some reason can't have soffice in your PATH you can specifiy the file path to the soffice binary
42
45
  Libreconv.convert('document.docx', '/Users/ricn/pdf_documents', '/Applications/LibreOffice.app/Contents/MacOS/soffice')
43
46
 
47
+ # Converts document.docx to my_document_as.html
48
+ Libreconv.convert('document.docx', '/Users/ricn/pdf_documents/my_document_as.html', nil, 'html')
49
+
50
+ # Converts document.docx to my_document_as.pdf using writer_pdf_Export filter
51
+ Libreconv.convert('document.docx', '/Users/ricn/pdf_documents/my_document_as.pdf', nil, 'pdf:writer_pdf_Export')
52
+
44
53
  ```
45
54
 
46
55
  ## Credits
@@ -48,9 +57,13 @@ Libreconv.convert('document.docx', '/Users/ricn/pdf_documents', '/Applications/L
48
57
  The following people have contributed ideas, documentation, or code to Libreconv:
49
58
 
50
59
  * Richard Nyström
60
+ * Nathan Broadbent
51
61
 
52
62
  ## Contributing
53
63
 
64
+ * Install LibreOffice on Linux: `sudo apt-get install libreoffice`
65
+ * Install LibreOffice on Mac: `brew cask install libreoffice`
66
+
54
67
  1. Fork it
55
68
  2. Create your feature branch (`git checkout -b my-new-feature`)
56
69
  3. Commit your changes (`git commit -am 'Add some feature'`)
data/Rakefile CHANGED
@@ -1,6 +1,8 @@
1
- require "bundler/gem_tasks"
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
2
4
  require 'rspec/core/rake_task'
3
5
 
4
6
  RSpec::Core::RakeTask.new(:spec)
5
7
 
6
- task :default => :spec
8
+ task default: :spec
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Libreconv
2
- VERSION = "0.9.0"
4
+ VERSION = '0.9.2'
3
5
  end
data/lib/libreconv.rb CHANGED
@@ -1,48 +1,108 @@
1
- require "libreconv/version"
2
- require "uri"
3
- require "net/http"
4
- require "tmpdir"
5
- require "spoon"
1
+ # frozen_string_literal: true
2
+
3
+ require 'libreconv/version'
4
+ require 'uri'
5
+ require 'net/http'
6
+ require 'tmpdir'
7
+ require 'securerandom'
8
+ require 'open3'
6
9
 
7
10
  module Libreconv
11
+ class ConversionFailedError < StandardError; end
12
+
13
+ SOURCE_TYPES = {
14
+ file: 1,
15
+ url: 2
16
+ }.freeze
8
17
 
9
- def self.convert(source, target, soffice_command = nil)
10
- Converter.new(source, target, soffice_command).convert
18
+ def self.convert(source, target, soffice_command = nil, convert_to = nil)
19
+ Converter.new(source, target, soffice_command, convert_to).convert
11
20
  end
12
21
 
13
22
  class Converter
14
23
  attr_accessor :soffice_command
15
24
 
16
- def initialize(source, target, soffice_command = nil)
25
+ def initialize(source, target, soffice_command = nil, convert_to = nil)
17
26
  @source = source
18
27
  @target = target
19
- @target_path = Dir.tmpdir
20
- @soffice_command = soffice_command
21
- determine_soffice_command
22
- check_source_type
28
+ @soffice_command =
29
+ soffice_command ||
30
+ which('soffice') ||
31
+ which('soffice.bin')
32
+ @convert_to = convert_to || 'pdf'
33
+ @source_type = check_source_type
23
34
 
24
- unless @soffice_command && File.exists?(@soffice_command)
25
- raise IOError, "Can't find Libreoffice or Openoffice executable."
26
- end
35
+ # If the URL contains GET params, the '&' could break when
36
+ # being used as an argument to soffice. Wrap it in single
37
+ # quotes to escape it. Then strip them from the target
38
+ # temp file name.
39
+ @escaped_source =
40
+ if @source_type == 1
41
+ @source
42
+ else
43
+ "'#{@source}'"
44
+ end
45
+ @escaped_source_path =
46
+ if @source_type == 1
47
+ @source
48
+ else
49
+ URI.parse(@source).path
50
+ end
51
+
52
+ ensure_soffice_exists
27
53
  end
28
54
 
29
55
  def convert
30
- orig_stdout = $stdout.clone
31
- $stdout.reopen File.new('/dev/null', 'w')
32
- pid = Spoon.spawnp(@soffice_command, "--headless", "--convert-to", "pdf", @source, "--outdir", @target_path)
33
- Process.waitpid(pid)
34
- $stdout.reopen orig_stdout
35
- target_tmp_file = "#{@target_path}/#{File.basename(@source, ".*")}.pdf"
36
- FileUtils.cp target_tmp_file, @target
56
+ pipe_uuid = SecureRandom.uuid
57
+
58
+ Dir.mktmpdir do |target_path|
59
+ accept_args = [
60
+ "pipe,name=soffice-pipe-#{pipe_uuid}",
61
+ 'url',
62
+ 'StarOffice.ServiceManager'
63
+ ].join(';')
64
+
65
+ command = [
66
+ soffice_command,
67
+ "--accept=\"#{accept_args}\"",
68
+ "-env:UserInstallation=file:///tmp/soffice-dir-#{pipe_uuid}",
69
+ '--headless',
70
+ '--convert-to',
71
+ @convert_to,
72
+ @escaped_source,
73
+ '--outdir',
74
+ target_path
75
+ ]
76
+
77
+ output, error, status = Open3.capture3(
78
+ {
79
+ 'HOME' => ENV['HOME'],
80
+ 'PATH' => ENV['PATH'],
81
+ 'LANG' => ENV['LANG']
82
+ },
83
+ *command,
84
+ unsetenv_others: true
85
+ )
86
+ unless status.success? && error == ''
87
+ raise ConversionFailedError,
88
+ "Conversion failed! Output: #{output.strip.inspect}, " \
89
+ "Error: #{error.strip.inspect}"
90
+ end
91
+
92
+ target_tmp_file = "#{target_path}/" \
93
+ "#{File.basename(@escaped_source_path, '.*')}." \
94
+ "#{File.basename(@convert_to, ':*')}"
95
+ FileUtils.cp target_tmp_file, @target
96
+ FileUtils.rm_rf("/tmp/soffice-dir-#{pipe_uuid}")
97
+ end
37
98
  end
38
99
 
39
100
  private
40
101
 
41
- def determine_soffice_command
42
- unless @soffice_command
43
- @soffice_command ||= which("soffice")
44
- @soffice_command ||= which("soffice.bin")
45
- end
102
+ def ensure_soffice_exists
103
+ return if soffice_command && File.exist?(soffice_command)
104
+
105
+ raise IOError, "Can't find Libreoffice or Openoffice executable."
46
106
  end
47
107
 
48
108
  def which(cmd)
@@ -54,14 +114,23 @@ module Libreconv
54
114
  end
55
115
  end
56
116
 
57
- return nil
117
+ nil
58
118
  end
59
119
 
60
120
  def check_source_type
61
- is_file = File.exists?(@source) && !File.directory?(@source)
62
- is_http = URI(@source).scheme == "http" && Net::HTTP.get_response(URI(@source)).is_a?(Net::HTTPSuccess)
63
- is_https = URI(@source).scheme == "https" && Net::HTTP.get_response(URI(@source)).is_a?(Net::HTTPSuccess)
64
- raise IOError, "Source (#{@source}) is neither a file nor an URL." unless is_file || is_http || is_https
121
+ if File.exist?(@source) && !File.directory?(@source)
122
+ return SOURCE_TYPES[:file]
123
+ end
124
+ if URI(@source).scheme == 'http' &&
125
+ Net::HTTP.get_response(URI(@source)).is_a?(Net::HTTPSuccess)
126
+ return SOURCE_TYPES[:url]
127
+ end
128
+ if URI(@source).scheme == 'https' &&
129
+ Net::HTTP.get_response(URI(@source)).is_a?(Net::HTTPSuccess)
130
+ return SOURCE_TYPES[:url]
131
+ end
132
+
133
+ raise IOError, "Source (#{@source}) is neither a file nor a URL."
65
134
  end
66
135
  end
67
136
  end
data/libreconv.gemspec CHANGED
@@ -1,24 +1,24 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
5
  require 'libreconv/version'
5
6
 
6
7
  Gem::Specification.new do |spec|
7
- spec.name = "libreconv"
8
+ spec.name = 'libreconv'
8
9
  spec.version = Libreconv::VERSION
9
- spec.authors = ["Richard Nyström"]
10
- spec.email = ["ricny046@gmail.com"]
11
- spec.description = %q{ Convert office documents to PDF using LibreOffice. }
12
- spec.summary = %q{ Convert office documents to PDF. }
13
- spec.homepage = "https://github.com/ricn/libreconv"
14
- spec.license = "MIT"
10
+ spec.authors = ['Richard Nyström', 'Nathan Broadbent']
11
+ spec.email = ['nathan@formapi.io']
12
+ spec.description = 'Convert office documents to PDF using LibreOffice.'
13
+ spec.summary = 'Convert office documents to PDF.'
14
+ spec.homepage = 'https://github.com/FormAPI/libreconv'
15
+ spec.license = 'MIT'
15
16
 
16
- spec.files = `git ls-files`.split($/)
17
+ spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
17
18
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
19
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
- spec.require_paths = ["lib"]
20
- spec.add_dependency "spoon"
21
- spec.add_development_dependency "bundler", "~> 1.6.0.rc2"
22
- spec.add_development_dependency "rake"
23
- spec.add_development_dependency "rspec", "~> 3.0.0.rc1"
20
+ spec.require_paths = ['lib']
21
+ spec.add_development_dependency 'bundler', '>= 0'
22
+ spec.add_development_dependency 'rake'
23
+ spec.add_development_dependency 'rspec', '~> 3.8.0'
24
24
  end
@@ -1,100 +1,111 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
+
2
3
  require 'spec_helper'
3
4
 
4
5
  describe Libreconv do
6
+ let(:docx_file) { fixture_path('docx.docx') }
7
+ let(:doc_file) { fixture_path('doc.doc') }
8
+ let(:pptx_file) { fixture_path('pptx.pptx') }
9
+ let(:ppt_file) { fixture_path('ppt.ppt') }
10
+ let(:target_path) { '/tmp/libreconv' }
11
+ let(:url) { 'http://s3.amazonaws.com/libreconv-test/docx.docx' }
5
12
 
6
- before(:all) do
7
- @docx_file = file_path("docx.docx")
8
- @doc_file = file_path("doc.doc")
9
- @pptx_file = file_path("pptx.pptx")
10
- @ppt_file = file_path("ppt.ppt")
11
- @target_path = "/tmp/libreconv"
12
- @url = "http://s3.amazonaws.com/libreconv-test/docx.docx"
13
- end
14
-
15
- before(:each) do
16
- FileUtils.mkdir_p @target_path
13
+ before do
14
+ FileUtils.mkdir_p target_path
17
15
  end
18
16
 
19
- after(:each) do
20
- FileUtils.rm_rf @target_path
17
+ after do
18
+ FileUtils.rm_rf target_path
21
19
  end
22
20
 
23
21
  describe Libreconv::Converter do
24
- describe "#new" do
25
- it "should raise error if soffice command does not exists" do
26
- expect { Libreconv::Converter.new(@doc_file, "/target", "/Whatever/soffice") }.to raise_error(IOError)
22
+ describe '#new' do
23
+ it 'raises error if soffice command does not exists' do
24
+ expect do
25
+ Libreconv::Converter.new(
26
+ doc_file, '/target', '/Whatever/soffice'
27
+ )
28
+ end.to raise_error(IOError)
27
29
  end
28
30
 
29
- it "should raise error if source does not exists" do
30
- expect { Libreconv::Converter.new(file_path("nonsense.txt"), "/target") }.to raise_error(IOError)
31
+ it 'raises error if source does not exists' do
32
+ expect do
33
+ Libreconv::Converter.new(
34
+ fixture_path('nonsense.txt'), '/target'
35
+ )
36
+ end.to raise_error(IOError)
31
37
  end
32
38
  end
33
39
 
34
- describe "#convert" do
35
- it "should convert a docx do pdf specifying target_file" do
36
- target_file = "#{@target_path}/#{File.basename(@doc_file, ".doc")}.pdf"
37
- converter = Libreconv::Converter.new(@doc_file, target_file)
40
+ describe '#convert' do
41
+ it 'converts a docx do pdf specifying target_file' do
42
+ target_file = "#{target_path}/#{File.basename(doc_file, '.doc')}.pdf"
43
+ converter = Libreconv::Converter.new(doc_file, target_file)
38
44
  converter.convert
39
45
  expect(File.file?(target_file)).to eq true
40
46
  end
41
47
 
42
- it "should convert a doc to pdf" do
43
- target_file = "#{@target_path}/#{File.basename(@doc_file, ".doc")}.pdf"
44
- converter = Libreconv::Converter.new(@doc_file, @target_path)
48
+ it 'converts a doc to pdf' do
49
+ target_file = "#{target_path}/#{File.basename(doc_file, '.doc')}.pdf"
50
+ converter = Libreconv::Converter.new(doc_file, target_path)
45
51
  converter.convert
46
52
  expect(File.file?(target_file)).to eq true
47
53
  end
48
54
 
49
- it "should convert a docx to pdf" do
50
- target_file = "#{@target_path}/#{File.basename(@docx_file, ".docx")}.pdf"
51
- converter = Libreconv::Converter.new(@docx_file, @target_path)
55
+ it 'converts a docx to pdf' do
56
+ target_file = "#{target_path}/#{File.basename(docx_file, '.docx')}.pdf"
57
+ converter = Libreconv::Converter.new(docx_file, target_path)
52
58
  converter.convert
53
59
  expect(File.file?(target_file)).to eq true
54
60
  end
55
61
 
56
- it "should convert a pptx to pdf" do
57
- target_file = "#{@target_path}/#{File.basename(@pptx_file, ".pptx")}.pdf"
58
- converter = Libreconv::Converter.new(@pptx_file, @target_path)
62
+ it 'converts a pptx to pdf' do
63
+ target_file = "#{target_path}/#{File.basename(pptx_file, '.pptx')}.pdf"
64
+ converter = Libreconv::Converter.new(pptx_file, target_path)
59
65
  converter.convert
60
66
  expect(File.file?(target_file)).to eq true
61
67
  end
62
68
 
63
- it "should convert a ppt to pdf" do
64
- target_file = "#{@target_path}/#{File.basename(@ppt_file, ".ppt")}.pdf"
65
- converter = Libreconv::Converter.new(@ppt_file, @target_path)
69
+ it 'converts a ppt to pdf' do
70
+ target_file = "#{target_path}/#{File.basename(ppt_file, '.ppt')}.pdf"
71
+ converter = Libreconv::Converter.new(ppt_file, target_path)
66
72
  converter.convert
67
73
  expect(File.file?(target_file)).to eq true
68
74
  end
69
75
 
70
- it "should convert a docx to pdf specifying an URL as source" do
71
- target_file = "#{@target_path}/docx.pdf"
72
- converter = Libreconv::Converter.new(@url, @target_path)
73
- converter.convert
74
- expect(File.file?(target_file)).to eq true
75
- end
76
+ # it 'raises ConversionFailedError when URL cannot be loaded' do
77
+ # stub_request(:get, url)
78
+ # expect do
79
+ # converter = Libreconv::Converter.new(url, target_path)
80
+ # converter.convert
81
+ # end.to raise_error(
82
+ # Libreconv::ConversionFailedError,
83
+ # /Conversion failed/
84
+ # )
85
+ # end
76
86
  end
77
87
 
78
- describe "#soffice_command" do
79
- it "should return the user specified command path" do
80
- cmd = file_path("soffice") # just faking that the command is present here
81
- converter = Libreconv::Converter.new(@doc_file, "/target", cmd)
88
+ describe '#soffice_command' do
89
+ it 'returns the user specified command path' do
90
+ # Just faking that the command is present here
91
+ cmd = fixture_path('soffice')
92
+ converter = Libreconv::Converter.new(doc_file, '/target', cmd)
82
93
  expect(converter.soffice_command).to eq cmd
83
94
  end
84
95
 
85
- it "should return the command found in path" do
96
+ it 'returns the command found in path' do
86
97
  cmd = `which soffice`.strip
87
- converter = Libreconv::Converter.new(@doc_file, "/target")
98
+ converter = Libreconv::Converter.new(doc_file, '/target')
88
99
  expect(converter.soffice_command).to eq cmd
89
100
  end
90
101
  end
102
+ end
91
103
 
92
- describe ".convert" do
93
- it "should convert a file to pdf" do
94
- target_file = "#{@target_path}/#{File.basename(@doc_file, ".doc")}.pdf"
95
- Libreconv.convert(@doc_file, @target_path)
96
- expect(File.file?(target_file)).to eq true
97
- end
104
+ describe '#convert' do
105
+ it 'converts a file to pdf' do
106
+ target_file = "#{target_path}/#{File.basename(doc_file, '.doc')}.pdf"
107
+ described_class.convert(doc_file, target_path)
108
+ expect(File.file?(target_file)).to eq true
98
109
  end
99
110
  end
100
111
  end
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'libreconv'
4
+ require 'pry-byebug'
5
+ require 'webmock/rspec'
2
6
 
3
- def file_path( *paths )
7
+ def fixture_path(*paths)
4
8
  File.expand_path(File.join(File.dirname(__FILE__), 'fixtures', *paths))
5
9
  end
6
10
 
metadata CHANGED
@@ -1,43 +1,30 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: libreconv
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.9.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Nyström
8
+ - Nathan Broadbent
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2014-05-31 00:00:00.000000000 Z
12
+ date: 2019-06-07 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
- name: spoon
15
+ name: bundler
15
16
  requirement: !ruby/object:Gem::Requirement
16
17
  requirements:
17
18
  - - ">="
18
19
  - !ruby/object:Gem::Version
19
20
  version: '0'
20
- type: :runtime
21
+ type: :development
21
22
  prerelease: false
22
23
  version_requirements: !ruby/object:Gem::Requirement
23
24
  requirements:
24
25
  - - ">="
25
26
  - !ruby/object:Gem::Version
26
27
  version: '0'
27
- - !ruby/object:Gem::Dependency
28
- name: bundler
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: 1.6.0.rc2
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: 1.6.0.rc2
41
28
  - !ruby/object:Gem::Dependency
42
29
  name: rake
43
30
  requirement: !ruby/object:Gem::Requirement
@@ -58,25 +45,28 @@ dependencies:
58
45
  requirements:
59
46
  - - "~>"
60
47
  - !ruby/object:Gem::Version
61
- version: 3.0.0.rc1
48
+ version: 3.8.0
62
49
  type: :development
63
50
  prerelease: false
64
51
  version_requirements: !ruby/object:Gem::Requirement
65
52
  requirements:
66
53
  - - "~>"
67
54
  - !ruby/object:Gem::Version
68
- version: 3.0.0.rc1
69
- description: " Convert office documents to PDF using LibreOffice. "
55
+ version: 3.8.0
56
+ description: Convert office documents to PDF using LibreOffice.
70
57
  email:
71
- - ricny046@gmail.com
58
+ - nathan@formapi.io
72
59
  executables: []
73
60
  extensions: []
74
61
  extra_rdoc_files: []
75
62
  files:
76
63
  - ".gitignore"
77
64
  - ".rspec"
65
+ - ".rubocop.yml"
66
+ - ".ruby-version"
78
67
  - ".travis.yml"
79
68
  - Gemfile
69
+ - Gemfile.lock
80
70
  - LICENSE.txt
81
71
  - README.md
82
72
  - Rakefile
@@ -90,7 +80,7 @@ files:
90
80
  - spec/fixtures/soffice
91
81
  - spec/libreconv_spec.rb
92
82
  - spec/spec_helper.rb
93
- homepage: https://github.com/ricn/libreconv
83
+ homepage: https://github.com/FormAPI/libreconv
94
84
  licenses:
95
85
  - MIT
96
86
  metadata: {}
@@ -110,7 +100,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
110
100
  version: '0'
111
101
  requirements: []
112
102
  rubyforge_project:
113
- rubygems_version: 2.2.2
103
+ rubygems_version: 2.7.8
114
104
  signing_key:
115
105
  specification_version: 4
116
106
  summary: Convert office documents to PDF.