paperclip-cloudinary 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +64 -5
- data/lib/paperclip/cloudinary/version.rb +1 -1
- data/lib/paperclip/storage/cloudinary.rb +12 -2
- 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: 26170d304fef36a6ea287a5f1bef2559cf029c7e
|
4
|
+
data.tar.gz: 6b16e4ae21c1d61cc6f30e491ddc9e6911f6ed92
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 23d63a198657b36b713021d3e01ab6be53b7f99f192a5293d10ccdd630e9663ea9bbc08033811035431d21bce6a2615aa255f7b920947d43d08c744edd23a3cf
|
7
|
+
data.tar.gz: eb40b01ba53f7660f4671c8d9f07ce93374887c24b7d0f4331d38cbb33c115189034b7f44c867602b15a82eb836544708caeb28ed7f648ff6c4f086d74fc66d3
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
# paperclip-cloudinary
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
[![Gem
|
4
|
+
Version](https://badge.fury.io/rb/paperclip-cloudinary.svg)](https://badge.fury.io/rb/paperclip-cloudinary)
|
5
|
+
|
6
|
+
`paperclip-cloudinary` allows Rails models managed via [Paperclip](http://github.com/thoughtbot/paperclip) to store image and file assets on a Cloudinary instance.
|
5
7
|
|
6
8
|
[Cloudinary](http://cloudinary.com) is an image, file and video hosting service that allows for
|
7
9
|
dynamic, on-the-fly transformations of images with fast results. There
|
@@ -13,11 +15,12 @@ credentials, use paperclip-cloudinary to manage your attachments.
|
|
13
15
|
|
14
16
|
At this stage, not all of the API has been exposed for Cloudinary, so if
|
15
17
|
it seems you can't quite leverage all of Cloudinary's functionality yet,
|
16
|
-
that's why.
|
18
|
+
that's why. But much Cloudinary's best offerings, like dynamic image transformation,
|
19
|
+
are readily available.
|
17
20
|
|
18
|
-
Note: Cloudinary also supports CarrierWave, and will probably be more
|
21
|
+
Note: Cloudinary also supports CarrierWave and Attachinary, and will probably be more
|
19
22
|
consistently maintained going forward. But if you are distinctively
|
20
|
-
looking for a
|
23
|
+
looking for a Paperclip-based solution, this gem is for you.
|
21
24
|
|
22
25
|
## Installation
|
23
26
|
|
@@ -67,6 +70,62 @@ has_attached_file :image,
|
|
67
70
|
The `cloudinary_credentials` can be a file location, a file, or a Hash
|
68
71
|
of options.
|
69
72
|
|
73
|
+
### Upload Options
|
74
|
+
|
75
|
+
Cloudinary supports a host of [upload
|
76
|
+
options](http://cloudinary.com/documentation/image_upload_api_reference#upload)
|
77
|
+
that can be run at the time an image or file is uploaded.
|
78
|
+
|
79
|
+
This gem specifies a few of these options for you:
|
80
|
+
|
81
|
+
* `public_id`: Defines the name of this file
|
82
|
+
* `use_filename`: set to true to use the filename
|
83
|
+
* `unique_filename`: set to false
|
84
|
+
* `overwrite`: set to true to overwrite existing files with each re-upload
|
85
|
+
* `invalidate`: set to true to invalidate CDN cache with each re-upload
|
86
|
+
|
87
|
+
You can specify additional options by supplying a Hash to `:cloudinary_upload_options`
|
88
|
+
in your `has_attached_file` declaration. The following options are supported here:
|
89
|
+
|
90
|
+
* `default`: Default options applied to all styles of this upload
|
91
|
+
* `styles`: A Hash of style names to the upload options for that
|
92
|
+
particular style.
|
93
|
+
|
94
|
+
See Cloudinary documentation for list of keys and expected value options and data types.
|
95
|
+
The value can also be a `lambda` function that returns the appropriate value. The
|
96
|
+
`style_name` and Paperclip `attachment` object will be passed to your function.
|
97
|
+
|
98
|
+
```ruby
|
99
|
+
has_attached_file :image,
|
100
|
+
:storage => :cloudinary,
|
101
|
+
:styles => { :avatar => '200x200>' },
|
102
|
+
:cloudinary_upload_options => {
|
103
|
+
:default => {
|
104
|
+
:tags => [ 'Web' ],
|
105
|
+
:context => {
|
106
|
+
:caption => lambda { |style_name, attachment| attachment.instance.caption }
|
107
|
+
}
|
108
|
+
},
|
109
|
+
:styles => {
|
110
|
+
:avatar => {
|
111
|
+
:tags => [ 'Web', 'Avatar' ],
|
112
|
+
:transformation => [
|
113
|
+
{ :crop => 'thumb', :gravity => 'face' }
|
114
|
+
]
|
115
|
+
}
|
116
|
+
}
|
117
|
+
}
|
118
|
+
}
|
119
|
+
```
|
120
|
+
|
121
|
+
Here, all image versions would be uploaded with a caption taken from the model's caption parameter and
|
122
|
+
a tag "Web." For the avatar style, the tags would be overridden to be both "Web" and "Avatar," and
|
123
|
+
an [incoming transformation](http://cloudinary.com/documentation/rails_image_upload#incoming_transformations) would
|
124
|
+
be run to crop the photo to a thumbnail and gravitate the center toward the user's face using Cloudinary's
|
125
|
+
facial recognition features.
|
126
|
+
|
127
|
+
The gem-provided default options can not be overridden.
|
128
|
+
|
70
129
|
## Contributing
|
71
130
|
|
72
131
|
Bug reports and pull requests are welcome on GitHub at https://github.com/GoGoCarl/paperclip-cloudinary.
|
@@ -21,9 +21,19 @@ module Paperclip
|
|
21
21
|
public_id: public_id(style_name),
|
22
22
|
use_filename: true,
|
23
23
|
unique_filename: false,
|
24
|
-
overwrite: true
|
24
|
+
overwrite: true,
|
25
|
+
invalidate: true
|
25
26
|
}
|
26
|
-
|
27
|
+
upload_opts = @options[:cloudinary_upload_options] || {}
|
28
|
+
default_opts = upload_opts[:default] || {}
|
29
|
+
style_opts = upload_opts[:styles].try(:[], style_name) || {}
|
30
|
+
|
31
|
+
options = {}
|
32
|
+
[default_opts, style_opts].each do |opts|
|
33
|
+
options.deep_merge!(opts) do |key, existing_value, new_value|
|
34
|
+
new_value.try(:call, style_name, self) || new_value
|
35
|
+
end
|
36
|
+
end
|
27
37
|
options.merge! defaults
|
28
38
|
::Cloudinary::Uploader.upload file, options
|
29
39
|
end
|
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.1.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-04-
|
11
|
+
date: 2016-04-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cloudinary
|