libreconv 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d201da6f6e044de9222041ca137e8ecdd1962991
4
+ data.tar.gz: ddd509dad045567bafd05bc563465def3424a511
5
+ SHA512:
6
+ metadata.gz: 1ab245ba4df5b5b464780e8851d49145ecb925ee82a9ee1aa7f1a2c6bc35339f07852126f1a77095c4b0233fbb94d36f422fba4ea5d13871949c905984e26b8e
7
+ data.tar.gz: 20705eee2c9e340114d2d5d20351f2540ddf7846ec008af8adc5801f90df41564c4c27b5f23c1bb7ea514c58d24c2d8f9cfa8064840b85031a6400b4ef852780
data/.gitignore ADDED
@@ -0,0 +1,23 @@
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
+
19
+ TODO.md
20
+
21
+ spec/.DS_Store
22
+
23
+ .DS_Store
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in libreconv.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Richard Nyström
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,50 @@
1
+ # Libreconv
2
+
3
+ Convert office documents to PDF using LibreOffice / OpenOffice for the heavy lifting.
4
+
5
+ [![Code Climate](https://codeclimate.com/github/ricn/libreconv.png)](https://codeclimate.com/github/ricn/libreconv)
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'libreconv'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install libreconv
20
+
21
+ ## Usage
22
+
23
+ You need to install Libreoffice or Openoffice on your system to use this gem. The code has been tested with Libreoffice 4.0.
24
+
25
+ ```ruby
26
+ require 'libreconv'
27
+
28
+ # Converts document.docx to document.pdf
29
+ # This requires that the soffice binary is present in your PATH.
30
+ Libreconv.convert('document.docx', '/Users/ricn/pdf_documents')
31
+
32
+ # Converts document.docx to document.pdf
33
+ # If you for some reason can't have soffice in your PATH you can specifiy the file path to the soffice binary
34
+ Libreconv.convert('document.docx', '/Users/ricn/pdf_documents', '/Applications/LibreOffice.app/Contents/MacOS/soffice')
35
+
36
+ ```
37
+
38
+ ## Credits
39
+
40
+ The following people have contributed ideas, documentation, or code to Libreconv:
41
+
42
+ * Richard Nyström
43
+
44
+ ## Contributing
45
+
46
+ 1. Fork it
47
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
48
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
49
+ 4. Push to the branch (`git push origin my-new-feature`)
50
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,3 @@
1
+ module Libreconv
2
+ VERSION = "0.5.0"
3
+ end
data/lib/libreconv.rb ADDED
@@ -0,0 +1,53 @@
1
+ require "libreconv/version"
2
+
3
+ module Libreconv
4
+
5
+ def self.convert(source, target, soffice_command = nil)
6
+ Converter.new(source, target, soffice_command).convert
7
+ end
8
+
9
+ class Converter
10
+ attr_accessor :soffice_command
11
+
12
+ def initialize(source, target_path, soffice_command = nil)
13
+ @source = source
14
+ @target_path = target_path
15
+ @soffice_command = soffice_command
16
+ determine_soffice_command
17
+
18
+ unless @soffice_command && File.exists?(@soffice_command)
19
+ raise IOError, "Can't find Libreoffice or Openoffice executable."
20
+ end
21
+
22
+ unless File.exists?(source)
23
+ raise IOError, "Source file (#{source}) does not exist."
24
+ end
25
+ end
26
+
27
+ def convert
28
+ cmd = "#{@soffice_command} --headless --convert-to pdf #{@source} -outdir #{@target_path}"
29
+ system("#{cmd} > /dev/null")
30
+ end
31
+
32
+ private
33
+
34
+ def determine_soffice_command
35
+ unless @soffice_command
36
+ @soffice_command ||= which("soffice")
37
+ @soffice_command ||= which("soffice.bin")
38
+ end
39
+ end
40
+
41
+ def which(cmd)
42
+ exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
43
+ ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
44
+ exts.each do |ext|
45
+ exe = File.join(path, "#{cmd}#{ext}")
46
+ return exe if File.executable? exe
47
+ end
48
+ end
49
+
50
+ return nil
51
+ end
52
+ end
53
+ end
data/libreconv.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'libreconv/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "libreconv"
8
+ 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 / OpenOffice for the heavy lifting. }
12
+ spec.summary = %q{ Convert office documents to PDF. }
13
+ spec.homepage = "https://github.com/ricn/libreconv"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ 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
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ end
Binary file
Binary file
Binary file
Binary file
Binary file
File without changes
@@ -0,0 +1,91 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Libreconv do
6
+
7
+ before(:all) do
8
+ @docx_file = file_path("docx.docx")
9
+ @doc_file = file_path("doc.doc")
10
+ @pptx_file = file_path("pptx.pptx")
11
+ @ppt_file = file_path("ppt.ppt")
12
+ @bin_file = file_path("bin.bin")
13
+ @target_path = "/tmp/libreconv"
14
+ end
15
+
16
+ after(:all) do
17
+ FileUtils.rm_rf @target_path
18
+ end
19
+
20
+ describe Libreconv::Converter do
21
+ describe "#new" do
22
+ it "should raise error if soffice command does not exists" do
23
+ lambda { Libreconv::Converter.new(@doc_file, "/target", "/Whatever/soffice") }.should raise_error(IOError)
24
+ end
25
+
26
+ it "should raise error if source file does not exists" do
27
+ lambda { Libreconv::Converter.new(file_path("nonsense.txt"), "/target") }.should raise_error(IOError)
28
+ end
29
+ end
30
+
31
+ describe "#convert" do
32
+ it "should convert a doc to pdf" do
33
+ target_file = "#{@target_path}/#{File.basename(@doc_file, ".doc")}.pdf"
34
+ converter = Libreconv::Converter.new(@doc_file, @target_path)
35
+ converter.convert
36
+ File.exists?(target_file).should == true
37
+ end
38
+
39
+ it "should convert a docx to pdf" do
40
+ target_file = "#{@target_path}/#{File.basename(@docx_file, ".docx")}.pdf"
41
+ converter = Libreconv::Converter.new(@docx_file, @target_path)
42
+ converter.convert
43
+ File.exists?(target_file).should == true
44
+ end
45
+
46
+ it "should convert a pptx to pdf" do
47
+ target_file = "#{@target_path}/#{File.basename(@pptx_file, ".pptx")}.pdf"
48
+ converter = Libreconv::Converter.new(@pptx_file, @target_path)
49
+ converter.convert
50
+ File.exists?(target_file).should == true
51
+ end
52
+
53
+ it "should convert a ppt to pdf" do
54
+ target_file = "#{@target_path}/#{File.basename(@ppt_file, ".ppt")}.pdf"
55
+ converter = Libreconv::Converter.new(@ppt_file, @target_path)
56
+ converter.convert
57
+ File.exists?(target_file).should == true
58
+ end
59
+
60
+ it "try converting binary file" do
61
+ source = @bin_file
62
+ target_file = "#{@target_path}/#{File.basename(source, ".bin")}.pdf"
63
+ converter = Libreconv::Converter.new(source, @target_path)
64
+ converter.convert
65
+ File.exists?(target_file).should == false
66
+ end
67
+ end
68
+
69
+ describe "#soffice_command" do
70
+ it "should return the user specified command path" do
71
+ cmd = file_path("soffice") # just faking that the command is present here
72
+ converter = Libreconv::Converter.new(@doc_file, "/target", cmd)
73
+ converter.soffice_command.should == cmd
74
+ end
75
+
76
+ it "should return the command found in path" do
77
+ cmd = `which soffice`.strip
78
+ converter = Libreconv::Converter.new(@doc_file, "/target")
79
+ converter.soffice_command.should == cmd
80
+ end
81
+ end
82
+
83
+ describe ".convert" do
84
+ it "should convert a file to pdf" do
85
+ target_file = "#{@target_path}/#{File.basename(@doc_file, ".doc")}.pdf"
86
+ Libreconv.convert(@doc_file, @target_path)
87
+ File.exists?(target_file).should == true
88
+ end
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,13 @@
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.treat_symbols_as_metadata_keys_with_true_values = true
9
+ config.run_all_when_everything_filtered = true
10
+ config.filter_run :focus
11
+
12
+ config.order = 'random'
13
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: libreconv
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.0
5
+ platform: ruby
6
+ authors:
7
+ - Richard Nyström
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-03-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: ' Convert office documents to PDF using LibreOffice / OpenOffice for
42
+ the heavy lifting. '
43
+ email:
44
+ - ricny046@gmail.com
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - .gitignore
50
+ - .rspec
51
+ - Gemfile
52
+ - LICENSE.txt
53
+ - README.md
54
+ - Rakefile
55
+ - lib/libreconv.rb
56
+ - lib/libreconv/version.rb
57
+ - libreconv.gemspec
58
+ - spec/fixtures/bin.bin
59
+ - spec/fixtures/doc.doc
60
+ - spec/fixtures/docx.docx
61
+ - spec/fixtures/ppt.ppt
62
+ - spec/fixtures/pptx.pptx
63
+ - spec/fixtures/soffice
64
+ - spec/libreconv_spec.rb
65
+ - spec/spec_helper.rb
66
+ homepage: https://github.com/ricn/libreconv
67
+ licenses:
68
+ - MIT
69
+ metadata: {}
70
+ post_install_message:
71
+ rdoc_options: []
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - '>='
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ requirements: []
85
+ rubyforge_project:
86
+ rubygems_version: 2.0.0
87
+ signing_key:
88
+ specification_version: 4
89
+ summary: Convert office documents to PDF.
90
+ test_files:
91
+ - spec/fixtures/bin.bin
92
+ - spec/fixtures/doc.doc
93
+ - spec/fixtures/docx.docx
94
+ - spec/fixtures/ppt.ppt
95
+ - spec/fixtures/pptx.pptx
96
+ - spec/fixtures/soffice
97
+ - spec/libreconv_spec.rb
98
+ - spec/spec_helper.rb