docsplit-paperclip-processor 0.1.1 → 0.1.2
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.
@@ -15,6 +15,7 @@ Gem::Specification.new do |s|
|
|
15
15
|
s.rubyforge_project = "docsplit-paperclip-processor"
|
16
16
|
|
17
17
|
s.add_dependency "paperclip", "~> 2.4"
|
18
|
+
s.add_dependency 'ruby-filemagic'
|
18
19
|
|
19
20
|
s.files = `git ls-files`.split("\n")
|
20
21
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
@@ -1,4 +1,6 @@
|
|
1
1
|
require "paperclip"
|
2
|
+
require "filemagic"
|
3
|
+
|
2
4
|
module Paperclip
|
3
5
|
class DocsplitProcessor < Processor
|
4
6
|
attr_accessor :src, :options, :attachment
|
@@ -31,8 +33,10 @@ module Paperclip
|
|
31
33
|
begin
|
32
34
|
src_path = File.expand_path(@src.path)
|
33
35
|
dst_dir = Dir.tmpdir
|
34
|
-
dst_path = File.join(dst_dir, "
|
35
|
-
|
36
|
+
dst_path = File.join(dst_dir, "#{@basename}.pdf")
|
37
|
+
|
38
|
+
if pdf_format?(src_path)
|
39
|
+
dst_path = File.join(dst_dir, "_#{@basename}.pdf")
|
36
40
|
FileUtils.copy_file(src_path, dst_path)
|
37
41
|
else
|
38
42
|
Docsplit.extract_pdf(src_path, :output => dst_dir)
|
@@ -43,6 +47,13 @@ module Paperclip
|
|
43
47
|
end
|
44
48
|
File.open(dst_path)
|
45
49
|
end
|
50
|
+
|
51
|
+
def pdf_format?(file)
|
52
|
+
file_magic = FileMagic.new
|
53
|
+
type = file_magic.file(file)
|
54
|
+
file_magic.close
|
55
|
+
type =~ /pdf/i
|
56
|
+
end
|
46
57
|
end
|
47
58
|
|
48
59
|
class DocsplitImage < DocsplitProcessor
|
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: 31
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 2
|
10
|
+
version: 0.1.2
|
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-05-
|
18
|
+
date: 2012-05-08 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: paperclip
|
@@ -32,6 +32,20 @@ dependencies:
|
|
32
32
|
version: "2.4"
|
33
33
|
type: :runtime
|
34
34
|
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: ruby-filemagic
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 3
|
44
|
+
segments:
|
45
|
+
- 0
|
46
|
+
version: "0"
|
47
|
+
type: :runtime
|
48
|
+
version_requirements: *id002
|
35
49
|
description: This gem is simple Paperclip processor which uses Docsplit to convert uploaded files to pdf, or extract information/thumbnails from them
|
36
50
|
email:
|
37
51
|
- tienlx@gmail.com
|