documentalist 0.1.0 → 0.1.1

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.
Files changed (48) hide show
  1. data/Manifest +48 -12
  2. data/README.rdoc +1 -1
  3. data/Rakefile +28 -12
  4. data/config/default.yml +17 -0
  5. data/documentalist.gemspec +40 -34
  6. data/lib/backends/net_pbm.rb +10 -0
  7. data/lib/backends/odf_merge.rb +64 -0
  8. data/lib/backends/open_office.rb +108 -0
  9. data/lib/backends/open_office/bridges/jodconverter-2.2.2/ChangeLog.txt +119 -0
  10. data/lib/backends/open_office/bridges/jodconverter-2.2.2/LICENSE.txt +504 -0
  11. data/lib/backends/open_office/bridges/jodconverter-2.2.2/README.txt +58 -0
  12. data/lib/backends/open_office/bridges/jodconverter-2.2.2/docs/jodconverter-2.2.2-javadoc.jar +0 -0
  13. data/lib/backends/open_office/bridges/jodconverter-2.2.2/docs/third-party-licenses/license-commons-io.txt +203 -0
  14. data/lib/backends/open_office/bridges/jodconverter-2.2.2/docs/third-party-licenses/license-openoffice.org.txt +8 -0
  15. data/lib/backends/open_office/bridges/jodconverter-2.2.2/docs/third-party-licenses/license-slf4j.txt +24 -0
  16. data/lib/backends/open_office/bridges/jodconverter-2.2.2/docs/third-party-licenses/license-xstream.txt +27 -0
  17. data/lib/backends/open_office/bridges/jodconverter-2.2.2/document-formats.xml +513 -0
  18. data/lib/backends/open_office/bridges/jodconverter-2.2.2/lib/DEPENDENCIES.txt +17 -0
  19. data/lib/backends/open_office/bridges/jodconverter-2.2.2/lib/commons-cli-1.2.jar +0 -0
  20. data/lib/backends/open_office/bridges/jodconverter-2.2.2/lib/commons-io-1.4.jar +0 -0
  21. data/lib/backends/open_office/bridges/jodconverter-2.2.2/lib/jodconverter-2.2.2.jar +0 -0
  22. data/lib/backends/open_office/bridges/jodconverter-2.2.2/lib/jodconverter-cli-2.2.2.jar +0 -0
  23. data/lib/backends/open_office/bridges/jodconverter-2.2.2/lib/juh-3.0.1.jar +0 -0
  24. data/lib/backends/open_office/bridges/jodconverter-2.2.2/lib/jurt-3.0.1.jar +0 -0
  25. data/lib/backends/open_office/bridges/jodconverter-2.2.2/lib/ridl-3.0.1.jar +0 -0
  26. data/lib/backends/open_office/bridges/jodconverter-2.2.2/lib/slf4j-api-1.5.6.jar +0 -0
  27. data/lib/backends/open_office/bridges/jodconverter-2.2.2/lib/slf4j-jdk14-1.5.6.jar +0 -0
  28. data/lib/backends/open_office/bridges/jodconverter-2.2.2/lib/unoil-3.0.1.jar +0 -0
  29. data/lib/backends/open_office/bridges/jodconverter-2.2.2/lib/xstream-1.3.1.jar +0 -0
  30. data/lib/backends/open_office/bridges/jodconverter-2.2.2/src/jodconverter-2.2.2-sources.jar +0 -0
  31. data/lib/backends/open_office/bridges/jodconverter-2.2.2/src/jodconverter-cli-2.2.2-sources.jar +0 -0
  32. data/lib/{DocumentConverter.py → backends/open_office/bridges/pyodconverter.py} +0 -0
  33. data/lib/{open_office → backends/open_office}/server.rb +8 -5
  34. data/lib/backends/pdf_tools.rb +14 -0
  35. data/lib/documentalist.rb +130 -42
  36. data/lib/tasks/tasks.rb +6 -0
  37. data/rails/config/documentalist.yml.tpl +67 -0
  38. data/rails/init.rb +12 -1
  39. data/rails/initialize_configuration.rb +6 -0
  40. data/test/documentalist_test.rb +48 -25
  41. data/test/fixtures/{fixture.odt → fixture_001.odt} +0 -0
  42. data/test/net_pbm_test.rb +7 -0
  43. data/test/odf_merge_test.rb +56 -0
  44. data/test/open_office_test.rb +70 -13
  45. data/test/pdf_tools_test.rb +8 -0
  46. data/test/rails_integration_test.rb +39 -0
  47. data/test/test_helper.rb +29 -0
  48. metadata +112 -12
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class NetPBMTest < Test::Unit::TestCase
4
+ def test_net_pbm_binary_is_present
5
+ assert !`which ppmtojpeg`.empty?, "Can't seem to find ppmtojpeg binary"
6
+ end
7
+ end
@@ -0,0 +1,56 @@
1
+ require 'test_helper'
2
+
3
+ class ODFMergeTest < Test::Unit::TestCase
4
+ # Tests that an arbitrary hash of data gets correctly merged into a string template
5
+ def test_merge
6
+ template = "<%= @var1 %><%= 1.upto(3).map{ |n| n.to_s }.join %><%= @var2 %>"
7
+
8
+ merged = Documentalist::ODFMerge.merge_string(template, :locals => {
9
+ :var1 => "test",
10
+ :var2 => "working?"
11
+ }
12
+ )
13
+
14
+ assert_equal "test123working?", merged, "Merge wasn't performed correctly"
15
+ end
16
+
17
+ # Tests that the ODFMerge backend correctly extracts the contents.xml contents
18
+ # of an ODF document
19
+ def test_extracts_contents_from_odf_file
20
+ contents = Documentalist::ODFMerge.get_contents fixture_001
21
+
22
+ assert_match /Hello/, contents
23
+ assert_match /thing/, contents
24
+ assert !(contents =~ /%&gt;/)
25
+ assert !(contents =~ /&lt;%=/)
26
+ end
27
+
28
+ # Tests that a merge is correctly performed with an ODF template
29
+ def test_odf_merge
30
+ result = File.join(Dir.tmpdir, "#{(rand * 10 ** 9).to_i}.odt")
31
+
32
+ Documentalist.odf_merge fixture_001,
33
+ :locals => {:thing => "world"},
34
+ :to => result
35
+
36
+ assert /world/, Documentalist::ODFMerge.get_contents(result)
37
+
38
+ FileUtils.rm result
39
+ assert !File.exists?(result), "Oops, we haven't cleaned up our mess..."
40
+ end
41
+
42
+ # Tests that an ODF template can be merged and then converted to another format
43
+ # using the OpenOffice backend
44
+ def test_odf_merge_and_convert
45
+ result = File.join(Dir.tmpdir, "#{(rand * 10 ** 9).to_i}.pdf")
46
+
47
+ Documentalist.odf_merge fixture_001,
48
+ :locals => {:thing => "world"},
49
+ :to => result
50
+
51
+ assert File.exists?(result), "Seems like there is no merged result"
52
+
53
+ FileUtils.rm result
54
+ assert !File.exists?(result), "Oops, we haven't cleaned up our mess..."
55
+ end
56
+ end
@@ -1,21 +1,78 @@
1
- require 'test/unit'
2
- require 'documentalist'
3
- require 'fileutils'
4
- require 'tmpdir'
1
+ require 'test_helper'
5
2
 
