libreconv 0.9.3 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 771ed18ef3438a2fbe8aa0a213c57c97a7631e1d8ab25e63fbd791d0884ea81b
4
- data.tar.gz: 568a8dacb50e126a828843dd142a3ad0209bd0daee230d5ec355566a7e9a1ed9
3
+ metadata.gz: 5ae94a53817b7bd0f69b71501286d2ecef0f6e4fa698d6a73175fdd0b9c9c1db
4
+ data.tar.gz: 0af95f4eaafc34508dafa929de52f678fc4d227fe3de1ad6b53195c385ca9b47
5
5
  SHA512:
6
- metadata.gz: fb1894b92d6c3f96b4e8955724969e7da080ef82db3d68495e87030f9210ba363b617c29e76efac5dc79428a91fafe108b31b746cab175268bd338c375fa8359
7
- data.tar.gz: 7d7b25767c5467cd52a7446bd7f1c2d76219c985233167294337386c83e1f6a039e01bca6926517d9480907530b5feeddcf028b5f654871c01641f61ff8cd6f8
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
- *.gem
2
- *.rbc
3
- .bundle
4
- .config
5
- .yardoc
6
- InstalledFiles
7
- _yardoc
8
- coverage
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
- TODO.md
10
+ # rspec failure tracking
11
+ .rspec_status
20
12
 
21
- spec/.DS_Store
13
+ /Gemfile.lock
14
+ /.ruby-version
15
+ *.gem
16
+ /vendor/bundle
22
17
 
18
+ # Misc.
23
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 CHANGED
@@ -1,25 +1,23 @@
1
1
  require: rubocop-rspec
2
2
 
3
- Metrics/AbcSize:
4
- # Max: 25
5
- Enabled: false
3
+ AllCops:
4
+ TargetRubyVersion: 2.3
6
5
 
7
- Metrics/MethodLength:
8
- # Max: 20
6
+ Style/Documentation:
9
7
  Enabled: false
10
8
 
11
- Metrics/CyclomaticComplexity:
12
- # Max: 10
13
- Enabled: false
9
+ Metrics/LineLength:
10
+ Max: 100
14
11
 
15
- Metrics/BlockLength:
16
- Enabled: false
12
+ Style/PercentLiteralDelimiters:
13
+ PreferredDelimiters:
14
+ '%w': '[]'
17
15
 
18
- Metrics/PerceivedComplexity:
16
+ Style/ExpandPathArguments:
19
17
  Enabled: false
20
18
 
21
- RSpec/ExampleLength:
19
+ Style/Encoding:
22
20
  Enabled: false
23
21
 
24
- Style/Documentation:
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
- - 2.2.0
4
- - 2.5.3
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
@@ -4,10 +4,3 @@ source 'https://rubygems.org'
4
4
 
5
5
  # Specify your gem's dependencies in libreconv.gemspec
6
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/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
- gem 'libreconv'
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 Libreoffice or Openoffice on your system to use this gem. The code has been tested with Libreoffice 6.1.3.
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 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
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).
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Libreconv
4
- VERSION = '0.9.3'
4
+ VERSION = '0.9.5'
5
5
  end
data/lib/libreconv.rb CHANGED
@@ -7,110 +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
- SOURCE_TYPES = {
14
- file: 1,
15
- url: 2
16
- }.freeze
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
- pipe_uuid = SecureRandom.uuid
48
+ tmp_pipe_path = File.join(Dir.tmpdir, "soffice-pipe-#{SecureRandom.uuid}")
57
49
 
58
50
  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
- 'LD_LIBRARY_PATH' => ENV['LD_LIBRARY_PATH']
83
- },
84
- *command,
85
- unsetenv_others: true
86
- )
87
- if !status.success?
88
- raise ConversionFailedError,
89
- "Conversion failed! Output: #{output.strip.inspect}, " \
90
- "Error: #{error.strip.inspect}"
91
- end
51
+ command = build_command(tmp_pipe_path, target_path)
52
+ target_tmp_file = execute_command(command, target_path)
92
53
 
