libreconv 0.9.1 → 0.9.5

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: 522fce89fe66792d062925292ab1104b4c4d4c7e
4
- data.tar.gz: 7c2f41f839955d1900417339bdf4be23833debaf
2
+ SHA256:
3
+ metadata.gz: 5ae94a53817b7bd0f69b71501286d2ecef0f6e4fa698d6a73175fdd0b9c9c1db
4
+ data.tar.gz: 0af95f4eaafc34508dafa929de52f678fc4d227fe3de1ad6b53195c385ca9b47
5
5
  SHA512:
6
- metadata.gz: 8d9b40454b77418914765b032a54e6c41f1e995a28ac411d61f13f558ea14ce740ee7414a5b2e700bb3d7d8fb7467e30e461698e4add05e45d712fdd11178a3e
7
- data.tar.gz: 4913f63b22d7da58a2eec6a3f5f909e10a4f074e1cfe51d32a872b43a8ec7c604d44702ba4101af0c3a7c505706845b4a6ec3598f702c9e23328eb65e2e7a30a
6
+ metadata.gz: 53a3ac9d20908d5aecba062984c31461ccafc2defe9fb55432a77b540a24d6274e001b7107885b45eb77890ac7c2da5d0cfa0a2f075b820a36f2d3862e41f009
7
+ data.tar.gz: f3880d9db0000edbd39479b128b40a9f4357274ef05f75093bdd90bdda6220202d9e2313595c28059027f4b60e186aa277d32a3c6149031211dadd7d78ace707
data/.editorconfig ADDED
@@ -0,0 +1,15 @@
1
+ # Editor configuration, see https://editorconfig.org
2
+ root = true
3
+
4
+ [*]
5
+ charset = utf-8
6
+ indent_style = space
7
+ indent_size = 2
8
+ end_of_line = lf
9
+ insert_final_newline = true
10
+ max_line_length = 100
11
+ trim_trailing_whitespace = true
12
+
13
+ [*.md]
14
+ max_line_length = off
15
+ trim_trailing_whitespace = false
data/.gitignore CHANGED
@@ -1,24 +1,20 @@
1
- *.gem
2
- *.rbc
3
- .bundle
4
- .config
5
- .yardoc
6
- Gemfile.lock
7
- InstalledFiles
8
- _yardoc
9
- coverage
10
- doc/
11
- lib/bundler/man
12
- pkg
13
- rdoc
14
- spec/reports
15
- test/tmp
16
- test/version_tmp
17
- tmp
18
- .idea/
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
19
9
 
20
- TODO.md
10
+ # rspec failure tracking
11
+ .rspec_status
21
12
 
22
- spec/.DS_Store
13
+ /Gemfile.lock
14
+ /.ruby-version
15
+ *.gem
16
+ /vendor/bundle
23
17
 
18
+ # Misc.
24
19
  .DS_Store
20
+ /.idea/
data/.rspec CHANGED
@@ -1,2 +1,4 @@
1
1
  --color
2
- --format progress
2
+ --format documentation
3
+ --require spec_helper
4
+ --order rand
data/.rubocop.yml ADDED
@@ -0,0 +1,23 @@
1
+ require: rubocop-rspec
2
+
3
+ AllCops:
4
+ TargetRubyVersion: 2.3
5
+
6
+ Style/Documentation:
7
+ Enabled: false
8
+
9
+ Metrics/LineLength:
10
+ Max: 100
11
+
12
+ Style/PercentLiteralDelimiters:
13
+ PreferredDelimiters:
14
+ '%w': '[]'
15
+
16
+ Style/ExpandPathArguments:
17
+ Enabled: false
18
+
19
+ Style/Encoding:
20
+ Enabled: false
21
+
22
+ Layout/EndOfLine:
23
+ Enabled: false
data/.travis.yml CHANGED
@@ -1,10 +1,14 @@
1
+ sudo: false
1
2
  language: ruby
3
+ cache: bundler
2
4
  rvm:
3
- - 2.1.1
4
- - 2.2.2
5
- notifications:
6
- recipients:
7
- - ricn@rny.io
5
+ - 1.9.3
6
+ - 2.2
7
+ - 2.3
8
+ - 2.5
9
+ - jruby
8
10
  before_install:
9
11
  - sudo apt-get update -qq