6
3
  class OpenOfficeTest < Test::Unit::TestCase
7
- def test_open_office
8
- destination = File.join(Dir.tmpdir, "fixture#{rand(10**9)}.pdf")
4
+ @@oo_server = Documentalist::OpenOffice::Server
9
5
 
10
- Documentalist.convert(
11
- File.join(File.dirname(__FILE__), "fixtures", "fixture.odt"),
12
- destination
13
- )
6
+ def setup
7
+ # Make our test reproductible
8
+ @@oo_server.kill! if @@oo_server.running?
9
+ end
10
+
11
+ def test_open_office_converts_from_odf_to_pdf_with_jod
12
+ destination = File.join(Dir.tmpdir, "#{rand(10**9)}.doc")
13
+
14
+ Documentalist.convert fixture_001, :to => destination
15
+
16
+ assert File.exist?(destination), "Nothing seems to have been converted..."
17
+
18
+ FileUtils.rm destination
19
+ assert !File.exist?(destination), "We didn't clean up our mess!"
20
+ end
21
+
22
+ def test_open_office_converts_from_odf_to_pdf_with_pyod
23
+ Documentalist.config[:open_office][:bridge] = "PYOD"
24
+
25
+ destination = File.join(Dir.tmpdir, "#{rand(10**9)}.doc")
26
+
27
+ Documentalist.convert fixture_001, :to => destination
28
+
29
+ assert File.exist?(destination), "Nothing seems to have been converted..."
30
+
31
+ FileUtils.rm destination
32
+ assert !File.exist?(destination), "We didn't clean up our mess!"
33
+ end
34
+
35
+ def test_open_office_converts_with_just_a_format
36
+ Documentalist.config[:open_office][:bridge] = "PYOD"
14
37
 
