paperclip 4.3.0 → 5.0.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.
Potentially problematic release.
This version of paperclip might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/.travis.yml +14 -13
- data/Appraisals +22 -9
- data/CONTRIBUTING.md +16 -5
- data/Gemfile +2 -8
- data/LICENSE +1 -1
- data/NEWS +49 -2
- data/README.md +126 -102
- data/UPGRADING +12 -9
- data/features/basic_integration.feature +1 -0
- data/features/migration.feature +0 -24
- data/features/step_definitions/attachment_steps.rb +20 -20
- data/features/step_definitions/html_steps.rb +2 -2
- data/features/step_definitions/rails_steps.rb +11 -17
- data/features/step_definitions/s3_steps.rb +2 -2
- data/features/step_definitions/web_steps.rb +1 -103
- data/features/support/file_helpers.rb +2 -2
- data/gemfiles/4.2.awsv2.0.gemfile +17 -0
- data/gemfiles/4.2.awsv2.1.gemfile +17 -0
- data/gemfiles/{4.2.gemfile → 4.2.awsv2.gemfile} +1 -1
- data/gemfiles/5.0.awsv2.0.gemfile +17 -0
- data/gemfiles/5.0.awsv2.1.gemfile +17 -0
- data/gemfiles/{4.1.gemfile → 5.0.awsv2.gemfile} +2 -2
- data/lib/paperclip/attachment.rb +18 -17
- data/lib/paperclip/attachment_registry.rb +2 -1
- data/lib/paperclip/callbacks.rb +8 -6
- data/lib/paperclip/content_type_detector.rb +3 -2
- data/lib/paperclip/errors.rb +3 -1
- data/lib/paperclip/geometry_parser_factory.rb +1 -1
- data/lib/paperclip/glue.rb +1 -1
- data/lib/paperclip/has_attached_file.rb +7 -1
- data/lib/paperclip/helpers.rb +14 -10
- data/lib/paperclip/interpolations/plural_cache.rb +6 -5
- data/lib/paperclip/interpolations.rb +18 -13
- data/lib/paperclip/io_adapters/http_url_proxy_adapter.rb +1 -1
- data/lib/paperclip/io_adapters/uri_adapter.rb +3 -1
- data/lib/paperclip/matchers/validate_attachment_content_type_matcher.rb +4 -4
- data/lib/paperclip/media_type_spoof_detector.rb +1 -1
- data/lib/paperclip/rails_environment.rb +1 -1
- data/lib/paperclip/schema.rb +3 -9
- data/lib/paperclip/storage/fog.rb +17 -8
- data/lib/paperclip/storage/s3.rb +51 -49
- data/lib/paperclip/validators/attachment_size_validator.rb +1 -7
- data/lib/paperclip/version.rb +3 -1
- data/lib/paperclip.rb +2 -1
- data/lib/tasks/paperclip.rake +1 -1
- data/paperclip.gemspec +15 -11
- data/spec/paperclip/attachment_processing_spec.rb +2 -4
- data/spec/paperclip/attachment_registry_spec.rb +28 -0
- data/spec/paperclip/attachment_spec.rb +36 -14
- data/spec/paperclip/geometry_spec.rb +1 -1
- data/spec/paperclip/glue_spec.rb +44 -0
- data/spec/paperclip/has_attached_file_spec.rb +24 -8
- data/spec/paperclip/integration_spec.rb +4 -3
- data/spec/paperclip/interpolations_spec.rb +14 -4
- data/spec/paperclip/io_adapters/http_url_proxy_adapter_spec.rb +12 -0
- data/spec/paperclip/io_adapters/uri_adapter_spec.rb +27 -0
- data/spec/paperclip/matchers/validate_attachment_content_type_matcher_spec.rb +10 -0
- data/spec/paperclip/media_type_spoof_detector_spec.rb +12 -3
- data/spec/paperclip/paperclip_spec.rb +3 -28
- data/spec/paperclip/plural_cache_spec.rb +17 -16
- data/spec/paperclip/storage/fog_spec.rb +31 -1
- data/spec/paperclip/storage/s3_live_spec.rb +8 -4
- data/spec/paperclip/storage/s3_spec.rb +213 -156
- data/spec/paperclip/validators/attachment_size_validator_spec.rb +26 -20
- data/spec/paperclip/validators_spec.rb +3 -3
- data/spec/spec_helper.rb +6 -1
- data/spec/support/assertions.rb +7 -0
- data/spec/support/model_reconstruction.rb +9 -1
- data/spec/support/reporting.rb +11 -0
- metadata +74 -47
- data/cucumber/paperclip_steps.rb +0 -6
- data/gemfiles/3.2.gemfile +0 -20
- data/lib/paperclip/locales/de.yml +0 -18
- data/lib/paperclip/locales/es.yml +0 -18
- data/lib/paperclip/locales/ja.yml +0 -18
- data/lib/paperclip/locales/pt-BR.yml +0 -18
- data/lib/paperclip/locales/zh-CN.yml +0 -18
- data/lib/paperclip/locales/zh-HK.yml +0 -18
- data/lib/paperclip/locales/zh-TW.yml +0 -18
- data/spec/support/rails_helpers.rb +0 -7
data/README.md
CHANGED
@@ -1,12 +1,27 @@
|
|
1
1
|
Paperclip
|
2
2
|
=========
|
3
3
|
|
4
|
-
|
4
|
+
## Documentation valid for `master` branch
|
5
|
+
|
6
|
+
Please check the documentation for the paperclip version you are using:
|
7
|
+
https://github.com/thoughtbot/paperclip/releases
|
8
|
+
|
9
|
+
---
|
10
|
+
|
11
|
+
[](http://travis-ci.org/thoughtbot/paperclip)
|
12
|
+
[](https://gemnasium.com/thoughtbot/paperclip)
|
13
|
+
[](https://codeclimate.com/github/thoughtbot/paperclip)
|
14
|
+
[](http://inch-ci.org/github/thoughtbot/paperclip)
|
15
|
+
[](https://hakiri.io/github/thoughtbot/paperclip/master)
|
16
|
+
|
17
|
+
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
|
18
|
+
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
|
19
|
+
|
5
20
|
|
6
21
|
- [Requirements](#requirements)
|
7
|
-
- [Ruby
|
22
|
+
- [Ruby and Rails](#ruby-and-rails)
|
8
23
|
- [Image Processor](#image-processor)
|
9
|
-
- [file](#file)
|
24
|
+
- [`file`](#file)
|
10
25
|
- [Installation](#installation)
|
11
26
|
- [Quick Start](#quick-start)
|
12
27
|
- [Models](#models)
|
@@ -14,35 +29,39 @@ Paperclip
|
|
14
29
|
- [Edit and New Views](#edit-and-new-views)
|
15
30
|
- [Edit and New Views with Simple Form](#edit-and-new-views-with-simple-form)
|
16
31
|
- [Controller](#controller)
|
17
|
-
- [
|
32
|
+
- [View Helpers](#view-helpers)
|
18
33
|
- [Deleting an Attachment](#deleting-an-attachment)
|
19
34
|
- [Usage](#usage)
|
20
35
|
- [Validations](#validations)
|
36
|
+
- [Internationalization (I18n)](#internationalization-i18n)
|
21
37
|
- [Security Validations](#security-validations)
|
22
38
|
- [Defaults](#defaults)
|
23
39
|
- [Migrations](#migrations-1)
|
24
|
-
- [Table
|
40
|
+
- [Add Attachment Column To A Table](#add-attachment-column-to-a-table)
|
25
41
|
- [Schema Definition](#schema-definition)
|
26
|
-
- [Vintage
|
42
|
+
- [Vintage syntax](#vintage-syntax)
|
27
43
|
- [Storage](#storage)
|
28
44
|
- [Understanding Storage](#understanding-storage)
|
29
45
|
- [Post Processing](#post-processing)
|
30
46
|
- [Events](#events)
|
31
47
|
- [URI Obfuscation](#uri-obfuscation)
|
32
|
-
|
33
|
-
|
48
|
+
- [MD5 Checksum / Fingerprint](#md5-checksum--fingerprint)
|
49
|
+
- [File Preservation for Soft-Delete](#file-preservation-for-soft-delete)
|
34
50
|
- [Custom Attachment Processors](#custom-attachment-processors)
|
35
51
|
- [Dynamic Configuration](#dynamic-configuration)
|
36
|
-
- [Dynamic Styles](#dynamic-styles)
|
37
|
-
- [Dynamic Processors](#dynamic-processors)
|
52
|
+
- [Dynamic Styles:](#dynamic-styles)
|
53
|
+
- [Dynamic Processors:](#dynamic-processors)
|
38
54
|
- [Logging](#logging)
|
39
55
|
- [Deployment](#deployment)
|
56
|
+
- [Attachment Styles](#attachment-styles)
|
40
57
|
- [Testing](#testing)
|
41
58
|
- [Contributing](#contributing)
|
42
59
|
- [License](#license)
|
43
60
|
- [About thoughtbot](#about-thoughtbot)
|
44
61
|
|
45
|
-
|
62
|
+
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
|
63
|
+
|
64
|
+
Paperclip is intended as an easy file attachment library for ActiveRecord. The
|
46
65
|
intent behind it was to keep setup as easy as possible and to treat files as
|
47
66
|
much like other attributes as possible. This means they aren't saved to their
|
48
67
|
final locations on disk, nor are they deleted if set to nil, until
|
@@ -54,10 +73,10 @@ packages). Attached files are saved to the filesystem and referenced in the
|
|
54
73
|
browser by an easily understandable specification, which has sensible and
|
55
74
|
useful defaults.
|
56
75
|
|
57
|
-
See the documentation for `has_attached_file` in [`Paperclip::ClassMethods`](http://rubydoc.info/gems/paperclip/Paperclip/ClassMethods) for
|
76
|
+
See the documentation for `has_attached_file` in [`Paperclip::ClassMethods`](http://www.rubydoc.info/gems/paperclip/Paperclip/ClassMethods) for
|
58
77
|
more detailed options.
|
59
78
|
|
60
|
-
The complete [RDoc](http://
|
79
|
+
The complete [RDoc](http://www.rubydoc.info/gems/paperclip) is online.
|
61
80
|
|
62
81
|
---
|
63
82
|
|
@@ -66,9 +85,8 @@ Requirements
|
|
66
85
|
|
67
86
|
### Ruby and Rails
|
68
87
|
|
69
|
-
Paperclip now requires Ruby version **>= 2.
|
70
|
-
|
71
|
-
If you're still on Ruby 1.8.7 or Ruby on Rails 2.3.x, you can still use Paperclip 2.7.x with your project. Also, everything in this README might not apply to your version of Paperclip, and you should read [the README for version 2.7](http://rubydoc.info/gems/paperclip/2.7.0) instead.
|
88
|
+
Paperclip now requires Ruby version **>= 2.1** and Rails version **>= 4.2**
|
89
|
+
(only if you're going to use Paperclip with Ruby on Rails.)
|
72
90
|
|
73
91
|
### Image Processor
|
74
92
|
|
@@ -86,7 +104,7 @@ In development mode, you might add this line to `config/environments/development
|
|
86
104
|
Paperclip.options[:command_path] = "/usr/local/bin/"
|
87
105
|
```
|
88
106
|
|
89
|
-
If you're on Mac OS X, you'll want to run the following with Homebrew:
|
107
|
+
If you're on Mac OS X, you'll want to run the following with [Homebrew] (http://www.brew.sh):
|
90
108
|
|
91
109
|
brew install imagemagick
|
92
110
|
|
@@ -95,9 +113,14 @@ to install GhostScript. On Mac OS X, you can also install that using Homebrew:
|
|
95
113
|
|
96
114
|
brew install gs
|
97
115
|
|
116
|
+
If you are on Ubuntu (or any Debian base Linux distribution), you'll want to run
|
117
|
+
the following with apt-get:
|
118
|
+
|
119
|
+
sudo apt-get install imagemagick -y
|
120
|
+
|
98
121
|
### `file`
|
99
122
|
|
100
|
-
The Unix [`file` command](
|
123
|
+
The Unix [`file` command](https://en.wikipedia.org/wiki/File_(command)) is required for content-type checking.
|
101
124
|
This utility isn't available in Windows, but comes bundled with Ruby [Devkit](https://github.com/oneclick/rubyinstaller/wiki/Development-Kit),
|
102
125
|
so Windows users must make sure that the devkit is installed and added to the system `PATH`.
|
103
126
|
|
@@ -143,24 +166,18 @@ Paperclip is distributed as a gem, which is how it should be used in your app.
|
|
143
166
|
Include the gem in your Gemfile:
|
144
167
|
|
145
168
|
```ruby
|
146
|
-
gem "paperclip", "~>
|
147
|
-
```
|
148
|
-
|
149
|
-
If you're still using Rails 2.3.x, you should do this instead:
|
150
|
-
|
151
|
-
```ruby
|
152
|
-
gem "paperclip", "~> 2.7"
|
169
|
+
gem "paperclip", "~> 5.0.0"
|
153
170
|
```
|
154
171
|
|
155
172
|
Or, if you want to get the latest, you can get master from the main paperclip repository:
|
156
173
|
|
157
174
|
```ruby
|
158
|
-
gem "paperclip", :
|
175
|
+
gem "paperclip", git: "git://github.com/thoughtbot/paperclip.git"
|
159
176
|
```
|
160
177
|
|
161
178
|
If you're trying to use features that don't seem to be in the latest released gem, but are
|
162
179
|
mentioned in this README, then you probably need to specify the master branch if you want to
|
163
|
-
use them. This README is probably ahead of the latest released version
|
180
|
+
use them. This README is probably ahead of the latest released version if you're reading it
|
164
181
|
on GitHub.
|
165
182
|
|
166
183
|
For Non-Rails usage:
|
@@ -179,22 +196,10 @@ Quick Start
|
|
179
196
|
|
180
197
|
### Models
|
181
198
|
|
182
|
-
**Rails 3**
|
183
|
-
|
184
199
|
```ruby
|
185
200
|
class User < ActiveRecord::Base
|
186
|
-
|
187
|
-
|
188
|
-
validates_attachment_content_type :avatar, :content_type => /\Aimage\/.*\Z/
|
189
|
-
end
|
190
|
-
```
|
191
|
-
|
192
|
-
**Rails 4**
|
193
|
-
|
194
|
-
```ruby
|
195
|
-
class User < ActiveRecord::Base
|
196
|
-
has_attached_file :avatar, :styles => { :medium => "300x300>", :thumb => "100x100>" }, :default_url => "/images/:style/missing.png"
|
197
|
-
validates_attachment_content_type :avatar, :content_type => /\Aimage\/.*\Z/
|
201
|
+
has_attached_file :avatar, styles: { medium: "300x300>", thumb: "100x100>" }, default_url: "/images/:style/missing.png"
|
202
|
+
validates_attachment_content_type :avatar, content_type: /\Aimage\/.*\Z/
|
198
203
|
end
|
199
204
|
```
|
200
205
|
|
@@ -217,12 +222,13 @@ end
|
|
217
222
|
### Edit and New Views
|
218
223
|
|
219
224
|
```erb
|
220
|
-
<%= form_for @user, :
|
225
|
+
<%= form_for @user, url: users_path, html: { multipart: true } do |form| %>
|
221
226
|
<%= form.file_field :avatar %>
|
222
227
|
<% end %>
|
223
228
|
```
|
224
229
|
|
225
|
-
### Edit and New Views with Simple Form
|
230
|
+
### Edit and New Views with [Simple Form](https://github.com/plataformatec/simple_form)
|
231
|
+
|
226
232
|
```erb
|
227
233
|
<%= simple_form_for @user, url: users_path do |form| %>
|
228
234
|
<%= form.input :avatar, as: :file %>
|
@@ -231,16 +237,6 @@ end
|
|
231
237
|
|
232
238
|
### Controller
|
233
239
|
|
234
|
-
**Rails 3**
|
235
|
-
|
236
|
-
```ruby
|
237
|
-
def create
|
238
|
-
@user = User.create( params[:user] )
|
239
|
-
end
|
240
|
-
```
|
241
|
-
|
242
|
-
**Rails 4**
|
243
|
-
|
244
240
|
```ruby
|
245
241
|
def create
|
246
242
|
@user = User.create( user_params )
|
@@ -256,7 +252,7 @@ def user_params
|
|
256
252
|
end
|
257
253
|
```
|
258
254
|
|
259
|
-
###
|
255
|
+
### View Helpers
|
260
256
|
|
261
257
|
```erb
|
262
258
|
<%= image_tag @user.avatar.url %>
|
@@ -294,7 +290,7 @@ You'll need to add `<attachment>_content_type` in case you want to use content t
|
|
294
290
|
validation.
|
295
291
|
|
296
292
|
More information about the options passed to `has_attached_file` is available in the
|
297
|
-
documentation of [`Paperclip::ClassMethods`](http://rubydoc.info/gems/paperclip/Paperclip/ClassMethods).
|
293
|
+
documentation of [`Paperclip::ClassMethods`](http://www.rubydoc.info/gems/paperclip/Paperclip/ClassMethods).
|
298
294
|
|
299
295
|
Validations
|
300
296
|
-----------
|
@@ -308,9 +304,9 @@ For validations, Paperclip introduces several validators to validate your attach
|
|
308
304
|
Example Usage:
|
309
305
|
|
310
306
|
```ruby
|
311
|
-
validates :avatar, :
|
312
|
-
validates_with AttachmentPresenceValidator, :
|
313
|
-
validates_with AttachmentSizeValidator, :
|
307
|
+
validates :avatar, attachment_presence: true
|
308
|
+
validates_with AttachmentPresenceValidator, attributes: :avatar
|
309
|
+
validates_with AttachmentSizeValidator, attributes: :avatar, less_than: 1.megabytes
|
314
310
|
|
315
311
|
```
|
316
312
|
|
@@ -329,9 +325,9 @@ validates_attachment_presence :avatar
|
|
329
325
|
Lastly, you can also define multiple validations on a single attachment using `validates_attachment`:
|
330
326
|
|
331
327
|
```ruby
|
332
|
-
validates_attachment :avatar, :
|
333
|
-
:
|
334
|
-
:
|
328
|
+
validates_attachment :avatar, presence: true,
|
329
|
+
content_type: { content_type: "image/jpeg" },
|
330
|
+
size: { in: 0..10.kilobytes }
|
335
331
|
```
|
336
332
|
|
337
333
|
_NOTE: Post-processing will not even **start** if the attachment is not valid
|
@@ -389,7 +385,7 @@ image-y ones:
|
|
389
385
|
|
390
386
|
```ruby
|
391
387
|
validates_attachment :avatar,
|
392
|
-
:
|
388
|
+
content_type: { content_type: ["image/jpeg", "image/gif", "image/png"] }
|
393
389
|
```
|
394
390
|
|
395
391
|
`Paperclip::ContentTypeDetector` will attempt to match a file's extension to an
|
@@ -397,6 +393,12 @@ inferred content_type, regardless of the actual contents of the file.
|
|
397
393
|
|
398
394
|
---
|
399
395
|
|
396
|
+
Internationalization (I18n)
|
397
|
+
---------------------------
|
398
|
+
|
399
|
+
For using or adding locale files in different languages, check the project
|
400
|
+
https://github.com/thoughtbot/paperclip-i18n.
|
401
|
+
|
400
402
|
Security Validations
|
401
403
|
====================
|
402
404
|
|
@@ -413,9 +415,9 @@ do this.
|
|
413
415
|
class ActiveRecord::Base
|
414
416
|
has_attached_file :avatar
|
415
417
|
# Validate content type
|
416
|
-
validates_attachment_content_type :avatar, :
|
418
|
+
validates_attachment_content_type :avatar, content_type: /\Aimage/
|
417
419
|
# Validate filename
|
418
|
-
validates_attachment_file_name :avatar, :
|
420
|
+
validates_attachment_file_name :avatar, matches: [/png\Z/, /jpe?g\Z/]
|
419
421
|
# Explicitly do not validate
|
420
422
|
do_not_validate_attachment_file_type :avatar
|
421
423
|
end
|
@@ -435,14 +437,13 @@ will not cause errors to be raised.
|
|
435
437
|
|
436
438
|
This can sometimes cause false validation errors in applications that use custom
|
437
439
|
file extensions. In these cases you may wish to add your custom extension to the
|
438
|
-
list of
|
439
|
-
gem:
|
440
|
+
list of content type mappings by creating `config/initializers/paperclip.rb`:
|
440
441
|
|
441
442
|
```ruby
|
442
443
|
# Allow ".foo" as an extension for files with the MIME type "text/plain".
|
443
|
-
|
444
|
-
|
445
|
-
|
444
|
+
Paperclip.options[:content_type_mappings] = {
|
445
|
+
foo: %w(text/plain)
|
446
|
+
}
|
446
447
|
```
|
447
448
|
|
448
449
|
---
|
@@ -458,7 +459,7 @@ module YourApp
|
|
458
459
|
class Application < Rails::Application
|
459
460
|
# Other code...
|
460
461
|
|
461
|
-
config.paperclip_defaults = {:
|
462
|
+
config.paperclip_defaults = { storage: :fog, fog_credentials: { provider: "Local", local_root: "#{Rails.root}/public"}, fog_directory: "", fog_host: "localhost"}
|
462
463
|
end
|
463
464
|
end
|
464
465
|
```
|
@@ -469,7 +470,7 @@ An example Rails initializer would look something like this:
|
|
469
470
|
|
470
471
|
```ruby
|
471
472
|
Paperclip::Attachment.default_options[:storage] = :fog
|
472
|
-
Paperclip::Attachment.default_options[:fog_credentials] = {:
|
473
|
+
Paperclip::Attachment.default_options[:fog_credentials] = { provider: "Local", local_root: "#{Rails.root}/public"}
|
473
474
|
Paperclip::Attachment.default_options[:fog_directory] = ""
|
474
475
|
Paperclip::Attachment.default_options[:fog_host] = "http://localhost:3000"
|
475
476
|
```
|
@@ -491,6 +492,7 @@ class CreateUsersWithAttachments < ActiveRecord::Migration
|
|
491
492
|
create_table :users do |t|
|
492
493
|
t.attachment :avatar
|
493
494
|
end
|
495
|
+
end
|
494
496
|
|
495
497
|
# This is assuming you are only using the users table for Paperclip attachment. Drop with care!
|
496
498
|
def down
|
@@ -564,9 +566,9 @@ gems along side with Paperclip:
|
|
564
566
|
The files that are assigned as attachments are, by default, placed in the
|
565
567
|
directory specified by the `:path` option to `has_attached_file`. By default, this
|
566
568
|
location is `:rails_root/public/system/:class/:attachment/:id_partition/:style/:filename`.
|
567
|
-
This location was chosen because on standard Capistrano deployments, the
|
568
|
-
`public/system` directory
|
569
|
-
|
569
|
+
This location was chosen because, on standard Capistrano deployments, the
|
570
|
+
`public/system` directory can be symlinked to the app's shared directory, meaning it
|
571
|
+
survives between deployments. For example, using that `:path`, you may have a
|
570
572
|
file at
|
571
573
|
|
572
574
|
/data/myapp/releases/20081229172410/public/system/users/avatar/000/000/013/small/my_pic.png
|
@@ -578,12 +580,12 @@ You may also choose to store your files using Amazon's S3 service. To do so, inc
|
|
578
580
|
the `aws-sdk` gem in your Gemfile:
|
579
581
|
|
580
582
|
```ruby
|
581
|
-
gem 'aws-sdk', '
|
583
|
+
gem 'aws-sdk', '>= 2.0.34'
|
582
584
|
```
|
583
585
|
|
584
586
|
And then you can specify using S3 from `has_attached_file`.
|
585
587
|
You can find more information about configuring and using S3 storage in
|
586
|
-
[the `Paperclip::Storage::S3` documentation](http://rubydoc.info/gems/paperclip/Paperclip/Storage/S3).
|
588
|
+
[the `Paperclip::Storage::S3` documentation](http://www.rubydoc.info/gems/paperclip/Paperclip/Storage/S3).
|
587
589
|
|
588
590
|
Files on the local filesystem (and in the Rails app's public directory) will be
|
589
591
|
available to the internet at large. If you require access control, it's
|
@@ -608,20 +610,21 @@ processors. You can specify a processor with the `:processors` option to
|
|
608
610
|
`has_attached_file`:
|
609
611
|
|
610
612
|
```ruby
|
611
|
-
has_attached_file :scan, :
|
612
|
-
:
|
613
|
+
has_attached_file :scan, styles: { text: { quality: :better } },
|
614
|
+
processors: [:ocr]
|
613
615
|
```
|
614
616
|
|
615
617
|
This would load the hypothetical class Paperclip::Ocr, which would have the
|
616
|
-
hash "{ :
|
617
|
-
more information about defining processors, see
|
618
|
+
hash "{ quality: :better }" passed to it along with the uploaded file. For
|
619
|
+
more information about defining processors, see
|
620
|
+
[Paperclip::Processor](https://github.com/thoughtbot/paperclip/blob/master/lib/paperclip/processor.rb).
|
618
621
|
|
619
|
-
The default processor is Paperclip::Thumbnail. For
|
622
|
+
The default processor is Paperclip::Thumbnail. For backward compatibility
|
620
623
|
reasons, you can pass a single geometry string or an array containing a
|
621
624
|
geometry and a format that the file will be converted to, like so:
|
622
625
|
|
623
626
|
```ruby
|
624
|
-
has_attached_file :avatar, :
|
627
|
+
has_attached_file :avatar, styles: { thumb: ["32x32#", :png] }
|
625
628
|
```
|
626
629
|
|
627
630
|
This will convert the "thumb" style to a 32x32 square in PNG format, regardless
|
@@ -636,12 +639,12 @@ receive the same parameters, which are defined in the `:styles` hash.
|
|
636
639
|
For example, assuming we had this definition:
|
637
640
|
|
638
641
|
```ruby
|
639
|
-
has_attached_file :scan, :
|
640
|
-
:
|
642
|
+
has_attached_file :scan, styles: { text: { quality: :better } },
|
643
|
+
processors: [:rotator, :ocr]
|
641
644
|
```
|
642
645
|
|
643
646
|
then both the :rotator processor and the :ocr processor would receive the
|
644
|
-
options `{ :
|
647
|
+
options `{ quality: :better }`. This parameter may not mean anything to one
|
645
648
|
or more or the processors, and they are expected to ignore it.
|
646
649
|
|
647
650
|
_NOTE: Because processors operate by turning the original attachment into the
|
@@ -697,8 +700,8 @@ Example Usage:
|
|
697
700
|
|
698
701
|
```ruby
|
699
702
|
has_attached_file :avatar, {
|
700
|
-
:
|
701
|
-
:
|
703
|
+
url: "/system/:hash.:extension",
|
704
|
+
hash_secret: "longSecretString"
|
702
705
|
}
|
703
706
|
```
|
704
707
|
|
@@ -736,7 +739,7 @@ An option is available to preserve attachments in order to play nicely with soft
|
|
736
739
|
|
737
740
|
```ruby
|
738
741
|
has_attached_file :some_attachment, {
|
739
|
-
:
|
742
|
+
preserve_files: "true",
|
740
743
|
}
|
741
744
|
```
|
742
745
|
|
@@ -784,7 +787,7 @@ look as follows where a boss will receive a `300x300` thumbnail otherwise a
|
|
784
787
|
|
785
788
|
```ruby
|
786
789
|
class User < ActiveRecord::Base
|
787
|
-
has_attached_file :avatar, :
|
790
|
+
has_attached_file :avatar, styles: lambda { |attachment| { thumb: (attachment.instance.boss? ? "300x300>" : "100x100>") } }
|
788
791
|
end
|
789
792
|
```
|
790
793
|
|
@@ -801,7 +804,7 @@ processors, where a defined `watermark` processor is invoked after the
|
|
801
804
|
|
802
805
|
```ruby
|
803
806
|
class User < ActiveRecord::Base
|
804
|
-
has_attached_file :avatar, :
|
807
|
+
has_attached_file :avatar, processors: lambda { |instance| instance.processors }
|
805
808
|
attr_accessor :processors
|
806
809
|
end
|
807
810
|
```
|
@@ -811,7 +814,7 @@ end
|
|
811
814
|
Logging
|
812
815
|
----------
|
813
816
|
|
814
|
-
By default Paperclip outputs logging according to your logger level. If you want to disable logging (e.g. during testing) add this
|
817
|
+
By default, Paperclip outputs logging according to your logger level. If you want to disable logging (e.g. during testing) add this into your environment's configuration:
|
815
818
|
```ruby
|
816
819
|
Your::Application.configure do
|
817
820
|
...
|
@@ -820,13 +823,23 @@ Your::Application.configure do
|
|
820
823
|
end
|
821
824
|
```
|
822
825
|
|
823
|
-
More information in the [rdocs](http://
|
826
|
+
More information in the [rdocs](http://www.rubydoc.info/github/thoughtbot/paperclip/Paperclip.options)
|
824
827
|
|
825
828
|
---
|
826
829
|
|
827
830
|
Deployment
|
828
831
|
----------
|
829
832
|
|
833
|
+
To make Capistrano symlink the `public/system` directory so that attachments
|
834
|
+
survive new deployments, set the `linked_dirs` option in your `config/deploy.rb`
|
835
|
+
file:
|
836
|
+
|
837
|
+
```ruby
|
838
|
+
set :linked_dirs, fetch(:linked_dirs, []).push('public/system')
|
839
|
+
```
|
840
|
+
|
841
|
+
### Attachment Styles
|
842
|
+
|
830
843
|
Paperclip is aware of new attachment styles you have added in previous deploys. The only thing you should do after each deployment is to call
|
831
844
|
`rake paperclip:refresh:missing_styles`. It will store current attachment styles in `RAILS_ROOT/public/system/paperclip_attachments.yml`
|
832
845
|
by default. You can change it by:
|
@@ -838,9 +851,9 @@ Paperclip.registered_attachments_styles_path = '/tmp/config/paperclip_attachment
|
|
838
851
|
Here is an example for Capistrano:
|
839
852
|
|
840
853
|
```ruby
|
841
|
-
namespace :
|
854
|
+
namespace :paperclip do
|
842
855
|
desc "build missing paperclip styles"
|
843
|
-
task :
|
856
|
+
task :build_missing_styles do
|
844
857
|
on roles(:app) do
|
845
858
|
within release_path do
|
846
859
|
with rails_env: fetch(:rails_env) do
|
@@ -851,7 +864,7 @@ namespace :deploy do
|
|
851
864
|
end
|
852
865
|
end
|
853
866
|
|
854
|
-
after("deploy:compile_assets", "
|
867
|
+
after("deploy:compile_assets", "paperclip:build_missing_styles")
|
855
868
|
```
|
856
869
|
|
857
870
|
Now you don't have to remember to refresh thumbnails in production every time you add a new style.
|
@@ -862,12 +875,12 @@ Paperclip about existing styles. Simply create a `paperclip_attachments.yml` fil
|
|
862
875
|
|
863
876
|
```ruby
|
864
877
|
class User < ActiveRecord::Base
|
865
|
-
has_attached_file :avatar, :
|
878
|
+
has_attached_file :avatar, styles: { thumb: 'x100', croppable: '600x600>', big: '1000x1000>' }
|
866
879
|
end
|
867
880
|
|
868
881
|
class Book < ActiveRecord::Base
|
869
|
-
has_attached_file :cover, :
|
870
|
-
has_attached_file :sample, :
|
882
|
+
has_attached_file :cover, styles: { small: 'x100', large: '1000x1000>' }
|
883
|
+
has_attached_file :sample, styles: { thumb: 'x100' }
|
871
884
|
end
|
872
885
|
```
|
873
886
|
|
@@ -894,7 +907,7 @@ Testing
|
|
894
907
|
-------
|
895
908
|
|
896
909
|
Paperclip provides rspec-compatible matchers for testing attachments. See the
|
897
|
-
documentation on [Paperclip::Shoulda::Matchers](http://rubydoc.info/gems/paperclip/Paperclip/Shoulda/Matchers)
|
910
|
+
documentation on [Paperclip::Shoulda::Matchers](http://www.rubydoc.info/gems/paperclip/Paperclip/Shoulda/Matchers)
|
898
911
|
for more information.
|
899
912
|
|
900
913
|
**Parallel Tests**
|
@@ -934,6 +947,17 @@ config.after(:suite) do
|
|
934
947
|
FileUtils.rm_rf(Dir["#{Rails.root}/spec/test_files/"])
|
935
948
|
end
|
936
949
|
```
|
950
|
+
|
951
|
+
**Example of test configuration with Factory Girl**
|
952
|
+
|
953
|
+
|
954
|
+
```ruby
|
955
|
+
FactoryGirl.define do
|
956
|
+
factory :user do
|
957
|
+
avatar { File.new("#{Rails.root}/spec/support/fixtures/image.jpg") }
|
958
|
+
end
|
959
|
+
end
|
960
|
+
```
|
937
961
|
---
|
938
962
|
|
939
963
|
Contributing
|
@@ -949,14 +973,14 @@ guidelines:
|
|
949
973
|
about writing tests for paperclip, please open a
|
950
974
|
[GitHub issue](https://github.com/thoughtbot/paperclip/issues/new).
|
951
975
|
|
952
|
-
Please see `CONTRIBUTING.md` for more details on contributing and running test.
|
976
|
+
Please see [`CONTRIBUTING.md`](./CONTRIBUTING.md) for more details on contributing and running test.
|
953
977
|
|
954
|
-
Thank you to all [the contributors](https://github.com/thoughtbot/paperclip/contributors)!
|
978
|
+
Thank you to all [the contributors](https://github.com/thoughtbot/paperclip/graphs/contributors)!
|
955
979
|
|
956
980
|
License
|
957
981
|
-------
|
958
982
|
|
959
|
-
Paperclip is Copyright © 2008-
|
983
|
+
Paperclip is Copyright © 2008-2016 thoughtbot, inc. It is free software, and may be
|
960
984
|
redistributed under the terms specified in the MIT-LICENSE file.
|
961
985
|
|
962
986
|
About thoughtbot
|
data/UPGRADING
CHANGED
@@ -1,14 +1,17 @@
|
|
1
1
|
##################################################
|
2
|
-
# NOTE FOR UPGRADING FROM
|
2
|
+
# NOTE FOR UPGRADING FROM 4.3.0 OR EARLIER #
|
3
3
|
##################################################
|
4
4
|
|
5
|
-
Paperclip
|
6
|
-
path. This will help to prevent attachment name clashes when you have
|
7
|
-
multiple attachments with the same name. If you didn't alter your
|
8
|
-
attachment's path and are using Paperclip's default, you'll have to add
|
9
|
-
`:path` and `:url` to your `has_attached_file` definition. For example:
|
5
|
+
Paperclip is now compatible with aws-sdk >= 2.0.0.
|
10
6
|
|
11
|
-
|
12
|
-
|
13
|
-
:url => "/system/:attachment/:id/:style/:filename"
|
7
|
+
If you are using S3 storage, aws-sdk >= 2.0.0 requires you to make a few small
|
8
|
+
changes:
|
14
9
|
|
10
|
+
* You must set the `s3_region`
|
11
|
+
* If you are explicitly setting permissions anywhere, such as in an initializer,
|
12
|
+
note that the format of the permissions changed from using an underscore to
|
13
|
+
using a hyphen. For example, `:public_read` needs to be changed to
|
14
|
+
`public-read`.
|
15
|
+
|
16
|
+
For a walkthrough of upgrading from 4 to 5 and aws-sdk >= 2.0 you can watch
|
17
|
+
http://rubythursday.com/episodes/ruby-snack-27-upgrade-paperclip-and-aws-sdk-in-prep-for-rails-5
|
data/features/migration.feature
CHANGED
@@ -68,27 +68,3 @@ Feature: Migration
|
|
68
68
|
|
69
69
|
When I rollback a migration
|
70
70
|
Then I should not have attachment columns for "avatar"
|
71
|
-
|
72
|
-
Scenario: Rails 3.2 change method
|
73
|
-
Given I am using Rails newer than 3.1
|
74
|
-
When I write to "db/migrate/01_create_users.rb" with:
|
75
|
-
"""
|
76
|
-
class CreateUsers < ActiveRecord::Migration
|
77
|
-
def self.up
|
78
|
-
create_table :users
|
79
|
-
end
|
80
|
-
end
|
81
|
-
"""
|
82
|
-
When I write to "db/migrate/02_add_attachment_to_users.rb" with:
|
83
|
-
"""
|
84
|
-
class AddAttachmentToUsers < ActiveRecord::Migration
|
85
|
-
def change
|
86
|
-
add_attachment :users, :avatar
|
87
|
-
end
|
88
|
-
end
|
89
|
-
"""
|
90
|
-
And I run a migration
|
91
|
-
Then I should have attachment columns for "avatar"
|
92
|
-
|
93
|
-
When I rollback a migration
|
94
|
-
Then I should not have attachment columns for "avatar"
|