docsplit-paperclip-processor 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,28 +1,64 @@
1
1
  require "paperclip"
2
2
  module Paperclip
3
- class DocsplitPdf < Processor
3
+ class DocsplitProcessor < Processor
4
+ attr_accessor :src, :options, :attachment
4
5
 
5
- attr_accessor :src, :options
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
- @src = file
10
- @options = options
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
- escaped_src, escaped_dst = [src_path, dst_path].map &Docsplit::ESCAPE
53
+ pages = options[:pages] || [1]
54
+ options = @options.merge(:output => dst_path)
19
55
 
20
- Docsplit.extract_pdf(escaped_src, :output => escaped_dst)
21
- rescue Cocaine::CommandLineError => e
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 converting #{basename} to pdf"
59
+ raise PaperclipError, "There was an error extracting images from #{@basename}"
24
60
  end
25
- File.open(File.join(dst_path, "#{@basename}.pdf"))
61
+ File.open(File.join(dst_path, "#{@basename}_#{pages.first}.#{@options[:format]}"))
26
62
  end
27
63
  end
28
64
  end
@@ -1,7 +1,7 @@
1
1
  module Docsplit
2
2
  module Paperclip
3
3
  module Processor
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
6
6
  end
7
7
  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: 27
4
+ hash: 25
5
5
  prerelease:
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
  - Tien Le
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-03-09 00:00:00 Z
18
+ date: 2012-05-07 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: paperclip