10
- - sudo apt-get install libreoffice
12
+ - sudo apt-get install libreoffice-core libreoffice-writer libreoffice-calc libreoffice-impress -y --no-install-recommends
13
+ before_script: bundle exec rubocop
14
+ script: bundle exec rake
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in libreconv.gemspec
data/README.md CHANGED
@@ -2,15 +2,16 @@
2
2
 
3
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)
7
6
  [![Gem Version](https://badge.fury.io/rb/libreconv.svg)](http://badge.fury.io/rb/libreconv)
8
7
 
9
8
  ## Installation
10
9
 
11
10
  Add this line to your application's Gemfile:
12
11
 
13
- gem 'libreconv'
12
+ ```ruby
13
+ gem 'libreconv'
14
+ ```
14
15
 
15
16
  And then execute:
16
17
 
@@ -22,7 +23,7 @@ Or install it yourself as:
22
23
 
23
24
  ## Usage
24
25
 
25
- You need to install Libreoffice or Openoffice on your system to use this gem. The code has been tested with Libreoffice 4.2.
26
+ You need to install LibreOffice or OpenOffice on your system to use this gem. The code has been tested with LibreOffice 6.1.3.
26
27
 
27
28
  ```ruby
28
29
  require 'libreconv'
@@ -38,8 +39,11 @@ Libreconv.convert('document.docx', '/Users/ricn/pdf_documents')
38
39
  # You can also convert a source file directly from an URL
39
40
  Libreconv.convert('http://myserver.com/123/document.docx', '/Users/ricn/pdf_documents/doc.pdf')
40
41
 
42
+ # You cal pass a URL with GET params like this S3 example
43
+ 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')
44
+
41
45
  # Converts document.docx to document.pdf
42
- # If you for some reason can't have soffice in your PATH you can specifiy the file path to the soffice binary
46
+ # If you for some reason can't have soffice in your PATH you can specify the file path to the soffice binary
43
47
  Libreconv.convert('document.docx', '/Users/ricn/pdf_documents', '/Applications/LibreOffice.app/Contents/MacOS/soffice')
44
48
 
45
49
  # Converts document.docx to my_document_as.html
@@ -47,19 +51,33 @@ Libreconv.convert('document.docx', '/Users/ricn/pdf_documents/my_document_as.htm
47
51
 
48
52
  # Converts document.docx to my_document_as.pdf using writer_pdf_Export filter
49
53
  Libreconv.convert('document.docx', '/Users/ricn/pdf_documents/my_document_as.pdf', nil, 'pdf:writer_pdf_Export')
50
-
51
54
  ```
52
55
 
56
+ ## Development
57
+
58
+ After checking out the repo, run `bundle install` to install dependencies. Then, run `bundle exec rake` to run the tests.
59
+ You can also run `irb -r bundler/setup -r libreconv` for an interactive prompt that will allow you to experiment.
60
+
61
+ To install this gem onto your local machine, run `bundle exec rake install`.
62
+
53
63
  ## Credits
54
64
 
55
65
  The following people have contributed ideas, documentation, or code to Libreconv:
56
66
 
57
67
  * Richard Nyström
68
+ * Nathan Broadbent
58
69
 
59
70
  ## Contributing
60
71
 
72
+ * Install LibreOffice on Linux: `sudo apt-get install libreoffice`
73
+ * Install LibreOffice on Mac: `brew cask install libreoffice`
74
+
61
75
  1. Fork it
62
76
  2. Create your feature branch (`git checkout -b my-new-feature`)
63
77
  3. Commit your changes (`git commit -am 'Add some feature'`)
64
78
  4. Push to the branch (`git push origin my-new-feature`)
65
79
  5. Create new Pull Request
80
+
81
+ ## License
82
+
83
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
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
data/lib/libreconv.rb CHANGED
@@ -1,68 +1,181 @@
1
- require "libreconv/version"
2
- require "uri"
3
- require "net/http"
4
- require "tmpdir"
5
- require "spoon"
1
+ # frozen_string_literal: true
6
2
 
3
+ require 'libreconv/version'
4
+ require 'uri'
5
+ require 'net/http'
6
+ require 'tmpdir'
7
+ require 'securerandom'
8
+ require 'open3'
9
+
10
+ # Convert office documents using LibreOffice / OpenOffice to one of their supported formats.
7
11
  module Libreconv
12
+ class ConversionFailedError < StandardError; end
8
13
 
14
+ # @param [String] source Path or URL of the source file.
15
+ # @param [String] target Target file path.
16
+ # @param [String] soffice_command Path to the soffice binary.
17
+ # @param [String] convert_to Format to convert to (default: 'pdf').
18
+ # @raise [IOError] If invalid source file/URL or soffice command not found.
19
+ # @raise [URI::Error] When URI parsing error.
20
+ # @raise [Net::ProtocolError] If source URL checking failed.
21
+ # @raise [ConversionFailedError] When soffice command execution error.
9
22
  def self.convert(source, target, soffice_command = nil, convert_to = nil)
10
23
  Converter.new(source, target, soffice_command, convert_to).convert
11
24
  end
12
25
 
13
26
  class Converter
27
+ # @return [String]
14
28
  attr_accessor :soffice_command
15
29
 
30
+ # @param [String] source Path or URL of the source file.
31
+ # @param [String] target Target file path.
32
+ # @param [String] soffice_command Path to the soffice binary.
33
+ # @param [String] convert_to Format to convert to (default: 'pdf').
34
+ # @raise [IOError] If invalid source file/URL or soffice command not found.
35
+ # @raise [URI::Error] When URI parsing error.
36
+ # @raise [Net::ProtocolError] If source URL checking failed.
16
37
  def initialize(source, target, soffice_command = nil, convert_to = nil)
17
- @source = source
38
+ @source = check_source_type(source)
18
39
  @target = target
19
- @target_path = Dir.tmpdir
20
- @soffice_command = soffice_command
21
- @convert_to = convert_to || "pdf"
22
- determine_soffice_command
23
- check_source_type
24
-
25
- unless @soffice_command && File.exists?(@soffice_command)
26
- raise IOError, "Can't find Libreoffice or Openoffice executable."
27
- end
40
+ @soffice_command = soffice_command || which('soffice') || which('soffice.bin')
41
+ @convert_to = convert_to || 'pdf'
42
+
43
+ ensure_soffice_exists
28
44
  end
29
45
 
46
+ # @raise [ConversionFailedError] When soffice command execution error.
30
47
  def convert
31
- orig_stdout = $stdout.clone
32
- $stdout.reopen File.new('/dev/null', 'w')
33
- pid = Spoon.spawnp(@soffice_command, "--headless", "--convert-to", @convert_to, @source, "--outdir", @target_path)
34
- Process.waitpid(pid)
35
- $stdout.reopen orig_stdout
36
- target_tmp_file = "#{@target_path}/#{File.basename(@source, ".*")}.#{File.basename(@convert_to, ":*")}"
37
- FileUtils.cp target_tmp_file, @target
48
+ tmp_pipe_path = File.join(Dir.tmpdir, "soffice-pipe-#{SecureRandom.uuid}")
49
+
50
+ Dir.mktmpdir do |target_path|
51
+ command = build_command(tmp_pipe_path, target_path)
52
+ target_tmp_file = execute_command(command, target_path)
53
+
54
+ FileUtils.cp target_tmp_file, @target
55
+ end
56
+ ensure
57
+ FileUtils.rm_rf tmp_pipe_path if File.exist?(tmp_pipe_path)
38
58
  end
39
59
 
40
60
  private
41
61
 
42
- def determine_soffice_command
43
- unless @soffice_command
44
- @soffice_command ||= which("soffice")
45
- @soffice_command ||= which("soffice.bin")
46
- end
62
+ # @param [Array<String>] command
63
+ # @param [String] target_path
64
+ # @return [String]
65
+ # @raise [ConversionFailedError] When soffice command execution error.
66
+ def execute_command(command, target_path)
67
+ output, error, status =
68
+ if RUBY_PLATFORM =~ /java/
69
+ Open3.capture3(*command)
70
+ else
71
+ Open3.capture3(command_env, *command, unsetenv_others: true)
72
+ end
73
+
74
+ target_tmp_file = File.join(target_path, target_filename)
75
+ return target_tmp_file if status.success? && File.exist?(target_tmp_file)
76
+
77
+ raise ConversionFailedError,
78
+ "Conversion failed! Output: #{output.strip.inspect}, Error: #{error.strip.inspect}"
79
+ end
80
+
81
+ # @return [Hash]
82
+ def command_env
83
+ Hash[%w[HOME PATH LANG LD_LIBRARY_PATH SYSTEMROOT TEMP].map { |k| [k, ENV[k]] }]
84
+ end
85
+
86
+ # @param [String] tmp_pipe_path
87
+ # @param [String] target_path
88
+ # @return [Array<String>]
89
+ def build_command(tmp_pipe_path, target_path)
90
+ [
91
+ soffice_command,
92
+ "--accept=\"pipe,name=#{File.basename(tmp_pipe_path)};url;StarOffice.ServiceManager\"",
93
+ "-env:UserInstallation=#{build_file_uri(tmp_pipe_path)}",
94
+ '--headless',
95
+ '--convert-to', @convert_to,
96
+ escaped_source,
97
+ '--outdir', target_path
98
+ ]
99
+ end
100
+
101
+ # If the URL contains GET params, the '&' could break when being used as an argument to soffice.
102
+ # Wrap it in single quotes to escape it. Then strip them from the target temp file name.
103
+ # @return [String]
104
+ def escaped_source
105
+ # TODO: @source.is_a?(URI::Generic) ? "'#{@source}'" : @source
106
+ @source.to_s
107
+ end
108
+
109
+ # @return [String]
110
+ def escaped_source_path
111
+ @source.is_a?(URI::Generic) ? @source.path : @source
112
+ end
113
+
114
+ # @return [String]
115
+ def target_filename
116
+ File.basename(escaped_source_path, '.*') + '.' + File.basename(@convert_to, ':*')
47
117
  end
48
118
 
119
+ # @raise [IOError] If soffice headless command line tool not found.
120
+ def ensure_soffice_exists
121
+ return if soffice_command && File.exist?(soffice_command)
122
+
123
+ raise IOError, 'Can\'t find LibreOffice or OpenOffice executable.'
124
+ end
125
+
126
+ # @param [String] cmd
127
+ # @return [String, nil]
49
128
  def which(cmd)
50
129
  exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
130
+
51
131
  ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
52
132
  exts.each do |ext|
53
- exe = File.join(path, "#{cmd}#{ext}")
133
+ exe = File.expand_path("#{cmd}#{ext}", path)
54
134
  return exe if File.executable? exe
55
135
  end
56
136
  end
57
137
 
58
- return nil
138
+ nil
59
139
  end
60
140
 
61
- def check_source_type
62
- return if File.exists?(@source) && !File.directory?(@source) #file
63
- return if URI(@source).scheme == "http" && Net::HTTP.get_response(URI(@source)).is_a?(Net::HTTPSuccess) #http
64
- return if URI(@source).scheme == "https" && Net::HTTP.get_response(URI(@source)).is_a?(Net::HTTPSuccess) #https
65
- raise IOError, "Source (#{@source}) is neither a file nor an URL."
141
+ # @param [String] source
142
+ # @return [String, URI::HTTP]
143
+ # @raise [IOError] If invalid source file/URL.
144
+ # @raise [URI::Error] When URI parsing error.
145
+ # @raise [Net::ProtocolError] If source URL checking failed.
146
+ def check_source_type(source)
147
+ if File.exist?(source)
148
+ return source unless File.directory?(source)
149
+ elsif (uri = check_valid_url(source))
150
+ return uri
151
+ end
152
+
153
+ raise IOError, "Source (#{source}) is neither a file nor a URL."
154
+ end
155
+
156
+ # @param [String] url
157
+ # @return [URI::HTTP, false, nil]
158
+ # @raise [URI::Error] When URI parsing error.
159
+ # @raise [Net::ProtocolError] If source URL checking failed.
160
+ def check_valid_url(url)
161
+ uri = URI(url)
162
+ return false unless uri.is_a?(URI::HTTP)
163
+
164
+ Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') do |http|
165
+ response = http.head(uri.request_uri)
166
+ return check_valid_url(response['location']) if response.is_a?(Net::HTTPRedirection)
167
+
168
+ return response.is_a?(Net::HTTPSuccess) ? uri : nil
169
+ end
170
+ end
171
+
172
+ # @param [String] path
173
+ # @return [String]
174
+ def build_file_uri(path)
175
+ separators = /[#{Regexp.quote "#{File::SEPARATOR}#{File::ALT_SEPARATOR}"}]/
176
+ unsafe = Regexp.new("[^#{URI::PATTERN::UNRESERVED}/?:]")
177
+
178
+ 'file:///' + URI::DEFAULT_PARSER.escape(path.gsub(separators, '/').sub(%r{^/+}, ''), unsafe)
66
179
  end
67
180
  end
68
- end
181
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Libreconv
2
- VERSION = "0.9.1"
4
+ VERSION = '0.9.5'
3
5
  end
data/libreconv.gemspec CHANGED
@@ -1,24 +1,31 @@
1
- # coding: utf-8
1
+ # encoding: UTF-8
2
+ # frozen_string_literal: true
3
+
2
4
  lib = File.expand_path('../lib', __FILE__)
3
5
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
6
  require 'libreconv/version'
5
7
 
6
8
  Gem::Specification.new do |spec|
7
- spec.name = "libreconv"
9
+ spec.name = 'libreconv'
8
10
  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"
11
+ spec.authors = ['Richard Nyström', 'Nathan Broadbent']
12
+ spec.email = ['nathan@formapi.io']
13
+
14
+ spec.description = 'Convert office documents to PDF using LibreOffice.'
15
+ spec.summary = 'Convert office documents to PDF.'
16
+ spec.homepage = 'https://github.com/FormAPI/libreconv'
17
+ spec.license = 'MIT'
15
18
 
16
- spec.files = `git ls-files`.split($/)
19
+ spec.files = Dir.chdir(File.expand_path('../', __FILE__)) do
20
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ end
17
22
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
- 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", ">= 0"
22
- spec.add_development_dependency "rake"
23
- spec.add_development_dependency "rspec", "~> 3.2.0"
23
+ spec.require_paths = ['lib']
24
+
25
+ spec.add_development_dependency 'bundler', '>= 0'
26
+ spec.add_development_dependency 'rake'
27
+ spec.add_development_dependency 'rspec', '~> 3.8'
28
+ spec.add_development_dependency 'rubocop'
29
+ spec.add_development_dependency 'rubocop-rspec'
30
+ spec.add_development_dependency 'webmock'
24
31
  end
metadata CHANGED
@@ -1,81 +1,112 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: libreconv
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1
4
+ version: 0.9.5
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: 2015-07-01 00:00:00.000000000 Z
12
+ date: 2019-10-28 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
28
  - !ruby/object:Gem::Dependency
28
- name: bundler
29
+ name: rake
29
30
  requirement: !ruby/object:Gem::Requirement
30
31
  requirements:
31
- - - '>='
32
+ - - ">="
32
33
  - !ruby/object:Gem::Version
33
34
  version: '0'
34
35
  type: :development
35
36
  prerelease: false
36
37
  version_requirements: !ruby/object:Gem::Requirement
37
38
  requirements:
38
- - - '>='
39
+ - - ">="
39
40
  - !ruby/object:Gem::Version
40
41
  version: '0'
41
42
  - !ruby/object:Gem::Dependency
42
- name: rake
43
+ name: rspec
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '3.8'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '3.8'
56
+ - !ruby/object:Gem::Dependency
57
+ name: rubocop
43
58
  requirement: !ruby/object:Gem::Requirement
44
59
  requirements:
45
- - - '>='
60
+ - - ">="
46
61
  - !ruby/object:Gem::Version
47
62
  version: '0'
48
63
  type: :development
49
64
  prerelease: false
50
65
  version_requirements: !ruby/object:Gem::Requirement
51
66
  requirements:
52
- - - '>='
67
+ - - ">="
53
68
  - !ruby/object:Gem::Version
54
69
  version: '0'
55
70
  - !ruby/object:Gem::Dependency
56
- name: rspec
71
+ name: rubocop-rspec
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: webmock
57
86
  requirement: !ruby/object:Gem::Requirement
58
87
  requirements:
59
- - - ~>
88
+ - - ">="
60
89
  - !ruby/object:Gem::Version
61
- version: 3.2.0
90
+ version: '0'
62
91
  type: :development
63
92
  prerelease: false
64
93
  version_requirements: !ruby/object:Gem::Requirement
65
94
  requirements:
66
- - - ~>
95
+ - - ">="
67
96
  - !ruby/object:Gem::Version
68
- version: 3.2.0
69
- description: ' Convert office documents to PDF using LibreOffice. '
97
+ version: '0'
98
+ description: Convert office documents to PDF using LibreOffice.
70
99
  email:
71
- - ricny046@gmail.com
100
+ - nathan@formapi.io
72
101
  executables: []
73
102
  extensions: []
74
103
  extra_rdoc_files: []
75
104
  files:
76
- - .gitignore
77
- - .rspec
78
- - .travis.yml
105
+ - ".editorconfig"
106
+ - ".gitignore"
107
+ - ".rspec"
108
+ - ".rubocop.yml"
109
+ - ".travis.yml"
79
110
  - Gemfile
80
111
  - LICENSE.txt
81
112
  - README.md
@@ -83,14 +114,7 @@ files:
83
114
  - lib/libreconv.rb
84
115
  - lib/libreconv/version.rb
85
116
  - libreconv.gemspec
86
- - spec/fixtures/doc.doc
87
- - spec/fixtures/docx.docx
88
- - spec/fixtures/ppt.ppt
89
- - spec/fixtures/pptx.pptx
90
- - spec/fixtures/soffice
91
- - spec/libreconv_spec.rb
92
- - spec/spec_helper.rb
93
- homepage: https://github.com/ricn/libreconv
117
+ homepage: https://github.com/FormAPI/libreconv
94
118
  licenses:
95
119
  - MIT
96
120
  metadata: {}
@@ -100,25 +124,18 @@ require_paths:
100
124
  - lib
101
125
  required_ruby_version: !ruby/object:Gem::Requirement
102
126
  requirements:
103
- - - '>='
127
+ - - ">="
104
128
  - !ruby/object:Gem::Version
105
129
  version: '0'
106
130
  required_rubygems_version: !ruby/object:Gem::Requirement
107
131
  requirements:
108
- - - '>='
132
+ - - ">="
109
133
  - !ruby/object:Gem::Version
110
134
  version: '0'
111
135
  requirements: []
112
136
  rubyforge_project:
113
- rubygems_version: 2.0.14
137
+ rubygems_version: 2.7.8
114
138
  signing_key:
115
139
  specification_version: 4
116
140
  summary: Convert office documents to PDF.
117
- test_files:
118
- - spec/fixtures/doc.doc
119
- - spec/fixtures/docx.docx
120
- - spec/fixtures/ppt.ppt
121
- - spec/fixtures/pptx.pptx
122
- - spec/fixtures/soffice
123
- - spec/libreconv_spec.rb
124
- - spec/spec_helper.rb
141
+ test_files: []
Binary file
Binary file
Binary file
Binary file
File without changes
@@ -1,100 +0,0 @@
1
- # encoding: utf-8
2
- require 'spec_helper'
3
-
4
- describe Libreconv do
5
-
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
17
- end
18
-
19
- after(:each) do
20
- FileUtils.rm_rf @target_path
21
- end
22
-
23
- 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)
27
- end
28
-
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
- end
32
- end
33
-
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)
38
- converter.convert
39
- expect(File.file?(target_file)).to eq true
40
- end
41
-
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)
45
- converter.convert
46
- expect(File.file?(target_file)).to eq true
47
- end
48
-
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)
52
- converter.convert
53
- expect(File.file?(target_file)).to eq true
54
- end
55
-
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)
59
- converter.convert
60
- expect(File.file?(target_file)).to eq true
61
- end
62
-
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)
66
- converter.convert
67
- expect(File.file?(target_file)).to eq true
68
- end
69
-
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
- end
77
-
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)
82
- expect(converter.soffice_command).to eq cmd
83
- end
84
-
85
- it "should return the command found in path" do
86
- cmd = `which soffice`.strip
87
- converter = Libreconv::Converter.new(@doc_file, "/target")
88
- expect(converter.soffice_command).to eq cmd
89
- end
90
- end
91
-
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
98
- end
99
- end
100
- end
data/spec/spec_helper.rb DELETED
@@ -1,12 +0,0 @@
1
- require 'libreconv'
2
-
3
- def file_path( *paths )
4
- File.expand_path(File.join(File.dirname(__FILE__), 'fixtures', *paths))
5
- end
6
-
7
- RSpec.configure do |config|
8
- config.run_all_when_everything_filtered = true
9
- config.filter_run :focus
10
-
11
- config.order = 'random'
12
- end