15
- assert File.exist?(destination)
38
+ destination = File.join(Dir.tmpdir, "#{rand(10**9)}.doc")
16
39
 
17
- FileUtils.rm(destination)
40
+ temp_origin = File.join(Dir.tmpdir, "#{rand(10 ** 9).to_s}_fixture_001.odt")
41
+ temp_destination = temp_origin.gsub(/\.odt/, ".txt")
42
+
43
+ FileUtils.cp fixture_001, temp_origin
44
+
45
+ Documentalist.convert temp_origin, :to_format => :txt
46
+
47
+ assert File.exist?(temp_origin), "Nothing seems to have been copied..."
48
+ assert File.exist?(temp_destination), "Nothing seems to have been converted..."
49
+
50
+ assert !File.size(temp_destination).zero?
51
+
52
+ FileUtils.rm temp_origin
53
+ FileUtils.rm temp_destination
54
+
55
+ assert !File.exist?(temp_origin), "We didn't clean up our mess!"
56
+ assert !File.exist?(temp_destination), "We didn't clean up our mess!"
57
+ end
58
+
59
+ def test_open_office_should_obey
60
+ assert !@@oo_server.running?, "OpenOffice service is running, it shouldn't be"
61
+
62
+ @@oo_server.start!
63
+ assert @@oo_server.running?, "OpenOffice didn't start"
64
+
65
+ pids = @@oo_server.pids
66
+ assert !(pids.nil? or pids.empty?), "Oops, pid was blank!"
67
+
68
+ @@oo_server.restart!
69
+ assert_not_equal pids, @@oo_server.pids, "Seems like OpenOffice didn't actually get restarted"
70
+ end
18
71
 
19
- assert !File.exist?(destination)
72
+ def test_open_office_should_explode_if_no_destination_given
73
+ assert_raise Documentalist::Error do
74
+ # We want to make sure an exception is raised if no destination is passed
75
+ Documentalist.convert(__FILE__)
76
+ end
20
77
  end
21
78
  end
