poleica 0.9.12 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +6 -14
  2. data/.travis.yml +2 -1
  3. data/CHANGELOG.md +30 -12
  4. data/Gemfile +5 -2
  5. data/Gemfile.lock +69 -146
  6. data/README.md +22 -12
  7. data/Rakefile +2 -3
  8. data/lib/poleica/configuration.rb +1 -0
  9. data/lib/poleica/converters/coercive.rb +3 -2
  10. data/lib/poleica/converters/convertible.rb +2 -3
  11. data/lib/poleica/converters/general.rb +0 -1
  12. data/lib/poleica/converters/graphics_magick/convert_options_generator.rb +69 -0
  13. data/lib/poleica/converters/graphics_magick/graphics_magick.rb +37 -0
  14. data/lib/poleica/converters/graphics_magick/thumbnail_options_generator.rb +108 -0
  15. data/lib/poleica/converters/libre_office.rb +13 -13
  16. data/lib/poleica/converters/utils.rb +36 -19
  17. data/lib/poleica/errors.rb +1 -0
  18. data/lib/poleica/pathable.rb +2 -2
  19. data/lib/poleica/polei.rb +1 -1
  20. data/lib/poleica/types/archive.rb +1 -2
  21. data/lib/poleica/types/document.rb +17 -18
  22. data/lib/poleica/types/general.rb +0 -2
  23. data/lib/poleica/types/image.rb +2 -3
  24. data/lib/poleica/types/pdf.rb +2 -3
  25. data/lib/poleica/version.rb +2 -1
  26. data/lib/poleica.rb +6 -1
  27. data/poleica.gemspec +0 -2
  28. data/test/poleica/configuration_test.rb +4 -2
  29. data/test/poleica/converters/coercive_test.rb +5 -6
  30. data/test/poleica/converters/graphics_magick_test.rb +38 -21
  31. data/test/poleica/converters/libre_office_test.rb +7 -8
  32. data/test/poleica/converters/utils_test.rb +12 -2
  33. data/test/poleica/types/typeable_test.rb +11 -11
  34. data/test/support/files/120x70.png +0 -0
  35. data/test/support/files/30x30.png +0 -0
  36. data/test/test_helper.rb +2 -1
  37. metadata +23 -32
  38. data/lib/poleica/converters/graphics_magick.rb +0 -118
@@ -4,23 +4,33 @@ require 'test_helper'
4
4
  class UtilsTest < Minitest::Test
5
5
  def test_exec_with_timeout
6
6
  start_time = Time.now
7
- Poleica::Converters::Utils.exec_with_timeout('sleep', 2, 0.1) rescue nil
7
+ # rubocop:disable RescueModifier
8
+ Poleica::Converters::Utils.exec_with_timeout('sleep', 2, timeout: 0.1) rescue nil
9
+ # rubocop:enable
8
10
  duration = Time.now - start_time
9
11
  assert(duration < 2)
10
12
  end
11
13
 
12
14
  def test_exec_with_timeout_raise_an_exception
13
15
  assert_raises(Poleica::TimeoutError) do
14
- Poleica::Converters::Utils.exec_with_timeout('sleep', 2, 0.1)
16
+ Poleica::Converters::Utils.exec_with_timeout('sleep', 2, timeout: 0.1)
15
17
  end
16
18
  end
17
19
 
18
20
  def test_exec_with_timeout_kill
19
21
  assert(`ps -a | grep soffice.bin | grep -v grep`.empty?)
20
22
  Poleica.configure { |conf| conf.timeout = 0.001 }
23
+ # rubocop:disable RescueModifier
21
24
  Poleica.new("#{Support.support_path}/files/example.doc").to_png rescue nil
25
+ # rubocop:enable
22
26
  assert(`ps -a | grep example.doc | grep -v grep`.empty?)
23
27
  ensure
24
28
  Poleica.configure { |config| config.timeout = 120 }
25
29
  end
30
+
31
+ def test_exec_with_timeout_exception
32
+ assert_raises(Poleica::ProcessError) do
33
+ Poleica::Converters::Utils.exec_with_timeout('false')
34
+ end
35
+ end
26
36
  end
@@ -2,14 +2,14 @@
2
2
  require 'test_helper'
3
3
  # Test the Typeable Module
4
4
  class TypeableTest < Minitest::Test
5
- EXTENSION_NAMES ||= %w{doc pdf mp3 png}
5
+ EXTENSION_NAMES ||= %w(doc pdf mp3 png)
6
6
 
7
7
  def test_that_it_extracts_a_mimetype
8
- expected_mime_types = %w{
9
- application/pdf
10
- audio/mpeg
11
- image/png
12
- }
8
+ expected_mime_types = %w(
9
+ application/pdf
10
+ audio/mpeg
11
+ image/png
12
+ )
13
13
  mime_types = files_enumerator.map(&:file_mimetype)
