odf-converter 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/odf/config.rb +34 -0
- data/lib/odf/converter/hash.rb +3 -1
- data/lib/odf/converter/version.rb +1 -1
- data/lib/odf/converter.rb +9 -5
- data/lib/odf-converter.rb +1 -0
- data/odf-converter.gemspec +2 -2
- data/spec/odf/converter_spec.rb +4 -1
- metadata +11 -21
data/lib/odf/config.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'active_support/configurable'
|
2
|
+
|
3
|
+
module ODF
|
4
|
+
# Configures global settings for ODF
|
5
|
+
# ODF.configure do |config|
|
6
|
+
# config.port = 3111
|
7
|
+
# end
|
8
|
+
def self.configure(&block)
|
9
|
+
yield @config ||= ODF::Configuration.new
|
10
|
+
end
|
11
|
+
|
12
|
+
# Global settings for ODF::Converter
|
13
|
+
def self.config
|
14
|
+
@config
|
15
|
+
end
|
16
|
+
|
17
|
+
# need a Class for 3.0
|
18
|
+
class Configuration #:nodoc:
|
19
|
+
include ActiveSupport::Configurable
|
20
|
+
|
21
|
+
config_accessor :office_bin
|
22
|
+
config_accessor :connection_type
|
23
|
+
config_accessor :host
|
24
|
+
config_accessor :port
|
25
|
+
end
|
26
|
+
|
27
|
+
# this is ugly. why can't we pass the default value to config_accessor...?
|
28
|
+
configure do |config|
|
29
|
+
config.office_bin = "soffice"
|
30
|
+
config.connection_type = :socket
|
31
|
+
config.host = :localhost
|
32
|
+
config.port = 2083
|
33
|
+
end
|
34
|
+
end
|
data/lib/odf/converter/hash.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
|
+
Uno::PropertyValue = Rubyuno.uno_require "com.sun.star.beans.PropertyValue"
|
2
|
+
|
1
3
|
class Hash
|
2
4
|
def to_uno_properties
|
3
5
|
self.inject([]) do |memo, (key, value)|
|
4
|
-
property =
|
6
|
+
property = Uno::PropertyValue.new
|
5
7
|
property.Name = key.to_s
|
6
8
|
property.Value = value.to_s
|
7
9
|
memo << property
|
data/lib/odf/converter.rb
CHANGED
@@ -1,21 +1,21 @@
|
|
1
1
|
require "rubyuno"
|
2
|
-
require "odf/
|
2
|
+
require "odf/config"
|
3
3
|
require "odf/converter/families"
|
4
4
|
require "odf/converter/filters/base_filter"
|
5
5
|
require "odf/converter/filters/import"
|
6
6
|
require "odf/converter/filters/export"
|
7
7
|
require "odf/converter/hash"
|
8
|
+
require "odf/converter/version"
|
8
9
|
|
9
10
|
module ODF
|
10
|
-
PropertyValue = Rubyuno.uno_require "com.sun.star.beans.PropertyValue"
|
11
|
-
|
12
11
|
class Converter
|
13
12
|
class DocumentConversionError < Exception; end
|
14
13
|
|
15
14
|
attr_reader :ctx, :smgr, :desktop, :document
|
16
15
|
|
17
16
|
def initialize
|
18
|
-
|
17
|
+
config = ODF.config
|
18
|
+
@ctx = Uno::Connector.bootstrap(config.office_bin.to_s, config.connection_type.to_s, config.host.to_s, config.port)
|
19
19
|
@smgr = @ctx.getServiceManager
|
20
20
|
@desktop = @smgr.createInstanceWithContext("com.sun.star.frame.Desktop", @ctx)
|
21
21
|
end
|
@@ -35,10 +35,14 @@ module ODF
|
|
35
35
|
perform_conversion(infile, outfile) && outfile
|
36
36
|
end
|
37
37
|
|
38
|
+
def inspect
|
39
|
+
"#<#{self.class.name} #{self.class.config.office_bin}@#{self.class.config.host}:#{self.class.config.port}>"
|
40
|
+
end
|
41
|
+
|
38
42
|
def self.convert(*args)
|
39
43
|
new.convert(*args)
|
40
44
|
end
|
41
|
-
|
45
|
+
|
42
46
|
private
|
43
47
|
def detect_family(doc)
|
44
48
|
return Families::WEB if doc.supportsService("com.sun.star.text.WebDocument")
|
data/lib/odf-converter.rb
CHANGED
data/odf-converter.gemspec
CHANGED
@@ -16,7 +16,7 @@ Gem::Specification.new do |gem|
|
|
16
16
|
gem.version = ODF::Converter::VERSION
|
17
17
|
|
18
18
|
gem.add_dependency "rubyuno"
|
19
|
-
gem.
|
20
|
-
|
19
|
+
gem.add_dependency 'activesupport', ['>= 3.0.0']
|
20
|
+
|
21
21
|
gem.add_development_dependency "rspec"
|
22
22
|
end
|
data/spec/odf/converter_spec.rb
CHANGED
@@ -10,7 +10,10 @@ describe ODF::Converter do
|
|
10
10
|
let(:c) { ODF::Converter.new }
|
11
11
|
|
12
12
|
describe do
|
13
|
-
before
|
13
|
+
before do
|
14
|
+
Uno::Connector.stub_chain(:bootstrap, :getServiceManager, :createInstanceWithContext)
|
15
|
+
c.stub(:perform_conversion) { true }
|
16
|
+
end
|
14
17
|
|
15
18
|
it "should raise an error if the to option is not given" do
|
16
19
|
expect { c.convert("infile.txt") }.to raise_error ArgumentError
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: odf-converter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2012-07-08 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rubyuno
|
16
|
-
requirement: &
|
16
|
+
requirement: &22699960 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,32 +21,21 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *22699960
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
|
-
name:
|
27
|
-
requirement: &
|
26
|
+
name: activesupport
|
27
|
+
requirement: &22698340 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version:
|
33
|
-
type: :
|
34
|
-
prerelease: false
|
35
|
-
version_requirements: *20530480
|
36
|
-
- !ruby/object:Gem::Dependency
|
37
|
-
name: pry-editline
|
38
|
-
requirement: &20529660 !ruby/object:Gem::Requirement
|
39
|
-
none: false
|
40
|
-
requirements:
|
41
|
-
- - ! '>='
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
version: '0'
|
44
|
-
type: :development
|
32
|
+
version: 3.0.0
|
33
|
+
type: :runtime
|
45
34
|
prerelease: false
|
46
|
-
version_requirements: *
|
35
|
+
version_requirements: *22698340
|
47
36
|
- !ruby/object:Gem::Dependency
|
48
37
|
name: rspec
|
49
|
-
requirement: &
|
38
|
+
requirement: &22696080 !ruby/object:Gem::Requirement
|
50
39
|
none: false
|
51
40
|
requirements:
|
52
41
|
- - ! '>='
|
@@ -54,7 +43,7 @@ dependencies:
|
|
54
43
|
version: '0'
|
55
44
|
type: :development
|
56
45
|
prerelease: false
|
57
|
-
version_requirements: *
|
46
|
+
version_requirements: *22696080
|
58
47
|
description: Ruby library for converting ODF files through OO.org
|
59
48
|
email:
|
60
49
|
- dvandersluis@selfmgmt.com
|
@@ -68,6 +57,7 @@ files:
|
|
68
57
|
- README.md
|
69
58
|
- Rakefile
|
70
59
|
- lib/odf-converter.rb
|
60
|
+
- lib/odf/config.rb
|
71
61
|
- lib/odf/converter.rb
|
72
62
|
- lib/odf/converter/families.rb
|
73
63
|
- lib/odf/converter/filters/base_filter.rb
|