@@ -0,0 +1,8 @@
1
+ require 'test_helper'
2
+
3
+ class PdfToolsTest < Test::Unit::TestCase
4
+ def test_pdf_tools_binaries_are_present
5
+ assert !`which pdfimages`.empty?, "Can't seem to find pdfimages binary"
6
+ assert !`which pdftotext`.empty?, "Can't seem to find pdftotext binary"
7
+ end
8
+ end
@@ -0,0 +1,39 @@
1
+ require 'test_helper'
2
+ require 'tmpdir'
3
+
4
+ class RailsIntegrationTest < Test::Unit::TestCase
5
+ def test_config_file_gets_copied_and_loaded
6
+ # Undefine Documentalist so we don't get annoying warnings about constant redefinition
7
+ # when redefining Documentalist::BACKENDS when requiring it a second time after it
8
+ # being required a first time through the 'test_helper' require
9
+ Object.send(:remove_const, :Documentalist)
10
+
11
+ # Ensure that RAILS_ROOT is undefined
12
+ assert !Object.const_defined?(:RAILS_ROOT), "RAILS_ROOT constant is defined, I won't go further"
13
+
14
+ # Set up a fake RAILS_ROOT
15
+ tmp_dir = Object.const_set :RAILS_ROOT, File.join(Dir.tmpdir, (rand(10**9)).to_s)
16
+ FileUtils.mkdir_p File.join(tmp_dir, "config")
17
+
18
+ # Set up a fake RAILS_ENV
19
+ Object.const_set :RAILS_ENV, "development"
20
+
21
+ # Initialize in fake Rails context
22
+ require File.join(File.dirname(__FILE__), %w{.. rails init})
23
+
24
+ # Check that the configuration got loaded up properly
25
+ assert_equal Documentalist.config[:python][:path], '/usr/bin/python'
26
+
27
+ # Check that our configuration template got copied
28
+ assert File.exists?(File.join(RAILS_ROOT, %w{config documentalist.yml})),
29
+ "Configuration file did not get copied properly"
30
+
31
+ assert_equal Documentalist.config[:logfile], File.join(RAILS_ROOT, %w{log documentalist-#{RAILS_ENV}.log})
32
+
33
+ # Delete fake RAILS_ROOT
34
+ FileUtils.rm_rf tmp_dir
35
+
36
+ # Check that we cleaned our mess up
37
+ assert !File.exist?(File.join(RAILS_ROOT, %w{config documentalist.yml})), "Temporary file hasn't been removed properly"
38
+ end
39
+ end
@@ -0,0 +1,29 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'flexmock/test_unit'
4
+ require 'documentalist'
5
+
6
+ def fixture_001
7
+ File.join(File.dirname(__FILE__), "fixtures/fixture_001.odt")
8
+ end
9
+
10
+ class Test::Unit::TestCase
11
+ def assert_difference(code, difference = 0, message = nil)
12
+ message = "Returned values were equal" unless message
13
+ start_value = eval(code).to_i
14
+ yield
15
+ end_value = eval(code).to_i
16
+
17
+ if difference
18
+ assert_equal difference, end_value - start_value, message
19
+ else
20
+ assert((end_value - start_value) != 0, message)
21
+ end
22
+ end
23
+
24
+ def assert_no_difference(code, message = "Returned values were different")
25
+ assert_difference(code, 0, message) do
26
+ yield
27
+ end
28
+ end
29
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: documentalist
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 0
10
- version: 0.1.0
9
+ - 1
10
+ version: 0.1.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - David FRANCOIS
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-06-08 00:00:00 +02:00
18
+ date: 2010-06-30 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -34,7 +34,38 @@ dependencies:
34
34
  version: 2.0.2
35
35
  type: :runtime
36
36
  version_requirements: *id001
37
- description: Ruby interface that talks to OpenOffice
37
+ - !ruby/object:Gem::Dependency
38
+ name: SystemTimer
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 11
46
+ segments:
47
+ - 1
48
+ - 2
49
+ version: "1.2"
50
+ type: :runtime
51
+ version_requirements: *id002
52
+ - !ruby/object:Gem::Dependency
53
+ name: flexmock
54
+ prerelease: false
55
+ requirement: &id003 !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ hash: 51
61
+ segments:
62
+ - 0
63
+ - 8
64
+ - 6
65
+ version: 0.8.6
66
+ type: :development
67
+ version_requirements: *id003
68
+ description: The smooth document management experience, usable as a Rails gem plugin or standalone in any ruby application
38
69
  email: david.francois@webflows.fr
39
70
  executables: []
40
71
 
@@ -42,21 +73,85 @@ extensions: []
42
73
 
43
74
  extra_rdoc_files:
44
75
  - README.rdoc
45
- - lib/DocumentConverter.py
76
+ - lib/backends/net_pbm.rb
77
+ - lib/backends/odf_merge.rb
78
+ - lib/backends/open_office.rb
79
+ - lib/backends/open_office/bridges/jodconverter-2.2.2/ChangeLog.txt
80
+ - lib/backends/open_office/bridges/jodconverter-2.2.2/LICENSE.txt
81
+ - lib/backends/open_office/bridges/jodconverter-2.2.2/README.txt
82
+ - lib/backends/open_office/bridges/jodconverter-2.2.2/docs/jodconverter-2.2.2-javadoc.jar
83
+ - lib/backends/open_office/bridges/jodconverter-2.2.2/docs/third-party-licenses/license-commons-io.txt
84
+ - lib/backends/open_office/bridges/jodconverter-2.2.2/docs/third-party-licenses/license-openoffice.org.txt
85
+ - lib/backends/open_office/bridges/jodconverter-2.2.2/docs/third-party-licenses/license-slf4j.txt
86
+ - lib/backends/open_office/bridges/jodconverter-2.2.2/docs/third-party-licenses/license-xstream.txt
87
+ - lib/backends/open_office/bridges/jodconverter-2.2.2/document-formats.xml
88
+ - lib/backends/open_office/bridges/jodconverter-2.2.2/lib/DEPENDENCIES.txt
89
+ - lib/backends/open_office/bridges/jodconverter-2.2.2/lib/commons-cli-1.2.jar
90
+ - lib/backends/open_office/bridges/jodconverter-2.2.2/lib/commons-io-1.4.jar
91
+ - lib/backends/open_office/bridges/jodconverter-2.2.2/lib/jodconverter-2.2.2.jar
92
+ - lib/backends/open_office/bridges/jodconverter-2.2.2/lib/jodconverter-cli-2.2.2.jar
93
+ - lib/backends/open_office/bridges/jodconverter-2.2.2/lib/juh-3.0.1.jar
94
+ - lib/backends/open_office/bridges/jodconverter-2.2.2/lib/jurt-3.0.1.jar
95
+ - lib/backends/open_office/bridges/jodconverter-2.2.2/lib/ridl-3.0.1.jar
96
+ - lib/backends/open_office/bridges/jodconverter-2.2.2/lib/slf4j-api-1.5.6.jar
97
+ - lib/backends/open_office/bridges/jodconverter-2.2.2/lib/slf4j-jdk14-1.5.6.jar
98
+ - lib/backends/open_office/bridges/jodconverter-2.2.2/lib/unoil-3.0.1.jar
99
+ - lib/backends/open_office/bridges/jodconverter-2.2.2/lib/xstream-1.3.1.jar
100
+ - lib/backends/open_office/bridges/jodconverter-2.2.2/src/jodconverter-2.2.2-sources.jar
101
+ - lib/backends/open_office/bridges/jodconverter-2.2.2/src/jodconverter-cli-2.2.2-sources.jar
102
+ - lib/backends/open_office/bridges/pyodconverter.py
103
+ - lib/backends/open_office/server.rb
104
+ - lib/backends/pdf_tools.rb
46
105
  - lib/documentalist.rb
47
- - lib/open_office/server.rb
106
+ - lib/tasks/tasks.rb
48
107
  files:
49
108
  - README.rdoc
50
109
  - Rakefile
110
+ - config/default.yml
51
111
  - documentalist.gemspec
52
112
  - init.rb
53
- - lib/DocumentConverter.py
113
+ - lib/backends/net_pbm.rb
114
+ - lib/backends/odf_merge.rb
115
+ - lib/backends/open_office.rb
116
+ - lib/backends/open_office/bridges/jodconverter-2.2.2/ChangeLog.txt
117
+ - lib/backends/open_office/bridges/jodconverter-2.2.2/LICENSE.txt
118
+ - lib/backends/open_office/bridges/jodconverter-2.2.2/README.txt
119
+ - lib/backends/open_office/bridges/jodconverter-2.2.2/docs/jodconverter-2.2.2-javadoc.jar
120
+ - lib/backends/open_office/bridges/jodconverter-2.2.2/docs/third-party-licenses/license-commons-io.txt
121
+ - lib/backends/open_office/bridges/jodconverter-2.2.2/docs/third-party-licenses/license-openoffice.org.txt
122
+ - lib/backends/open_office/bridges/jodconverter-2.2.2/docs/third-party-licenses/license-slf4j.txt
123
+ - lib/backends/open_office/bridges/jodconverter-2.2.2/docs/third-party-licenses/license-xstream.txt
124
+ - lib/backends/open_office/bridges/jodconverter-2.2.2/document-formats.xml
125
+ - lib/backends/open_office/bridges/jodconverter-2.2.2/lib/DEPENDENCIES.txt
126
+ - lib/backends/open_office/bridges/jodconverter-2.2.2/lib/commons-cli-1.2.jar
127
+ - lib/backends/open_office/bridges/jodconverter-2.2.2/lib/commons-io-1.4.jar
128
+ - lib/backends/open_office/bridges/jodconverter-2.2.2/lib/jodconverter-2.2.2.jar
129
+ - lib/backends/open_office/bridges/jodconverter-2.2.2/lib/jodconverter-cli-2.2.2.jar
130
+ - lib/backends/open_office/bridges/jodconverter-2.2.2/lib/juh-3.0.1.jar
131
+ - lib/backends/open_office/bridges/jodconverter-2.2.2/lib/jurt-3.0.1.jar
132
+ - lib/backends/open_office/bridges/jodconverter-2.2.2/lib/ridl-3.0.1.jar
133
+ - lib/backends/open_office/bridges/jodconverter-2.2.2/lib/slf4j-api-1.5.6.jar
134
+ - lib/backends/open_office/bridges/jodconverter-2.2.2/lib/slf4j-jdk14-1.5.6.jar
135
+ - lib/backends/open_office/bridges/jodconverter-2.2.2/lib/unoil-3.0.1.jar
136
+ - lib/backends/open_office/bridges/jodconverter-2.2.2/lib/xstream-1.3.1.jar
137
+ - lib/backends/open_office/bridges/jodconverter-2.2.2/src/jodconverter-2.2.2-sources.jar
138
+ - lib/backends/open_office/bridges/jodconverter-2.2.2/src/jodconverter-cli-2.2.2-sources.jar
139
+ - lib/backends/open_office/bridges/pyodconverter.py
140
+ - lib/backends/open_office/server.rb
141
+ - lib/backends/pdf_tools.rb
54
142
  - lib/documentalist.rb
55
- - lib/open_office/server.rb
143
+ - lib/tasks/tasks.rb
144
+ - rails/config/documentalist.yml.tpl
56
145
  - rails/init.rb
146
+ - rails/initialize_configuration.rb
57
147
  - test/documentalist_test.rb
58
- - test/fixtures/fixture.odt
148
+ - test/fixtures/fixture_001.odt
149
+ - test/net_pbm_test.rb
150
+ - test/odf_merge_test.rb
59
151
  - test/open_office_test.rb
152
+ - test/pdf_tools_test.rb
153
+ - test/rails_integration_test.rb
154
+ - test/test_helper.rb
60
155
  - Manifest
61
156
  has_rdoc: true
62
157
  homepage: http://github.com/davout/documentalist
@@ -97,7 +192,12 @@ rubyforge_project: documentalist
97
192
  rubygems_version: 1.3.7
98
193
  signing_key:
99
194
  specification_version: 3
100
- summary: Ruby interface that talks to OpenOffice
195
+ summary: The smooth document management experience, usable as a Rails gem plugin or standalone in any ruby application
101
196
  test_files:
102
- - test/documentalist_test.rb
103
197
  - test/open_office_test.rb
198
+ - test/odf_merge_test.rb
199
+ - test/documentalist_test.rb
200
+ - test/rails_integration_test.rb
201
+ - test/test_helper.rb
202
+ - test/pdf_tools_test.rb
203
+ - test/net_pbm_test.rb