poleica 0.9.12 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +6 -14
- data/.travis.yml +2 -1
- data/CHANGELOG.md +30 -12
- data/Gemfile +5 -2
- data/Gemfile.lock +69 -146
- data/README.md +22 -12
- data/Rakefile +2 -3
- data/lib/poleica/configuration.rb +1 -0
- data/lib/poleica/converters/coercive.rb +3 -2
- data/lib/poleica/converters/convertible.rb +2 -3
- data/lib/poleica/converters/general.rb +0 -1
- data/lib/poleica/converters/graphics_magick/convert_options_generator.rb +69 -0
- data/lib/poleica/converters/graphics_magick/graphics_magick.rb +37 -0
- data/lib/poleica/converters/graphics_magick/thumbnail_options_generator.rb +108 -0
- data/lib/poleica/converters/libre_office.rb +13 -13
- data/lib/poleica/converters/utils.rb +36 -19
- data/lib/poleica/errors.rb +1 -0
- data/lib/poleica/pathable.rb +2 -2
- data/lib/poleica/polei.rb +1 -1
- data/lib/poleica/types/archive.rb +1 -2
- data/lib/poleica/types/document.rb +17 -18
- data/lib/poleica/types/general.rb +0 -2
- data/lib/poleica/types/image.rb +2 -3
- data/lib/poleica/types/pdf.rb +2 -3
- data/lib/poleica/version.rb +2 -1
- data/lib/poleica.rb +6 -1
- data/poleica.gemspec +0 -2
- data/test/poleica/configuration_test.rb +4 -2
- data/test/poleica/converters/coercive_test.rb +5 -6
- data/test/poleica/converters/graphics_magick_test.rb +38 -21
- data/test/poleica/converters/libre_office_test.rb +7 -8
- data/test/poleica/converters/utils_test.rb +12 -2
- data/test/poleica/types/typeable_test.rb +11 -11
- data/test/support/files/120x70.png +0 -0
- data/test/support/files/30x30.png +0 -0
- data/test/test_helper.rb +2 -1
- metadata +23 -32
- data/lib/poleica/converters/graphics_magick.rb +0 -118
@@ -0,0 +1,108 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
module Poleica
|
3
|
+
module Converters
|
4
|
+
class GraphicsMagick
|
5
|
+
# Generate options for the GraphicsMagick to_thumbnail
|
6
|
+
# @options page [Array, Integer]
|
7
|
+
class ThumbnailOptionsGenerator
|
8
|
+
include Poleica::Converters::Utils
|
9
|
+
attr_reader :polei, :options, :current_width,
|
10
|
+
:current_height, :output_path
|
11
|
+
|
12
|
+
def initialize(polei, options = {})
|
13
|
+
@polei = polei
|
14
|
+
@options = default_options.merge(options)
|
15
|
+
@current_width, @current_height = identify
|
16
|
+
end
|
17
|
+
|
18
|
+
def generate
|
19
|
+
[
|
20
|
+
'convert',
|
21
|
+
"#{polei.path}[0]",
|
22
|
+
orient_options,
|
23
|
+
resize_options,
|
24
|
+
output_options
|
25
|
+
].flatten
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def default_options
|
31
|
+
{
|
32
|
+
height: DEFAULT_MEASURE,
|
33
|
+
width: DEFAULT_MEASURE,
|
34
|
+
auto_orient: true
|
35
|
+
}
|
36
|
+
end
|
37
|
+
|
38
|
+
def orient_options
|
39
|
+
@orient_options ||= options[:auto_orient] ? '-auto-orient' : ''
|
40
|
+
end
|
41
|
+
|
42
|
+
def resize_options
|
43
|
+
@resize_options ||=
|
44
|
+
[
|
45
|
+
'-resize',
|
46
|
+
"#{width_and_height_options}"
|
47
|
+
]
|
48
|
+
end
|
49
|
+
|
50
|
+
def width_and_height_options
|
51
|
+
if current_width >= current_height
|
52
|
+
width_only_option
|
53
|
+
else
|
54
|
+
height_only_option
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def width_only_option
|
59
|
+
if percent(current_width, options[:width]) > 50
|
60
|
+
"#{options[:width]}!x"
|
61
|
+
else
|
62
|
+
"#{current_width}x#{current_height}"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def height_only_option
|
67
|
+
if percent(current_height, options[:height]) > 50
|
68
|
+
"x#{options[:height]}!"
|
69
|
+
else
|
70
|
+
"#{current_width}x#{current_height}"
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def identify
|
75
|
+
line = exec_with_timeout(bin_path(GraphicsMagick), identify_options)
|
76
|
+
width, height = line.split.first.split('x')
|
77
|
+
[width.to_i, height.to_i]
|
78
|
+
end
|
79
|
+
|
80
|
+
def identify_options
|
81
|
+
[
|
82
|
+
'identify',
|
83
|
+
'-format',
|
84
|
+
'%wx%h ',
|
85
|
+
polei.path
|
86
|
+
]
|
87
|
+
end
|
88
|
+
|
89
|
+
def percent(comparing, compared)
|
90
|
+
(comparing.to_f / compared.to_f) * 100
|
91
|
+
end
|
92
|
+
|
93
|
+
def output_options
|
94
|
+
@output_path = if options[:path]
|
95
|
+
if File.directory?(options[:path])
|
96
|
+
name = File.basename(polei.path_with_md5(:png))
|
97
|
+
File.join(options[:path], name)
|
98
|
+
else
|
99
|
+
options[:path]
|
100
|
+
end
|
101
|
+
else
|
102
|
+
polei.path_with_md5(:png)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end # class ThumbnailOptionsGenerator
|
106
|
+
end # class GraphicsMagick
|
107
|
+
end # module Converters
|
108
|
+
end # module Poleica
|
@@ -21,10 +21,10 @@ module Poleica
|
|
21
21
|
opts_gen = OptionsGenerator.new(polei, options, :pdf)
|
22
22
|
exec_with_timeout(bin_path, opts_gen.generate)
|
23
23
|
expected_file_path = opts_gen[:path] || polei.path_with_md5(:pdf)
|
24
|
-
File.
|
24
|
+
File.exist?(expected_file_path) ? expected_file_path : nil
|
25
25
|
ensure
|
26
26
|
temp_file_path = opts_gen.temp_path
|
27
|
-
File.delete(temp_file_path) if File.
|
27
|
+
File.delete(temp_file_path) if File.exist?(temp_file_path)
|
28
28
|
end
|
29
29
|
|
30
30
|
private
|
@@ -58,7 +58,7 @@ module Poleica
|
|
58
58
|
# @return temp_path [String]
|
59
59
|
def temp_path
|
60
60
|
@temp_path ||= generate_temp_path
|
61
|
-
FileUtils.cp(polei.path, @temp_path) unless File.
|
61
|
+
FileUtils.cp(polei.path, @temp_path) unless File.exist?(@temp_path)
|
62
62
|
@temp_path
|
63
63
|
end
|
64
64
|
|
@@ -78,19 +78,19 @@ module Poleica
|
|
78
78
|
end
|
79
79
|
|
80
80
|
def pathable_object
|
81
|
-
|
82
|
-
|
81
|
+
pathable_object = Struct.new(:path).new(options[:path])
|
82
|
+
pathable_object.extend(Poleica::Pathable)
|
83
83
|
end
|
84
84
|
|
85
85
|
def default_options
|
86
|
-
%w
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
86
|
+
%w(
|
87
|
+
--nologo
|
88
|
+
--headless
|
89
|
+
--invisible
|
90
|
+
--norestore
|
91
|
+
--nolockcheck
|
92
|
+
--convert-to
|
93
|
+
)
|
94
94
|
end
|
95
95
|
|
96
96
|
def output_options
|
@@ -6,7 +6,6 @@ module Poleica
|
|
6
6
|
module Converters
|
7
7
|
# An Utility module for the converters needs to be include
|
8
8
|
module Utils
|
9
|
-
|
10
9
|
HOST_OS ||= (defined?('RbConfig') ? RbConfig : Config)::CONFIG['host_os']
|
11
10
|
|
12
11
|
def windows?
|
@@ -22,15 +21,15 @@ module Poleica
|
|
22
21
|
end
|
23
22
|
|
24
23
|
def host_os
|
25
|
-
[:windows, :osx, :linux].find { |os|
|
24
|
+
[:windows, :osx, :linux].find { |os| send(:"#{os}?") }
|
26
25
|
end
|
27
26
|
|
28
|
-
def bin_path
|
29
|
-
converter = :"#{underscorize(self.class)}"
|
27
|
+
def bin_path(given_class = nil)
|
28
|
+
converter = :"#{underscorize(given_class || self.class)}"
|
30
29
|
configuration = Poleica.configuration.send(converter)
|
31
30
|
bin_paths = configuration[:bin_paths]
|
32
31
|
path = bin_paths[host_os] || bin_paths[:linux]
|
33
|
-
|
32
|
+
fail "#{converter} not found @ #{path}" unless File.exist?(path)
|
34
33
|
path
|
35
34
|
end
|
36
35
|
|
@@ -50,24 +49,42 @@ module Poleica
|
|
50
49
|
[extension, options]
|
51
50
|
end
|
52
51
|
|
53
|
-
def exec_with_timeout(bin, args = [],
|
54
|
-
|
55
|
-
|
56
|
-
process
|
57
|
-
|
58
|
-
|
59
|
-
|
52
|
+
def exec_with_timeout(bin, args = [], options = {})
|
53
|
+
timeout = options[:timeout] || Poleica.configuration.timeout
|
54
|
+
process = ChildProcess.build(bin, *Array(args).map(&:to_s))
|
55
|
+
map_std(process) do
|
56
|
+
process.start
|
57
|
+
timeout ? process.poll_for_exit(timeout) : process.wait
|
58
|
+
end
|
60
59
|
rescue ChildProcess::TimeoutError => e
|
61
60
|
process.stop
|
62
|
-
raise
|
61
|
+
raise Poleica::TimeoutError, e.message
|
62
|
+
end
|
63
|
+
|
64
|
+
def map_std(process, &block)
|
65
|
+
stdout, stdout_w, stderr, stderr_w = init_process_std(process)
|
66
|
+
yield
|
67
|
+
stderr_w.close.nil? && fail_if_error(process, stderr)
|
68
|
+
stdout_w.close.nil? && stdout.read
|
69
|
+
ensure
|
70
|
+
stderr_w.close unless stderr_w.closed?
|
71
|
+
stdout_w.close unless stdout_w.closed?
|
72
|
+
end
|
73
|
+
|
74
|
+
def init_process_std(process)
|
75
|
+
stdout, stdout_w = IO.pipe
|
76
|
+
stderr, stderr_w = IO.pipe
|
77
|
+
|
78
|
+
process.io.stdout = stdout_w
|
79
|
+
process.io.stderr = stderr_w
|
80
|
+
|
81
|
+
[stdout, stdout_w, stderr, stderr_w]
|
63
82
|
end
|
64
83
|
|
65
|
-
def
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
else
|
70
|
-
process.io.inherit!
|
84
|
+
def fail_if_error(process, stderr)
|
85
|
+
unless process.exit_code == 0
|
86
|
+
message = "Code: #{process.exit_code} #{stderr.read}"
|
87
|
+
fail Poleica::ProcessError, message
|
71
88
|
end
|
72
89
|
end
|
73
90
|
end # module Utils
|
data/lib/poleica/errors.rb
CHANGED
data/lib/poleica/pathable.rb
CHANGED
@@ -7,11 +7,11 @@ module Poleica
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def path_without_extension
|
10
|
-
File.join(File.dirname(
|
10
|
+
File.join(File.dirname(path), File.basename(path, '.*'))
|
11
11
|
end
|
12
12
|
|
13
13
|
def path_with_md5(extension = self.extension)
|
14
|
-
data = File.read(
|
14
|
+
data = File.read(path)
|
15
15
|
md5 = Digest::MD5.new
|
16
16
|
digest = md5.hexdigest(data)
|
17
17
|
"#{path_without_extension}-#{digest}.#{extension}"
|
data/lib/poleica/polei.rb
CHANGED
@@ -4,25 +4,25 @@ module Poleica
|
|
4
4
|
# Document Type
|
5
5
|
class Document
|
6
6
|
COMPATIBLE_MIMETYPES = [
|
7
|
-
'
|
8
|
-
'application/vnd.oasis.opendocument.
|
9
|
-
'application/vnd.oasis.opendocument.
|
10
|
-
'application/vnd.oasis.opendocument.
|
11
|
-
'application/vnd.oasis.opendocument.
|
12
|
-
'application/vnd.oasis.opendocument.
|
13
|
-
'application/vnd.oasis.opendocument.
|
14
|
-
'application/vnd.oasis.opendocument.text',
|
15
|
-
'application/vnd.ms-office',
|
16
|
-
'application/vnd.ms-excel',
|
17
|
-
'application/vnd.ms-office',
|
18
|
-
'application/msword',
|
19
|
-
'text/html',
|
20
|
-
'text/plain',
|
21
|
-
'text/rtf'
|
7
|
+
'application/vnd.oasis.opendocument.presentation', # .opd
|
8
|
+
'application/vnd.oasis.opendocument.text-master', # .odm
|
9
|
+
'application/vnd.oasis.opendocument.spreadsheet', # .ods
|
10
|
+
'application/vnd.oasis.opendocument.graphics', # .odg
|
11
|
+
'application/vnd.oasis.opendocument.formula', # .odf
|
12
|
+
'application/vnd.oasis.opendocument.chart', # .odc
|
13
|
+
'application/vnd.oasis.opendocument.image', # .odi
|
14
|
+
'application/vnd.oasis.opendocument.text', # .odt
|
15
|
+
'application/vnd.ms-office', # .doc
|
16
|
+
'application/vnd.ms-excel', # .xls
|
17
|
+
'application/vnd.ms-office', # .ppt, .pps
|
18
|
+
'application/msword', # .doc
|
19
|
+
'text/html', # .html, .htm
|
20
|
+
'text/plain', # .txt
|
21
|
+
'text/rtf' # .rft
|
22
22
|
]
|
23
23
|
|
24
24
|
# Unsupported :( : key, pages
|
25
|
-
COMPATIBLE_EXTENSIONS = %w
|
25
|
+
COMPATIBLE_EXTENSIONS = %w(
|
26
26
|
html
|
27
27
|
htm
|
28
28
|
odt
|
@@ -43,10 +43,9 @@ module Poleica
|
|
43
43
|
pps
|
44
44
|
txt
|
45
45
|
rft
|
46
|
-
|
46
|
+
)
|
47
47
|
|
48
48
|
def initialize(file_path)
|
49
|
-
|
50
49
|
end
|
51
50
|
end # class Document
|
52
51
|
end # module Types
|
@@ -4,12 +4,10 @@ module Poleica
|
|
4
4
|
# Null Object Pattern Type, this is the type returned if no compatible
|
5
5
|
# types are found
|
6
6
|
class General
|
7
|
-
|
8
7
|
COMPATIBLE_MIMETYPES = []
|
9
8
|
COMPATIBLE_EXTENSIONS = []
|
10
9
|
|
11
10
|
def initialize(file_path)
|
12
|
-
|
13
11
|
end
|
14
12
|
end # class General
|
15
13
|
end # module Types
|
data/lib/poleica/types/image.rb
CHANGED
@@ -14,7 +14,7 @@ module Poleica
|
|
14
14
|
'image/png' # .png
|
15
15
|
]
|
16
16
|
|
17
|
-
COMPATIBLE_EXTENSIONS = %w
|
17
|
+
COMPATIBLE_EXTENSIONS = %w(
|
18
18
|
tiff
|
19
19
|
jpeg
|
20
20
|
ppm
|
@@ -27,10 +27,9 @@ module Poleica
|
|
27
27
|
tif
|
28
28
|
gif
|
29
29
|
png
|
30
|
-
|
30
|
+
)
|
31
31
|
|
32
32
|
def initialize(file_path)
|
33
|
-
|
34
33
|
end
|
35
34
|
end # class Image
|
36
35
|
end # module Types
|
data/lib/poleica/types/pdf.rb
CHANGED
data/lib/poleica/version.rb
CHANGED
data/lib/poleica.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
+
# The Awesome Namespace
|
3
|
+
# Poleica is a general converter
|
2
4
|
module Poleica
|
3
5
|
def self.new(file_or_path)
|
4
6
|
file_or_path = file_or_path.path if file_or_path.respond_to?(:path)
|
@@ -20,8 +22,11 @@ require 'poleica/types/all'
|
|
20
22
|
require 'poleica/converters/utils'
|
21
23
|
require 'poleica/converters/general'
|
22
24
|
require 'poleica/converters/coercive'
|
23
|
-
require 'poleica/converters/graphics_magick'
|
24
25
|
require 'poleica/converters/libre_office'
|
26
|
+
require 'poleica/converters/graphics_magick/graphics_magick'
|
27
|
+
require 'poleica/converters/graphics_magick/thumbnail_options_generator'
|
28
|
+
require 'poleica/converters/graphics_magick/convert_options_generator'
|
29
|
+
# /!\ Should be last converters
|
25
30
|
require 'poleica/converters/convertible'
|
26
31
|
|
27
32
|
require 'poleica/pathable'
|
data/poleica.gemspec
CHANGED
@@ -15,8 +15,6 @@ Gem::Specification.new do |s|
|
|
15
15
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
16
16
|
|
17
17
|
s.add_runtime_dependency 'childprocess'
|
18
|
-
# s.add_runtime_dependency 'posix-spawn' ONLY MRI
|
19
18
|
|
20
19
|
s.add_development_dependency 'bundler', '~> 1.3'
|
21
|
-
s.add_development_dependency 'rake'
|
22
20
|
end
|
@@ -5,9 +5,11 @@ class ConfigurationTest < Minitest::Test
|
|
5
5
|
def test_timeout_configuration
|
6
6
|
start_time = Time.now
|
7
7
|
Poleica.configure { |config| config.timeout = 1 }
|
8
|
-
|
8
|
+
# rubocop:disable RescueModifier
|
9
|
+
Poleica::Converters::Utils.exec_with_timeout('sleep 10') rescue nil
|
10
|
+
# rubocop:enable
|
9
11
|
duration = Time.now - start_time
|
10
|
-
assert(duration <
|
12
|
+
assert(duration < 10)
|
11
13
|
ensure
|
12
14
|
Poleica.configure { |config| config.timeout = 120 }
|
13
15
|
end
|
@@ -1,7 +1,6 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
require 'test_helper'
|
3
3
|
# Test the Coercive Converter Module
|
4
|
-
|
5
4
|
class CoerciveTest < Minitest::Test
|
6
5
|
DOC_PATH = "#{Support.support_path}/files/example.doc"
|
7
6
|
|
@@ -18,13 +17,13 @@ class CoerciveTest < Minitest::Test
|
|
18
17
|
|
19
18
|
def test_try_convert_intermediary_file_creation
|
20
19
|
coercive_conv.send(:coerce, :to_png, {})
|
21
|
-
assert(File.
|
20
|
+
assert(File.exist?(expected_pdf_path))
|
22
21
|
clean_pdf_file
|
23
22
|
end
|
24
23
|
|
25
24
|
def test_try_convert_file_creation
|
26
25
|
coercive_conv.send(:try_convert, :to_png)
|
27
|
-
assert(File.
|
26
|
+
assert(File.exist?(find_png_path))
|
28
27
|
clean_png_file(find_png_path)
|
29
28
|
clean_pdf_file
|
30
29
|
end
|
@@ -32,7 +31,7 @@ class CoerciveTest < Minitest::Test
|
|
32
31
|
def test_coercive_conversion
|
33
32
|
polei = Poleica.new(DOC_PATH)
|
34
33
|
returned_path = polei.to_png
|
35
|
-
assert(File.
|
34
|
+
assert(File.exist?(returned_path))
|
36
35
|
clean_png_file(find_png_path)
|
37
36
|
end
|
38
37
|
|
@@ -45,11 +44,11 @@ class CoerciveTest < Minitest::Test
|
|
45
44
|
private
|
46
45
|
|
47
46
|
def clean_pdf_file
|
48
|
-
File.
|
47
|
+
File.exist?(expected_pdf_path) && File.delete(expected_pdf_path)
|
49
48
|
end
|
50
49
|
|
51
50
|
def clean_png_file(png_path = expected_png_path)
|
52
|
-
File.
|
51
|
+
File.exist?(png_path) && File.delete(png_path)
|
53
52
|
end
|
54
53
|
|
55
54
|
def expected_pdf_path
|
@@ -2,7 +2,6 @@
|
|
2
2
|
require 'test_helper'
|
3
3
|
# Test the GraphicsMagick Converter Module
|
4
4
|
class GraphicsMagickTest < Minitest::Test
|
5
|
-
|
6
5
|
PDF_PATH = "#{Support.support_path}/files/example.pdf"
|
7
6
|
|
8
7
|
def setup
|
@@ -18,7 +17,7 @@ class GraphicsMagickTest < Minitest::Test
|
|
18
17
|
|
19
18
|
def test_to_png_create_a_file
|
20
19
|
returned_path = pdf_polei.to_png
|
21
|
-
assert(returned_path && File.
|
20
|
+
assert(returned_path && File.exist?(returned_path))
|
22
21
|
clean_png_file
|
23
22
|
end
|
24
23
|
|
@@ -26,31 +25,31 @@ class GraphicsMagickTest < Minitest::Test
|
|
26
25
|
path_option = "#{Support.support_path}/files/path_test.png"
|
27
26
|
returned_path = pdf_polei.to_png(path: path_option)
|
28
27
|
assert(returned_path)
|
29
|
-
assert(File.
|
30
|
-
assert(File.
|
28
|
+
assert(File.exist?(path_option))
|
29
|
+
assert(File.exist?(returned_path))
|
31
30
|
assert_equal(returned_path, path_option)
|
32
|
-
File.delete(path_option) if File.
|
31
|
+
File.delete(path_option) if File.exist?(path_option)
|
33
32
|
end
|
34
33
|
|
35
34
|
def test_to_png_path_with_spaces
|
36
35
|
path_option = "#{Support.support_path}/files/path with spaces.png"
|
37
36
|
returned_path = pdf_polei.to_png(path: path_option)
|
38
37
|
assert(returned_path)
|
39
|
-
assert(File.
|
40
|
-
assert(File.
|
38
|
+
assert(File.exist?(path_option))
|
39
|
+
assert(File.exist?(returned_path))
|
41
40
|
assert_equal(returned_path, path_option)
|
42
|
-
File.delete(path_option) if File.
|
41
|
+
File.delete(path_option) if File.exist?(path_option)
|
43
42
|
end
|
44
43
|
|
45
44
|
def test_path_folder
|
46
45
|
path_option = '/tmp/'
|
47
|
-
expected_path = "/tmp/#{File.basename(pdf_polei.path_with_md5)}"
|
46
|
+
expected_path = "/tmp/#{File.basename(pdf_polei.path_with_md5(:png))}"
|
48
47
|
returned_path = pdf_polei.to_png(path: path_option)
|
49
48
|
assert(returned_path)
|
50
|
-
assert(File.
|
51
|
-
assert(File.
|
49
|
+
assert(File.exist?(expected_path))
|
50
|
+
assert(File.exist?(returned_path))
|
52
51
|
assert_equal(expected_path, returned_path)
|
53
|
-
File.delete(expected_path) if File.
|
52
|
+
File.delete(expected_path) if File.exist?(expected_path)
|
54
53
|
end
|
55
54
|
|
56
55
|
def test_force_resize_option
|
@@ -76,22 +75,40 @@ class GraphicsMagickTest < Minitest::Test
|
|
76
75
|
clean_png_file
|
77
76
|
end
|
78
77
|
|
79
|
-
def
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
78
|
+
def test_thumbnail
|
79
|
+
path_option = "#{Support.support_path}/files/120x70.png"
|
80
|
+
polei = Poleica::Polei.new(path_option)
|
81
|
+
returned_path = polei.to_thumbnail(width: 100,
|
82
|
+
height: 100)
|
83
|
+
expected_path = Support.expected_converted_path(path_option)
|
84
|
+
bin_path = Poleica::Converters::GraphicsMagick.new(polei).bin_path
|
85
85
|
assert_equal(expected_path, returned_path)
|
86
86
|
size = `#{bin_path} identify #{returned_path}`.split[2][/(\w)*/]
|
87
|
-
assert_equal('
|
88
|
-
|
87
|
+
assert_equal('100x58', size)
|
88
|
+
if File.exist?(expected_path)
|
89
|
+
File.delete(expected_path)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_thumbnail_too_small
|
94
|
+
path_option = "#{Support.support_path}/files/30x30.png"
|
95
|
+
polei = Poleica::Polei.new(path_option)
|
96
|
+
returned_path = polei.to_thumbnail(width: 100,
|
97
|
+
height: 100)
|
98
|
+
expected_path = Support.expected_converted_path(path_option)
|
99
|
+
bin_path = Poleica::Converters::GraphicsMagick.new(polei).bin_path
|
100
|
+
assert_equal(expected_path, returned_path)
|
101
|
+
size = `#{bin_path} identify #{returned_path}`.split[2][/(\w)*/]
|
102
|
+
assert_equal('30x30', size)
|
103
|
+
if File.exist?(expected_path)
|
104
|
+
File.delete(expected_path)
|
105
|
+
end
|
89
106
|
end
|
90
107
|
|
91
108
|
private
|
92
109
|
|
93
110
|
def clean_png_file
|
94
|
-
if File.
|
111
|
+
if File.exist?(Support.expected_converted_path(PDF_PATH, :png))
|
95
112
|
File.delete(Support.expected_converted_path(PDF_PATH, :png))
|
96
113
|
end
|
97
114
|
end
|
@@ -2,7 +2,6 @@
|
|
2
2
|
require 'test_helper'
|
3
3
|
# Test the LibreOffice Converter Module
|
4
4
|
class LibreOfficeTest < Minitest::Test
|
5
|
-
|
6
5
|
DOC_PATH = "#{Support.support_path}/files/example.doc"
|
7
6
|
|
8
7
|
def setup
|
@@ -18,7 +17,7 @@ class LibreOfficeTest < Minitest::Test
|
|
18
17
|
|
19
18
|
def test_to_pdf_create_a_file
|
20
19
|
returned_path = doc_polei.to_pdf
|
21
|
-
assert(returned_path && File.
|
20
|
+
assert(returned_path && File.exist?(returned_path))
|
22
21
|
clean_pdf_file
|
23
22
|
end
|
24
23
|
|
@@ -26,25 +25,25 @@ class LibreOfficeTest < Minitest::Test
|
|
26
25
|
path_option = "#{Support.support_path}/files/path_test.pdf"
|
27
26
|
returned_path = doc_polei.to_pdf(path: path_option)
|
28
27
|
assert(returned_path)
|
29
|
-
assert(File.
|
30
|
-
assert(File.
|
28
|
+
assert(File.exist?(path_option))
|
29
|
+
assert(File.exist?(returned_path))
|
31
30
|
assert_equal(returned_path, path_option)
|
32
|
-
File.delete(path_option) if File.
|
31
|
+
File.delete(path_option) if File.exist?(path_option)
|
33
32
|
end
|
34
33
|
|
35
34
|
def test_path_folder
|
36
35
|
path_option = '/tmp/'
|
37
36
|
returned_path = doc_polei.to_pdf(path: path_option)
|
38
37
|
assert(returned_path)
|
39
|
-
assert(File.
|
40
|
-
assert(File.
|
38
|
+
assert(File.exist?(path_option))
|
39
|
+
assert(File.exist?(returned_path))
|
41
40
|
assert_equal(returned_path, path_option)
|
42
41
|
end
|
43
42
|
|
44
43
|
private
|
45
44
|
|
46
45
|
def clean_pdf_file
|
47
|
-
if File.
|
46
|
+
if File.exist?(Support.expected_converted_path(DOC_PATH, :pdf))
|
48
47
|
File.delete(Support.expected_converted_path(DOC_PATH, :pdf))
|
49
48
|
end
|
50
49
|
end
|