docsplit-paperclip-processor 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.
@@ -1,28 +1,64 @@
|
|
1
1
|
require "paperclip"
|
2
2
|
module Paperclip
|
3
|
-
class
|
3
|
+
class DocsplitProcessor < Processor
|
4
|
+
attr_accessor :src, :options, :attachment
|
4
5
|
|
5
|
-
|
6
|
+
def initialize(file, options = {}, attachment = nil)
|
7
|
+
super
|
8
|
+
@src = file
|
9
|
+
@options = options
|
10
|
+
@attachment = attachment
|
11
|
+
@basename = File.basename(@file.path, '.*')
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class DocsplitChaining < Processor
|
16
|
+
attr_accessor :options, :attachment
|
6
17
|
|
7
18
|
def initialize(file, options = {}, attachment = nil)
|
8
19
|
super
|
9
|
-
@
|
10
|
-
@
|
11
|
-
@basename = File.basename(@file.path, '.*')
|
20
|
+
@options = options
|
21
|
+
@attachment = attachment
|
12
22
|
end
|
13
23
|
|
24
|
+
def make
|
25
|
+
attachment.to_file(options[:from_style] || :original)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
class DocsplitPdf < DocsplitProcessor
|
30
|
+
def make
|
31
|
+
begin
|
32
|
+
src_path = File.expand_path(@src.path)
|
33
|
+
dst_dir = Dir.tmpdir
|
34
|
+
dst_path = File.join(dst_dir, "_#{@basename}.pdf")
|
35
|
+
if File.extname(src_path) == '.pdf'
|
36
|
+
FileUtils.copy_file(src_path, dst_path)
|
37
|
+
else
|
38
|
+
Docsplit.extract_pdf(src_path, :output => dst_dir)
|
39
|
+
end
|
40
|
+
rescue Exception => e
|
41
|
+
Rails.logger.error e.message
|
42
|
+
raise PaperclipError, "There was an error converting #{@basename} to pdf"
|
43
|
+
end
|
44
|
+
File.open(dst_path)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
class DocsplitImage < DocsplitProcessor
|
14
49
|
def make
|
15
50
|
begin
|
16
51
|
src_path = File.expand_path(@src.path)
|
17
52
|
dst_path = Dir.tmpdir
|
18
|
-
|
53
|
+
pages = options[:pages] || [1]
|
54
|
+
options = @options.merge(:output => dst_path)
|
19
55
|
|
20
|
-
Docsplit.
|
21
|
-
rescue
|
56
|
+
Docsplit.extract_images(src_path, options)
|
57
|
+
rescue Exception => e
|
22
58
|
Rails.logger.error e.message
|
23
|
-
raise PaperclipError, "There was an error
|
59
|
+
raise PaperclipError, "There was an error extracting images from #{@basename}"
|
24
60
|
end
|
25
|
-
File.open(File.join(dst_path, "#{@basename}.
|
61
|
+
File.open(File.join(dst_path, "#{@basename}_#{pages.first}.#{@options[:format]}"))
|
26
62
|
end
|
27
63
|
end
|
28
64
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: docsplit-paperclip-processor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 1
|
10
|
+
version: 0.1.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Tien Le
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-
|
18
|
+
date: 2012-05-07 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: paperclip
|