93
- target_tmp_file = "#{target_path}/" \
94
- "#{File.basename(@escaped_source_path, '.*')}." \
95
- "#{File.basename(@convert_to, ':*')}"
96
54
  FileUtils.cp target_tmp_file, @target
97
- FileUtils.rm_rf("/tmp/soffice-dir-#{pipe_uuid}")
98
55
  end
56
+ ensure
57
+ FileUtils.rm_rf tmp_pipe_path if File.exist?(tmp_pipe_path)
99
58
  end
100
59
 
101
60
  private
102
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.
103
120
  def ensure_soffice_exists
104
121
  return if soffice_command && File.exist?(soffice_command)
105
122
 
106
- raise IOError, "Can't find Libreoffice or Openoffice executable."
123
+ raise IOError, 'Can\'t find LibreOffice or OpenOffice executable.'
107
124
  end
108
125
 
126
+ # @param [String] cmd
127
+ # @return [String, nil]
109
128
  def which(cmd)
110
129
  exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
130
+
111
131
  ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
112
132
  exts.each do |ext|
113
- exe = File.join(path, "#{cmd}#{ext}")
133
+ exe = File.expand_path("#{cmd}#{ext}", path)
114
134
  return exe if File.executable? exe
115
135
  end
116
136
  end
@@ -118,20 +138,44 @@ module Libreconv
118
138
  nil
119
139
  end
120
140
 
121
- def check_source_type
122
- if File.exist?(@source) && !File.directory?(@source)
123
- return SOURCE_TYPES[:file]
124
- end
125
- if URI(@source).scheme == 'http' &&
126
- Net::HTTP.get_response(URI(@source)).is_a?(Net::HTTPSuccess)
127
- return SOURCE_TYPES[: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
128
151
  end
129
- if URI(@source).scheme == 'https' &&
130
- Net::HTTP.get_response(URI(@source)).is_a?(Net::HTTPSuccess)
131
- return SOURCE_TYPES[:url]
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
132
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}/?:]")
133
177
 
134
- raise IOError, "Source (#{@source}) is neither a file nor a URL."
178
+ 'file:///' + URI::DEFAULT_PARSER.escape(path.gsub(separators, '/').sub(%r{^/+}, ''), unsafe)
135
179
  end
136
180
  end
137
181
  end
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', __dir__)
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 = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
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.0'
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.3
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-06-07 00:00:00.000000000 Z
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.0
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.0
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,26 +102,18 @@ 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
- - Gemfile.lock
70
111
  - LICENSE.txt
71
112
  - README.md
72
113
  - Rakefile
73
114
  - lib/libreconv.rb
74
115
  - lib/libreconv/version.rb
75
116
  - libreconv.gemspec
76
- - spec/fixtures/doc.doc
77
- - spec/fixtures/docx.docx
78
- - spec/fixtures/ppt.ppt
79
- - spec/fixtures/pptx.pptx
80
- - spec/fixtures/soffice
81
- - spec/libreconv_spec.rb
82
- - spec/spec_helper.rb
83
117
  homepage: https://github.com/FormAPI/libreconv
84
118
  licenses:
85
119
  - MIT
@@ -104,11 +138,4 @@ rubygems_version: 2.7.8
104
138
  signing_key:
105
139
  specification_version: 4
106
140
  summary: Convert office documents to PDF.
107
- test_files:
108
- - spec/fixtures/doc.doc
109
- - spec/fixtures/docx.docx
110
- - spec/fixtures/ppt.ppt
111
- - spec/fixtures/pptx.pptx
112
- - spec/fixtures/soffice
113
- - spec/libreconv_spec.rb
114
- - spec/spec_helper.rb
141
+ test_files: []
data/.ruby-version DELETED
@@ -1 +0,0 @@
1
- 2.5.3
data/Gemfile.lock DELETED
@@ -1,78 +0,0 @@
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
Binary file
Binary file
Binary file
Binary file
File without changes
@@ -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
- Libreconv::Converter.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
- Libreconv::Converter.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 = Libreconv::Converter.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 = Libreconv::Converter.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 = Libreconv::Converter.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 = Libreconv::Converter.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 = Libreconv::Converter.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 = Libreconv::Converter.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 = Libreconv::Converter.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 = Libreconv::Converter.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