paperclip-cloudinary 1.2.0 → 1.3.0
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/Gemfile.lock +1 -1
- data/README.md +29 -3
- data/lib/paperclip/cloudinary/version.rb +1 -1
- data/lib/paperclip/storage/cloudinary.rb +29 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1777407449495c90962cd0540d3e9dc826a4fb03
|
4
|
+
data.tar.gz: ecb3b29dee07e50ea59d7e799c68d9444e553e96
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e918d3aadcd2aacc8ba207951b4b9463fde67c749b7a262077e86a957b9f1070c367e500509129124304a431d85b6573a7412528f7df0149587cc18dca39795f
|
7
|
+
data.tar.gz: 815561dcf263b692bdded9a65f80932247b0754d663a909d35248cd7aa1dd84bb677d67eb1d18d285d7b540ee07696d73be7d96baa7f1d80244c8632298b5528
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -70,6 +70,28 @@ has_attached_file :image,
|
|
70
70
|
The `cloudinary_credentials` can be a file location, a file, or a Hash
|
71
71
|
of options.
|
72
72
|
|
73
|
+
### Resource Types
|
74
|
+
|
75
|
+
Cloudinary supports a number of resource types for your attachments, including:
|
76
|
+
|
77
|
+
* image
|
78
|
+
* audio
|
79
|
+
* video
|
80
|
+
* raw
|
81
|
+
|
82
|
+
By default, this gem assumes that your resource type is an image, but if
|
83
|
+
you are uploading other resources, such as videos, you can specify the
|
84
|
+
resource type in your configuration:
|
85
|
+
|
86
|
+
```ruby
|
87
|
+
has_attached_file :video,
|
88
|
+
:storage => :cloudinary,
|
89
|
+
:cloudinary_resource_type => :video
|
90
|
+
```
|
91
|
+
|
92
|
+
Cloudinary has recently introduced auto-detection features that may soon
|
93
|
+
be integrated with this gem to make this step optional.
|
94
|
+
|
73
95
|
### Upload Options
|
74
96
|
|
75
97
|
Cloudinary supports a host of [upload
|
@@ -144,7 +166,8 @@ has_attached_file :image
|
|
144
166
|
},
|
145
167
|
:styles => {
|
146
168
|
:avatar => {
|
147
|
-
:
|
169
|
+
:quality => 75,
|
170
|
+
:transformation => [ { :angle => 20 } ]
|
148
171
|
}
|
149
172
|
}
|
150
173
|
}
|
@@ -155,9 +178,12 @@ for all calls, then the style-specific ones, if applicable.
|
|
155
178
|
|
156
179
|
#### In-line Configuration
|
157
180
|
|
181
|
+
The same URL options provided for the avatar above can also be expressed as
|
182
|
+
in-line configuration options:
|
183
|
+
|
158
184
|
```ruby
|
159
|
-
model.image.url(:avatar, :cloudinary => { :secure => true,
|
160
|
-
:
|
185
|
+
model.image.url(:avatar, :cloudinary => { :secure => true, :quality =>
|
186
|
+
75, :transformation => [ { :angle => 20 } ] })
|
161
187
|
```
|
162
188
|
|
163
189
|
These can be use in addition to the URL options provided in the
|
@@ -19,6 +19,7 @@ module Paperclip
|
|
19
19
|
@queued_for_write.each do |style_name, file|
|
20
20
|
defaults = {
|
21
21
|
public_id: public_id(style_name),
|
22
|
+
resource_type: resource_type,
|
22
23
|
use_filename: true,
|
23
24
|
unique_filename: false,
|
24
25
|
overwrite: true,
|
@@ -45,7 +46,11 @@ module Paperclip
|
|
45
46
|
|
46
47
|
def flush_deletes
|
47
48
|
@queued_for_delete.each do |path|
|
48
|
-
|
49
|
+
defaults = {
|
50
|
+
resource_type: resource_type,
|
51
|
+
invalidate: true
|
52
|
+
}
|
53
|
+
::Cloudinary::Uploader.destroy public_id_for_path(path), defaults
|
49
54
|
end
|
50
55
|
|
51
56
|
@queued_for_delete.clear
|
@@ -53,12 +58,12 @@ module Paperclip
|
|
53
58
|
|
54
59
|
def copy_to_local_file style, local_dest_path
|
55
60
|
File.open(local_dest_path, 'wb') do |file|
|
56
|
-
file.write ::Cloudinary::Downloader.download(
|
61
|
+
file.write ::Cloudinary::Downloader.download(url(style))
|
57
62
|
end
|
58
63
|
end
|
59
64
|
|
60
65
|
def exists? style = default_style
|
61
|
-
::Cloudinary::Uploader.exists?
|
66
|
+
::Cloudinary::Uploader.exists? public_id(style), cloudinary_url_options(style)
|
62
67
|
end
|
63
68
|
|
64
69
|
def url style_or_options = default_style, options = {}
|
@@ -73,10 +78,18 @@ module Paperclip
|
|
73
78
|
end
|
74
79
|
|
75
80
|
def public_id style
|
76
|
-
|
81
|
+
public_id_for_path(path style)
|
82
|
+
end
|
83
|
+
|
84
|
+
def public_id_for_path s
|
77
85
|
s[0..-(File.extname(s).length + 1)]
|
78
86
|
end
|
79
87
|
|
88
|
+
def resource_type
|
89
|
+
type = @options[:cloudinary_resource_type] || 'image'
|
90
|
+
%w{image raw video audio}.include?(type.to_s) ? type.to_s : 'image'
|
91
|
+
end
|
92
|
+
|
80
93
|
def cloud_name
|
81
94
|
cloudinary_credentials[:cloud_name]
|
82
95
|
end
|
@@ -90,7 +103,7 @@ module Paperclip
|
|
90
103
|
end
|
91
104
|
|
92
105
|
def cloudinary_credentials
|
93
|
-
@cloudinary_credentials ||= parse_credentials(@options[:cloudinary_credentials] ||
|
106
|
+
@cloudinary_credentials ||= parse_credentials(@options[:cloudinary_credentials] || find_default_config_path)
|
94
107
|
@cloudinary_credentials
|
95
108
|
end
|
96
109
|
|
@@ -108,6 +121,8 @@ module Paperclip
|
|
108
121
|
default_opts = url_opts[:default] || {}
|
109
122
|
style_opts = url_opts[:styles].try(:[], style_name) || {}
|
110
123
|
|
124
|
+
default_opts[:resource_type] = resource_type
|
125
|
+
|
111
126
|
options = {}
|
112
127
|
[default_opts, style_opts, inline_opts].each do |opts|
|
113
128
|
options.deep_merge!(opts) do |key, existing_value, new_value|
|
@@ -118,6 +133,15 @@ module Paperclip
|
|
118
133
|
options
|
119
134
|
end
|
120
135
|
|
136
|
+
def find_default_config_path
|
137
|
+
config_path = Rails.root.join("config/cloudinary.yml")
|
138
|
+
if File.exist? config_path
|
139
|
+
return config_path
|
140
|
+
else
|
141
|
+
return Rails.root.join("config/cloudinary.yaml")
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
121
145
|
def find_credentials creds
|
122
146
|
case creds
|
123
147
|
when File
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: paperclip-cloudinary
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Carl Scott
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-07-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cloudinary
|