14
14
  # Don't test doc files, it doesnt behave the same way
15
15
  # on Linux or MacOS (maybe FIXME)
@@ -25,11 +25,11 @@ class TypeableTest < Minitest::Test
25
25
 
26
26
  def test_that_it_extracts_a_type_object
27
27
  expected_classes = [
28
- Poleica::Types::Document,
29
- Poleica::Types::General,
30
- Poleica::Types::Document,
31
- Poleica::Types::Image
32
- ]
28
+ Poleica::Types::Document,
29
+ Poleica::Types::General,
30
+ Poleica::Types::Document,
31
+ Poleica::Types::Image
32
+ ]
33
33
  classes = files_enumerator.map do |type_detector|
34
34
  type_detector.file_type.class
35
35
  end
Binary file
Binary file
data/test/test_helper.rb CHANGED
@@ -10,7 +10,8 @@ if ENV['COVERAGE'] || ENV['TRAVIS']
10
10
  Coveralls.wear!
11
11
  end
12
12
 
13
- gem 'minitest'
13
+ Bundler.require(:default, :test)
14
+
14
15
  require 'minitest/autorun'
15
16
  require 'poleica'
16
17
 
metadata CHANGED
@@ -1,57 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: poleica
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.12
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Antoine Lyset
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-10 00:00:00.000000000 Z
11
+ date: 2015-03-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
+ name: childprocess
14
15
  requirement: !ruby/object:Gem::Requirement
15
16
  requirements:
16
- - - ! '>='
17
+ - - ">="
17
18
  - !ruby/object:Gem::Version
18
19
  version: '0'
20
+ type: :runtime
21
+ prerelease: false
19
22
  version_requirements: !ruby/object:Gem::Requirement
20
23
  requirements:
21
- - - ! '>='
24
+ - - ">="
22
25
  - !ruby/object:Gem::Version
23
26
  version: '0'
24
- type: :runtime
25
- prerelease: false
26
- name: childprocess
27
27
  - !ruby/object:Gem::Dependency
28
+ name: bundler
28
29
  requirement: !ruby/object:Gem::Requirement
29
30
  requirements:
30
- - - ~>
31
- - !ruby/object:Gem::Version
32
- version: '1.3'
33
- version_requirements: !ruby/object:Gem::Requirement
34
- requirements:
35
- - - ~>
31
+ - - "~>"
36
32
  - !ruby/object:Gem::Version
37
33
  version: '1.3'
38
34
  type: :development
39
35
  prerelease: false
40
- name: bundler
41
- - !ruby/object:Gem::Dependency
42
- requirement: !ruby/object:Gem::Requirement
43
- requirements:
44
- - - ! '>='
45
- - !ruby/object:Gem::Version
46
- version: '0'
47
36
  version_requirements: !ruby/object:Gem::Requirement
48
37
  requirements:
49
- - - ! '>='
38
+ - - "~>"
50
39
  - !ruby/object:Gem::Version
51
- version: '0'
52
- type: :development
53
- prerelease: false
54
- name: rake
40
+ version: '1.3'
55
41
  description: Poleica can convert docs and images to PDF and PNG, it can be extended
56
42
  to handle a lot of converters
57
43
  email: antoinelyset@gmail.com
@@ -59,8 +45,8 @@ executables: []
59
45
  extensions: []
60
46
  extra_rdoc_files: []
61
47
  files:
62
- - .gitignore
63
- - .travis.yml
48
+ - ".gitignore"
49
+ - ".travis.yml"
64
50
  - CHANGELOG.md
65
51
  - Gemfile
66
52
  - Gemfile.lock
@@ -73,7 +59,9 @@ files:
73
59
  - lib/poleica/converters/coercive.rb
74
60
  - lib/poleica/converters/convertible.rb
75
61
  - lib/poleica/converters/general.rb
76
- - lib/poleica/converters/graphics_magick.rb
62
+ - lib/poleica/converters/graphics_magick/convert_options_generator.rb
63
+ - lib/poleica/converters/graphics_magick/graphics_magick.rb
64
+ - lib/poleica/converters/graphics_magick/thumbnail_options_generator.rb
77
65
  - lib/poleica/converters/libre_office.rb
78
66
  - lib/poleica/converters/utils.rb
79
67
  - lib/poleica/errors.rb
@@ -99,7 +87,9 @@ files:
99
87
  - test/poleica/polei_test.rb
100
88
  - test/poleica/types/typeable_test.rb
101
89
  - test/poleica_test.rb
90
+ - test/support/files/120x70.png
102
91
  - test/support/files/1px.gif
92
+ - test/support/files/30x30.png
103
93
  - test/support/files/example.doc
