libreconv 0.9.4 → 0.9.5
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/.editorconfig +15 -0
- data/.gitignore +16 -19
- data/.rspec +3 -1
- data/.rubocop.yml +11 -13
- data/.travis.yml +10 -3
- data/Gemfile +0 -7
- data/README.md +16 -4
- data/lib/libreconv.rb +122 -85
- data/lib/libreconv/version.rb +1 -1
- data/libreconv.gemspec +11 -4
- metadata +48 -20
- data/.ruby-version +0 -1
- data/spec/fixtures/doc.doc +0 -0
- data/spec/fixtures/docx.docx +0 -0
- data/spec/fixtures/ppt.ppt +0 -0
- data/spec/fixtures/pptx.pptx +0 -0
- data/spec/fixtures/soffice +0 -0
- data/spec/libreconv_spec.rb +0 -111
- data/spec/spec_helper.rb +0 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5ae94a53817b7bd0f69b71501286d2ecef0f6e4fa698d6a73175fdd0b9c9c1db
|
4
|
+
data.tar.gz: 0af95f4eaafc34508dafa929de52f678fc4d227fe3de1ad6b53195c385ca9b47
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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,23 +1,20 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
doc/
|
10
|
-
lib/bundler/man
|
11
|
-
pkg
|
12
|
-
rdoc
|
13
|
-
spec/reports
|
14
|
-
test/tmp
|
15
|
-
test/version_tmp
|
16
|
-
tmp
|
17
|
-
.idea/
|
1
|
+
/.bundle/
|
2
|
+
/.yardoc
|
3
|
+
/_yardoc/
|
4
|
+
/coverage/
|
5
|
+
/doc/
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/tmp/
|
18
9
|
|
19
|
-
|
10
|
+
# rspec failure tracking
|
11
|
+
.rspec_status
|
20
12
|
|
21
|
-
|
13
|
+
/Gemfile.lock
|
14
|
+
/.ruby-version
|
15
|
+
*.gem
|
16
|
+
/vendor/bundle
|
22
17
|
|
18
|
+
# Misc.
|
23
19
|
.DS_Store
|
20
|
+
/.idea/
|
data/.rspec
CHANGED
data/.rubocop.yml
CHANGED
@@ -1,25 +1,23 @@
|
|
1
1
|
require: rubocop-rspec
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
Enabled: false
|
3
|
+
AllCops:
|
4
|
+
TargetRubyVersion: 2.3
|
6
5
|
|
7
|
-
|
8
|
-
# Max: 20
|
6
|
+
Style/Documentation:
|
9
7
|
Enabled: false
|
10
8
|
|
11
|
-
Metrics/
|
12
|
-
|
13
|
-
Enabled: false
|
9
|
+
Metrics/LineLength:
|
10
|
+
Max: 100
|
14
11
|
|
15
|
-
|
16
|
-
|
12
|
+
Style/PercentLiteralDelimiters:
|
13
|
+
PreferredDelimiters:
|
14
|
+
'%w': '[]'
|
17
15
|
|
18
|
-
|
16
|
+
Style/ExpandPathArguments:
|
19
17
|
Enabled: false
|
20
18
|
|
21
|
-
|
19
|
+
Style/Encoding:
|
22
20
|
Enabled: false
|
23
21
|
|
24
|
-
|
22
|
+
Layout/EndOfLine:
|
25
23
|
Enabled: false
|
data/.travis.yml
CHANGED
@@ -1,7 +1,14 @@
|
|
1
|
+
sudo: false
|
1
2
|
language: ruby
|
3
|
+
cache: bundler
|
2
4
|
rvm:
|
3
|
-
-
|
4
|
-
- 2.
|
5
|
+
- 1.9.3
|
6
|
+
- 2.2
|
7
|
+
- 2.3
|
8
|
+
- 2.5
|
9
|
+
- jruby
|
5
10
|
before_install:
|
6
11
|
- sudo apt-get update -qq
|
7
|
-
- 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
data/README.md
CHANGED
@@ -9,7 +9,9 @@ Convert office documents using LibreOffice / OpenOffice to one of their supporte
|
|
9
9
|
|
10
10
|
Add this line to your application's Gemfile:
|
11
11
|
|
12
|
-
|
12
|
+
```ruby
|
13
|
+
gem 'libreconv'
|
14
|
+
```
|
13
15
|
|
14
16
|
And then execute:
|
15
17
|
|
@@ -21,7 +23,7 @@ Or install it yourself as:
|
|
21
23
|
|
22
24
|
## Usage
|
23
25
|
|
24
|
-
You need to install
|
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.
|
25
27
|
|
26
28
|
```ruby
|
27
29
|
require 'libreconv'
|
@@ -41,7 +43,7 @@ Libreconv.convert('http://myserver.com/123/document.docx', '/Users/ricn/pdf_docu
|
|
41
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')
|
42
44
|
|
43
45
|
# Converts document.docx to document.pdf
|
44
|
-
# If you for some reason can't have soffice in your PATH you can
|
46
|
+
# If you for some reason can't have soffice in your PATH you can specify the file path to the soffice binary
|
45
47
|
Libreconv.convert('document.docx', '/Users/ricn/pdf_documents', '/Applications/LibreOffice.app/Contents/MacOS/soffice')
|
46
48
|
|
47
49
|
# Converts document.docx to my_document_as.html
|
@@ -49,9 +51,15 @@ Libreconv.convert('document.docx', '/Users/ricn/pdf_documents/my_document_as.htm
|
|
49
51
|
|
50
52
|
# Converts document.docx to my_document_as.pdf using writer_pdf_Export filter
|
51
53
|
Libreconv.convert('document.docx', '/Users/ricn/pdf_documents/my_document_as.pdf', nil, 'pdf:writer_pdf_Export')
|
52
|
-
|
53
54
|
```
|
54
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
|
+
|
55
63
|
## Credits
|
56
64
|
|
57
65
|
The following people have contributed ideas, documentation, or code to Libreconv:
|
@@ -69,3 +77,7 @@ The following people have contributed ideas, documentation, or code to Libreconv
|
|
69
77
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
70
78
|
4. Push to the branch (`git push origin my-new-feature`)
|
71
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/lib/libreconv.rb
CHANGED
@@ -7,117 +7,130 @@ require 'tmpdir'
|
|
7
7
|
require 'securerandom'
|
8
8
|
require 'open3'
|
9
9
|
|
10
|
+
# Convert office documents using LibreOffice / OpenOffice to one of their supported formats.
|
10
11
|
module Libreconv
|
11
12
|
class ConversionFailedError < StandardError; end
|
12
13
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
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.
|
18
22
|
def self.convert(source, target, soffice_command = nil, convert_to = nil)
|
19
23
|
Converter.new(source, target, soffice_command, convert_to).convert
|
20
24
|
end
|
21
25
|
|
22
26
|
class Converter
|
27
|
+
# @return [String]
|
23
28
|
attr_accessor :soffice_command
|
24
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.
|
25
37
|
def initialize(source, target, soffice_command = nil, convert_to = nil)
|
26
|
-
@source = source
|
38
|
+
@source = check_source_type(source)
|
27
39
|
@target = target
|
28
|
-
@soffice_command =
|
29
|
-
soffice_command ||
|
30
|
-
which('soffice') ||
|
31
|
-
which('soffice.bin')
|
40
|
+
@soffice_command = soffice_command || which('soffice') || which('soffice.bin')
|
32
41
|
@convert_to = convert_to || 'pdf'
|
33
|
-
@source_type = check_source_type
|
34
|
-
|
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
42
|
|
52
43
|
ensure_soffice_exists
|
53
44
|
end
|
54
45
|
|
46
|
+
# @raise [ConversionFailedError] When soffice command execution error.
|
55
47
|
def convert
|
56
|
-
|
57
|
-
pipe_path = File.join Dir.tmpdir, pipe_name
|
48
|
+
tmp_pipe_path = File.join(Dir.tmpdir, "soffice-pipe-#{SecureRandom.uuid}")
|
58
49
|
|
59
50
|
Dir.mktmpdir do |target_path|
|
60
|
-
|
61
|
-
|
62
|
-
'url',
|
63
|
-
'StarOffice.ServiceManager'
|
64
|
-
].join(';')
|
65
|
-
|
66
|
-
command = [
|
67
|
-
soffice_command,
|
68
|
-
"--accept=\"#{accept_args}\"",
|
69
|
-
'-env:UserInstallation=file:///' +
|
70
|
-
pipe_path.gsub('\\', '/').gsub(%r{^/}, ''),
|
71
|
-
'--headless',
|
72
|
-
'--convert-to',
|
73
|
-
@convert_to,
|
74
|
-
@escaped_source,
|
75
|
-
'--outdir',
|
76
|
-
target_path
|
77
|
-
]
|
78
|
-
|
79
|
-
output, error, status = Open3.capture3(
|
80
|
-
{
|
81
|
-
'HOME' => ENV['HOME'],
|
82
|
-
'PATH' => ENV['PATH'],
|
83
|
-
'LANG' => ENV['LANG'],
|
84
|
-
'LD_LIBRARY_PATH' => ENV['LD_LIBRARY_PATH'],
|
85
|
-
'SYSTEMROOT' => ENV['SYSTEMROOT'],
|
86
|
-
'TEMP' => ENV['TEMP']
|
87
|
-
},
|
88
|
-
*command,
|
89
|
-
unsetenv_others: true
|
90
|
-
)
|
91
|
-
|
92
|
-
FileUtils.rm_rf pipe_path if File.exist?(pipe_path)
|
93
|
-
unless status.success?
|
94
|
-
raise ConversionFailedError,
|
95
|
-
'Conversion failed! Output: ' + output.strip.inspect +
|
96
|
-
', Error: ' + error.strip.inspect
|
97
|
-
end
|
51
|
+
command = build_command(tmp_pipe_path, target_path)
|
52
|
+
target_tmp_file = execute_command(command, target_path)
|
98
53
|
|
99
|
-
target_tmp_file = File.join(
|
100
|
-
target_path,
|
101
|
-
File.basename(@escaped_source_path, '.*') + '.' +
|
102
|
-
File.basename(@convert_to, ':*')
|
103
|
-
)
|
104
54
|
FileUtils.cp target_tmp_file, @target
|
105
55
|
end
|
56
|
+
ensure
|
57
|
+
FileUtils.rm_rf tmp_pipe_path if File.exist?(tmp_pipe_path)
|
106
58
|
end
|
107
59
|
|
108
60
|
private
|
109
61
|
|
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, ':*')
|
117
|
+
end
|
118
|
+
|
119
|
+
# @raise [IOError] If soffice headless command line tool not found.
|
110
120
|
def ensure_soffice_exists
|
111
121
|
return if soffice_command && File.exist?(soffice_command)
|
112
122
|
|
113
123
|
raise IOError, 'Can\'t find LibreOffice or OpenOffice executable.'
|
114
124
|
end
|
115
125
|
|
126
|
+
# @param [String] cmd
|
127
|
+
# @return [String, nil]
|
116
128
|
def which(cmd)
|
117
129
|
exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
|
130
|
+
|
118
131
|
ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
|
119
132
|
exts.each do |ext|
|
120
|
-
exe = File.
|
133
|
+
exe = File.expand_path("#{cmd}#{ext}", path)
|
121
134
|
return exe if File.executable? exe
|
122
135
|
end
|
123
136
|
end
|
@@ -125,20 +138,44 @@ module Libreconv
|
|
125
138
|
nil
|
126
139
|
end
|
127
140
|
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
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
|
135
151
|
end
|
136
|
-
|
137
|
-
|
138
|
-
|
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
|
139
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}/?:]")
|
140
177
|
|
141
|
-
|
178
|
+
'file:///' + URI::DEFAULT_PARSER.escape(path.gsub(separators, '/').sub(%r{^/+}, ''), unsafe)
|
142
179
|
end
|
143
180
|
end
|
144
181
|
end
|
data/lib/libreconv/version.rb
CHANGED
data/libreconv.gemspec
CHANGED
@@ -1,6 +1,7 @@
|
|
1
|
+
# encoding: UTF-8
|
1
2
|
# frozen_string_literal: true
|
2
3
|
|
3
|
-
lib = File.expand_path('lib',
|
4
|
+
lib = File.expand_path('../lib', __FILE__)
|
4
5
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
6
|
require 'libreconv/version'
|
6
7
|
|
@@ -9,16 +10,22 @@ Gem::Specification.new do |spec|
|
|
9
10
|
spec.version = Libreconv::VERSION
|
10
11
|
spec.authors = ['Richard Nyström', 'Nathan Broadbent']
|
11
12
|
spec.email = ['nathan@formapi.io']
|
13
|
+
|
12
14
|
spec.description = 'Convert office documents to PDF using LibreOffice.'
|
13
15
|
spec.summary = 'Convert office documents to PDF.'
|
14
16
|
spec.homepage = 'https://github.com/FormAPI/libreconv'
|
15
17
|
spec.license = 'MIT'
|
16
18
|
|
17
|
-
spec.files =
|
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
|
18
22
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
|
-
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
23
|
spec.require_paths = ['lib']
|
24
|
+
|
21
25
|
spec.add_development_dependency 'bundler', '>= 0'
|
22
26
|
spec.add_development_dependency 'rake'
|
23
|
-
spec.add_development_dependency 'rspec', '~> 3.8
|
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,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: libreconv
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Richard Nyström
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2019-10-
|
12
|
+
date: 2019-10-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -45,14 +45,56 @@ dependencies:
|
|
45
45
|
requirements:
|
46
46
|
- - "~>"
|
47
47
|
- !ruby/object:Gem::Version
|
48
|
-
version: 3.8
|
48
|
+
version: '3.8'
|
49
49
|
type: :development
|
50
50
|
prerelease: false
|
51
51
|
version_requirements: !ruby/object:Gem::Requirement
|
52
52
|
requirements:
|
53
53
|
- - "~>"
|
54
54
|
- !ruby/object:Gem::Version
|
55
|
-
version: 3.8
|
55
|
+
version: '3.8'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: rubocop
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
- !ruby/object:Gem::Dependency
|
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
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
type: :development
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
56
98
|
description: Convert office documents to PDF using LibreOffice.
|
57
99
|
email:
|
58
100
|
- nathan@formapi.io
|
@@ -60,10 +102,10 @@ executables: []
|
|
60
102
|
extensions: []
|
61
103
|
extra_rdoc_files: []
|
62
104
|
files:
|
105
|
+
- ".editorconfig"
|
63
106
|
- ".gitignore"
|
64
107
|
- ".rspec"
|
65
108
|
- ".rubocop.yml"
|
66
|
-
- ".ruby-version"
|
67
109
|
- ".travis.yml"
|
68
110
|
- Gemfile
|
69
111
|
- LICENSE.txt
|
@@ -72,13 +114,6 @@ files:
|
|
72
114
|
- lib/libreconv.rb
|
73
115
|
- lib/libreconv/version.rb
|
74
116
|
- libreconv.gemspec
|
75
|
-
- spec/fixtures/doc.doc
|
76
|
-
- spec/fixtures/docx.docx
|
77
|
-
- spec/fixtures/ppt.ppt
|
78
|
-
- spec/fixtures/pptx.pptx
|
79
|
-
- spec/fixtures/soffice
|
80
|
-
- spec/libreconv_spec.rb
|
81
|
-
- spec/spec_helper.rb
|
82
117
|
homepage: https://github.com/FormAPI/libreconv
|
83
118
|
licenses:
|
84
119
|
- MIT
|
@@ -103,11 +138,4 @@ rubygems_version: 2.7.8
|
|
103
138
|
signing_key:
|
104
139
|
specification_version: 4
|
105
140
|
summary: Convert office documents to PDF.
|
106
|
-
test_files:
|
107
|
-
- spec/fixtures/doc.doc
|
108
|
-
- spec/fixtures/docx.docx
|
109
|
-
- spec/fixtures/ppt.ppt
|
110
|
-
- spec/fixtures/pptx.pptx
|
111
|
-
- spec/fixtures/soffice
|
112
|
-
- spec/libreconv_spec.rb
|
113
|
-
- spec/spec_helper.rb
|
141
|
+
test_files: []
|
data/.ruby-version
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
2.5.3
|
data/spec/fixtures/doc.doc
DELETED
Binary file
|
data/spec/fixtures/docx.docx
DELETED
Binary file
|
data/spec/fixtures/ppt.ppt
DELETED
Binary file
|
data/spec/fixtures/pptx.pptx
DELETED
Binary file
|
data/spec/fixtures/soffice
DELETED
File without changes
|
data/spec/libreconv_spec.rb
DELETED
@@ -1,111 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
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' }
|
12
|
-
|
13
|
-
before do
|
14
|
-
FileUtils.mkdir_p target_path
|
15
|
-
end
|
16
|
-
|
17
|
-
after do
|
18
|
-
FileUtils.rm_rf target_path
|
19
|
-
end
|
20
|
-
|
21
|
-
describe Libreconv::Converter do
|
22
|
-
describe '#new' do
|
23
|
-
it 'raises error if soffice command does not exists' do
|
24
|
-
expect do
|
25
|
-
described_class.new(
|
26
|
-
doc_file, '/target', '/Whatever/soffice'
|
27
|
-
)
|
28
|
-
end.to raise_error(IOError)
|
29
|
-
end
|
30
|
-
|
31
|
-
it 'raises error if source does not exists' do
|
32
|
-
expect do
|
33
|
-
described_class.new(
|
34
|
-
fixture_path('nonsense.txt'), '/target'
|
35
|
-
)
|
36
|
-
end.to raise_error(IOError)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
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 = described_class.new(doc_file, target_file)
|
44
|
-
converter.convert
|
45
|
-
expect(File.file?(target_file)).to eq true
|
46
|
-
end
|
47
|
-
|
48
|
-
it 'converts a doc to pdf' do
|
49
|
-
target_file = "#{target_path}/#{File.basename(doc_file, '.doc')}.pdf"
|
50
|
-
converter = described_class.new(doc_file, target_path)
|
51
|
-
converter.convert
|
52
|
-
expect(File.file?(target_file)).to eq true
|
53
|
-
end
|
54
|
-
|
55
|
-
it 'converts a docx to pdf' do
|
56
|
-
target_file = "#{target_path}/#{File.basename(docx_file, '.docx')}.pdf"
|
57
|
-
converter = described_class.new(docx_file, target_path)
|
58
|
-
converter.convert
|
59
|
-
expect(File.file?(target_file)).to eq true
|
60
|
-
end
|
61
|
-
|
62
|
-
it 'converts a pptx to pdf' do
|
63
|
-
target_file = "#{target_path}/#{File.basename(pptx_file, '.pptx')}.pdf"
|
64
|
-
converter = described_class.new(pptx_file, target_path)
|
65
|
-
converter.convert
|
66
|
-
expect(File.file?(target_file)).to eq true
|
67
|
-
end
|
68
|
-
|
69
|
-
it 'converts a ppt to pdf' do
|
70
|
-
target_file = "#{target_path}/#{File.basename(ppt_file, '.ppt')}.pdf"
|
71
|
-
converter = described_class.new(ppt_file, target_path)
|
72
|
-
converter.convert
|
73
|
-
expect(File.file?(target_file)).to eq true
|
74
|
-
end
|
75
|
-
|
76
|
-
# it 'raises ConversionFailedError when URL cannot be loaded' do
|
77
|
-
# stub_request(:get, url)
|
78
|
-
# expect do
|
79
|
-
# converter = described_class.new(url, target_path)
|
80
|
-
# converter.convert
|
81
|
-
# end.to raise_error(
|
82
|
-
# Libreconv::ConversionFailedError,
|
83
|
-
# /Conversion failed/
|
84
|
-
# )
|
85
|
-
# end
|
86
|
-
end
|
87
|
-
|
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 = described_class.new(doc_file, '/target', cmd)
|
93
|
-
expect(converter.soffice_command).to eq cmd
|
94
|
-
end
|
95
|
-
|
96
|
-
it 'returns the command found in path' do
|
97
|
-
cmd = `which soffice`.strip
|
98
|
-
converter = described_class.new(doc_file, '/target')
|
99
|
-
expect(converter.soffice_command).to eq cmd
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
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
|
109
|
-
end
|
110
|
-
end
|
111
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'libreconv'
|
4
|
-
require 'pry-byebug'
|
5
|
-
require 'webmock/rspec'
|
6
|
-
|
7
|
-
def fixture_path(*paths)
|
8
|
-
File.expand_path(File.join(File.dirname(__FILE__), 'fixtures', *paths))
|
9
|
-
end
|
10
|
-
|
11
|
-
RSpec.configure do |config|
|
12
|
-
config.run_all_when_everything_filtered = true
|
13
|
-
config.filter_run :focus
|
14
|
-
|
15
|
-
config.order = 'random'
|
16
|
-
end
|