paperclip_utils 1.0.0 → 1.0.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.
- checksums.yaml +4 -4
- data/README.md +7 -7
- data/lib/paperclip_utils/version.rb +1 -1
- data/lib/paperclip_utils.rb +3 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8a0899fdf1f5ba88dc1cfccaa2bc59adc756dcf2
|
4
|
+
data.tar.gz: ccfff2e9c8fa0aef4016c9c9c77ecd70aaeee525
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a1c6a70af2891e30bf6918a48e394a8fc570e9e2baa6ac258836520e04154458e9a2ca724336e913e43e39791a6447e4f684a6942b60a05d67aef08edbdb43f7
|
7
|
+
data.tar.gz: 99a0ff3c01000b824826813ab5f2953da145f0f339a4a23c65e6344f99028b9d19d078821bdce847f321afee78e97dd94a41987b6cb01892cd5db9bd4e2a0153
|
data/README.md
CHANGED
@@ -1,20 +1,20 @@
|
|
1
1
|
# Paperclip Utils
|
2
2
|
<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=VKY8YAWAS5XRQ&lc=CA&item_name=Weston%20Ganger&item_number=paperclip_utils¤cy_code=USD&bn=PP%2dDonationsBF%3abtn_donate_SM%2egif%3aNonHostedGuest" target="_blank" title="Donate"><img src="https://www.paypalobjects.com/en_US/i/btn/btn_donate_SM.gif" alt="Donate"/></a>
|
3
3
|
|
4
|
-
Paperclip Utils
|
4
|
+
Paperclip Utils is a helper class for easier dynamic processors and styles on your Paperclip file uploads
|
5
5
|
|
6
6
|
|
7
7
|
# Install
|
8
8
|
```ruby
|
9
9
|
gem install paperclip_utils
|
10
|
+
```
|
10
11
|
|
11
12
|
|
12
|
-
|
13
|
-
Paperclip Utils contains the following methods to ActiveRecord::Base:
|
13
|
+
Paperclip Utils contains the following methods:
|
14
14
|
```ruby
|
15
|
-
|
15
|
+
Paperclip::Utils.get_processors(content_type, processors_if_allowed, fallback_processors, allowed_content_types)
|
16
16
|
|
17
|
-
|
17
|
+
Paperclip::Utils.get_styles(content_type, styles_if_allowed, fallback_processors, allowed_content_types)
|
18
18
|
```
|
19
19
|
|
20
20
|
|
@@ -22,8 +22,8 @@ get_paperclip_styles(content_type, styles_if_allowed, fallback_processors, allow
|
|
22
22
|
```ruby
|
23
23
|
class Post < ActiveRecord::Base
|
24
24
|
has_attachment :file,
|
25
|
-
styles: lambda{|x| x.instance.
|
26
|
-
processors: lambda{|x|
|
25
|
+
styles: lambda{|x| Paperclip::Utils.get_styles(x.instance.file.content_type) },
|
26
|
+
processors: lambda{|x| Paperclip::Utils.get_processors(x.file.content_type) },
|
27
27
|
path: "public/system/:class/:attachment/:id_partition/:style/:filename",
|
28
28
|
url: "#{ActionController::Base.relative_url_root}/system/:class/:attachment/:id_partition/:style/:filename"
|
29
29
|
end
|
data/lib/paperclip_utils.rb
CHANGED
@@ -3,7 +3,7 @@ require 'paperclip_processors/ghostscript.rb'
|
|
3
3
|
|
4
4
|
module Paperclip
|
5
5
|
class Utils
|
6
|
-
def self.
|
6
|
+
def self.get_processors(content_type, to_processors=nil, fallback_processors=[], allowed_content_types=ALLOWED_CONTENT_TYPES)
|
7
7
|
if to_processors && to_processors.is_a?(Array)
|
8
8
|
processors = to_processors
|
9
9
|
end
|
@@ -17,10 +17,10 @@ module Paperclip
|
|
17
17
|
return (allowed_content_types.include?(content_type) ? processors : fallback_processors)
|
18
18
|
end
|
19
19
|
|
20
|
-
def self.
|
20
|
+
def self.get_styles(content_type, to_styles={preview: "800x600>", thumb: "100x100>"}, fallback_styles={}, allowed_content_types=ALLOWED_CONTENT_TYPES)
|
21
21
|
return (allowed_content_types.include?(content_type) ? to_styles : fallback_styles)
|
22
22
|
end
|
23
23
|
|
24
|
-
|
24
|
+
ALLOWED_CONTENT_TYPES = ['application/pdf', 'image/png', 'image/x-png', 'image/gif', 'image/jpeg', 'image/pjpeg', 'image/jpg', 'image/tif, ''image/tiff', 'image/x-tiff']
|
25
25
|
end
|
26
26
|
end
|