104
94
  - test/support/files/example.mp3
105
95
  - test/support/files/example.pdf
@@ -115,17 +105,17 @@ require_paths:
115
105
  - lib
116
106
  required_ruby_version: !ruby/object:Gem::Requirement
117
107
  requirements:
118
- - - ! '>='
108
+ - - ">="
119
109
  - !ruby/object:Gem::Version
120
110
  version: '0'
121
111
  required_rubygems_version: !ruby/object:Gem::Requirement
122
112
  requirements:
123
- - - ! '>='
113
+ - - ">="
124
114
  - !ruby/object:Gem::Version
125
115
  version: '0'
126
116
  requirements: []
127
117
  rubyforge_project:
128
- rubygems_version: 2.0.0
118
+ rubygems_version: 2.2.2
129
119
  signing_key:
130
120
  specification_version: 4
131
121
  summary: A general converter and thumbnail creator
@@ -141,10 +131,11 @@ test_files:
141
131
  - test/poleica/polei_test.rb
142
132
  - test/poleica/types/typeable_test.rb
143
133
  - test/poleica_test.rb
134
+ - test/support/files/120x70.png
144
135
  - test/support/files/1px.gif
136
+ - test/support/files/30x30.png
145
137
  - test/support/files/example.doc
146
138
  - test/support/files/example.mp3
147
139
  - test/support/files/example.pdf
148
140
  - test/support/files/example.png
149
141
  - test/test_helper.rb
150
- has_rdoc:
@@ -1,118 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
- module Poleica
3
- module Converters
4
- # The GraphicsMagick converter, use the 'gm' command to convert images and
5
- # documents
6
- class GraphicsMagick
7
- include Poleica::Converters::Utils
8
-
9
- COMPATIBLE_TYPES = [
10
- Types::Image,
11
- Types::PDF
12
- ]
13
-
14
- DEFAULT_MEASURE = 612
15
-
16
- attr_reader :polei
17
-
18
- def initialize(polei)
19
- @polei = polei
20
- end
21
-
22
- def to_png(options = {})
23
- opts_gen = OptionsGenerator.new(polei, options)
24
- exec_with_timeout(bin_path, opts_gen.generate)
25
- expected_file_path = opts_gen[:path]
26
- File.exists?(expected_file_path) ? expected_file_path : nil
27
- end
28
-
29
- private
30
-
31
- # Generate options for the gm command
32
- # @options page [Array, Integer]
33
- class OptionsGenerator
34
- attr_reader :polei, :options
35
-
36
- def initialize(polei, options = {})
37
- @polei = polei
38
- @options = default_options.merge(options)
39
- end
40
-
41
- def generate
42
- [
43
- 'convert',
44
- "#{polei.path}#{page_options}",
45
- orient_options,
46
- thumbnail_or_resize_options,
47
- output_options
48
- ].flatten
49
- end
50
-
51
- def [](key)
52
- options[key]
53
- end
54
-
55
- private
56
-
57
- def default_options
58
- {
59
- height: DEFAULT_MEASURE,
60
- width: DEFAULT_MEASURE,
61
- force_resize: false,
62
- auto_orient: true,
63
- thumbnail: false,
64
- page: 0,
65
- }
66
- end
67
-
68
- def page_options
69
- @page_options ||=
70
- "#{Array(options[:page]).flatten.compact.uniq.sort.to_s}"
71
- end
72
-
73
- def orient_options
74
- @orient_options ||= options[:auto_orient] ? '-auto-orient' : ''
75
- end
76
-
77
- def thumbnail_or_resize_options
78
- @thumbnail_or_resize_options ||=
79
- options[:thumbnail] ? thumbnail_options : resize_options
80
- end
81
-
82
- def thumbnail_options
83
- @thumbnail_options ||=
84
- [
85
- '-thumbnail',
86
- "#{options[:width]}x#{options[:height]}^",
87
- '-gravity',
88
- 'center',
89
- '-extent',
90
- "#{options[:width]}x#{options[:height]}"
91
- ]
92
- end
93
-
94
- def resize_options
95
- @resize_options ||=
96
- [
97
- '-resize',
98
- "#{options[:width]}x#{options[:height]}" +
99
- "#{'!' if options[:force_resize]}"
100
- ]
101
- end
102
-
103
- def output_options
104
- options[:path] = if options[:path]
105
- if File.directory?(options[:path])
106
- basename = File.basename(polei.path_with_md5)
107
- File.join(options[:path], basename)
108
- else
109
- options[:path]
110
- end
111
- else
112
- polei.path_with_md5(:png)
113
- end
114
- end
115
- end # class OptionsGenerator
116
- end # class GraphicsMagick
117
- end # module Converters
118
- end # module Poleica