paperclip 5.0.0.beta2 → 5.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.codeclimate.yml +17 -0
- data/.hound.yml +5 -16
- data/.travis.yml +14 -15
- data/Appraisals +3 -23
- data/CONTRIBUTING.md +10 -4
- data/Gemfile +1 -0
- data/NEWS +78 -2
- data/README.md +175 -81
- data/Rakefile +1 -1
- data/UPGRADING +1 -1
- data/features/basic_integration.feature +2 -2
- data/features/step_definitions/attachment_steps.rb +6 -6
- data/features/step_definitions/rails_steps.rb +29 -22
- data/features/step_definitions/s3_steps.rb +1 -1
- data/features/support/env.rb +1 -0
- data/features/support/paths.rb +1 -1
- data/features/support/rails.rb +0 -24
- data/gemfiles/{4.2.awsv2.0.gemfile → 4.2.gemfile} +1 -1
- data/gemfiles/{5.0.awsv2.1.gemfile → 5.0.gemfile} +2 -2
- data/lib/generators/paperclip/paperclip_generator.rb +9 -1
- data/lib/generators/paperclip/templates/paperclip_migration.rb.erb +1 -1
- data/lib/paperclip.rb +13 -10
- data/lib/paperclip/attachment.rb +16 -6
- data/lib/paperclip/content_type_detector.rb +3 -2
- data/lib/paperclip/errors.rb +3 -1
- data/lib/paperclip/file_command_content_type_detector.rb +1 -1
- data/lib/paperclip/geometry_detector_factory.rb +2 -2
- data/lib/paperclip/helpers.rb +15 -12
- data/lib/paperclip/interpolations.rb +1 -1
- data/lib/paperclip/io_adapters/abstract_adapter.rb +29 -3
- data/lib/paperclip/io_adapters/attachment_adapter.rb +10 -5
- data/lib/paperclip/io_adapters/data_uri_adapter.rb +8 -8
- data/lib/paperclip/io_adapters/empty_string_adapter.rb +5 -4
- data/lib/paperclip/io_adapters/file_adapter.rb +12 -6
- data/lib/paperclip/io_adapters/http_url_proxy_adapter.rb +7 -7
- data/lib/paperclip/io_adapters/identity_adapter.rb +12 -6
- data/lib/paperclip/io_adapters/nil_adapter.rb +8 -5
- data/lib/paperclip/io_adapters/registry.rb +6 -2
- data/lib/paperclip/io_adapters/stringio_adapter.rb +9 -6
- data/lib/paperclip/io_adapters/uploaded_file_adapter.rb +10 -6
- data/lib/paperclip/io_adapters/uri_adapter.rb +41 -19
- data/lib/paperclip/matchers/validate_attachment_content_type_matcher.rb +4 -4
- data/lib/paperclip/media_type_spoof_detector.rb +3 -2
- data/lib/paperclip/processor.rb +5 -4
- data/lib/paperclip/storage/filesystem.rb +13 -2
- data/lib/paperclip/storage/fog.rb +12 -7
- data/lib/paperclip/storage/s3.rb +46 -19
- data/lib/paperclip/thumbnail.rb +18 -8
- data/lib/paperclip/url_generator.rb +17 -13
- data/lib/paperclip/validators.rb +1 -1
- data/lib/paperclip/version.rb +3 -1
- data/lib/tasks/paperclip.rake +18 -4
- data/paperclip.gemspec +4 -5
- data/spec/paperclip/attachment_processing_spec.rb +2 -4
- data/spec/paperclip/attachment_spec.rb +40 -9
- data/spec/paperclip/content_type_detector_spec.rb +1 -1
- data/spec/paperclip/file_command_content_type_detector_spec.rb +15 -1
- data/spec/paperclip/io_adapters/abstract_adapter_spec.rb +76 -22
- data/spec/paperclip/io_adapters/attachment_adapter_spec.rb +6 -3
- data/spec/paperclip/io_adapters/data_uri_adapter_spec.rb +7 -1
- data/spec/paperclip/io_adapters/file_adapter_spec.rb +2 -2
- data/spec/paperclip/io_adapters/http_url_proxy_adapter_spec.rb +26 -6
- data/spec/paperclip/io_adapters/identity_adapter_spec.rb +1 -1
- data/spec/paperclip/io_adapters/registry_spec.rb +2 -2
- data/spec/paperclip/io_adapters/stringio_adapter_spec.rb +1 -1
- data/spec/paperclip/io_adapters/uploaded_file_adapter_spec.rb +5 -5
- data/spec/paperclip/io_adapters/uri_adapter_spec.rb +77 -7
- data/spec/paperclip/matchers/validate_attachment_content_type_matcher_spec.rb +10 -0
- data/spec/paperclip/media_type_spoof_detector_spec.rb +27 -3
- data/spec/paperclip/paperclip_spec.rb +13 -13
- data/spec/paperclip/processor_spec.rb +4 -4
- data/spec/paperclip/storage/fog_spec.rb +28 -0
- data/spec/paperclip/storage/s3_live_spec.rb +12 -10
- data/spec/paperclip/storage/s3_spec.rb +150 -39
- data/spec/paperclip/tempfile_spec.rb +35 -0
- data/spec/paperclip/thumbnail_spec.rb +38 -35
- data/spec/paperclip/url_generator_spec.rb +54 -43
- data/spec/paperclip/validators_spec.rb +3 -2
- data/spec/spec_helper.rb +3 -1
- data/spec/support/assertions.rb +5 -1
- data/spec/support/conditional_filter_helper.rb +5 -0
- data/spec/support/mock_attachment.rb +2 -0
- data/spec/support/mock_url_generator_builder.rb +2 -2
- metadata +37 -36
- data/gemfiles/4.2.awsv2.1.gemfile +0 -17
- data/gemfiles/4.2.awsv2.gemfile +0 -20
- data/gemfiles/5.0.awsv2.0.gemfile +0 -17
- data/gemfiles/5.0.awsv2.gemfile +0 -25
@@ -40,9 +40,9 @@ module Paperclip
|
|
40
40
|
|
41
41
|
def failure_message
|
42
42
|
"#{expected_attachment}\n".tap do |message|
|
43
|
-
message << accepted_types_and_failures
|
43
|
+
message << accepted_types_and_failures.to_s
|
44
44
|
message << "\n\n" if @allowed_types.present? && @rejected_types.present?
|
45
|
-
message << rejected_types_and_failures
|
45
|
+
message << rejected_types_and_failures.to_s
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
@@ -55,7 +55,7 @@ module Paperclip
|
|
55
55
|
def accepted_types_and_failures
|
56
56
|
if @allowed_types.present?
|
57
57
|
"Accept content types: #{@allowed_types.join(", ")}\n".tap do |message|
|
58
|
-
if @missing_allowed_types.
|
58
|
+
if @missing_allowed_types.present?
|
59
59
|
message << " #{@missing_allowed_types.join(", ")} were rejected."
|
60
60
|
else
|
61
61
|
message << " All were accepted successfully."
|
@@ -66,7 +66,7 @@ module Paperclip
|
|
66
66
|
def rejected_types_and_failures
|
67
67
|
if @rejected_types.present?
|
68
68
|
"Reject content types: #{@rejected_types.join(", ")}\n".tap do |message|
|
69
|
-
if @missing_rejected_types.
|
69
|
+
if @missing_rejected_types.present?
|
70
70
|
message << " #{@missing_rejected_types.join(", ")} were accepted."
|
71
71
|
else
|
72
72
|
message << " All were rejected successfully."
|
@@ -72,8 +72,9 @@ module Paperclip
|
|
72
72
|
|
73
73
|
def type_from_file_command
|
74
74
|
begin
|
75
|
-
Paperclip.run("file", "-b --mime :file", :
|
76
|
-
|
75
|
+
Paperclip.run("file", "-b --mime :file", file: @file.path).
|
76
|
+
split(/[:;\s]+/).first
|
77
|
+
rescue Terrapin::CommandLineError
|
77
78
|
""
|
78
79
|
end
|
79
80
|
end
|
data/lib/paperclip/processor.rb
CHANGED
@@ -7,13 +7,14 @@ module Paperclip
|
|
7
7
|
# Processors are required to be defined inside the Paperclip module and
|
8
8
|
# are also required to be a subclass of Paperclip::Processor. There is
|
9
9
|
# only one method you *must* implement to properly be a subclass:
|
10
|
-
# #make, but #initialize may also be of use.
|
10
|
+
# #make, but #initialize may also be of use. #initialize accepts 3
|
11
11
|
# arguments: the file that will be operated on (which is an instance of
|
12
12
|
# File), a hash of options that were defined in has_attached_file's
|
13
|
-
# style hash, and the Paperclip::Attachment itself.
|
13
|
+
# style hash, and the Paperclip::Attachment itself. These are set as
|
14
|
+
# instance variables that can be used within `#make`.
|
14
15
|
#
|
15
|
-
#
|
16
|
-
#
|
16
|
+
# #make must return an instance of File (Tempfile is acceptable) which
|
17
|
+
# contains the results of the processing.
|
17
18
|
#
|
18
19
|
# See Paperclip.run for more information about using command-line
|
19
20
|
# utilities from within Processors.
|
@@ -37,7 +37,7 @@ module Paperclip
|
|
37
37
|
@queued_for_write.each do |style_name, file|
|
38
38
|
FileUtils.mkdir_p(File.dirname(path(style_name)))
|
39
39
|
begin
|
40
|
-
|
40
|
+
move_file(file.path, path(style_name))
|
41
41
|
rescue SystemCallError
|
42
42
|
File.open(path(style_name), "wb") do |new_file|
|
43
43
|
while chunk = file.read(16 * 1024)
|
@@ -46,7 +46,7 @@ module Paperclip
|
|
46
46
|
end
|
47
47
|
end
|
48
48
|
unless @options[:override_file_permissions] == false
|
49
|
-
resolved_chmod = (@options[:override_file_permissions]
|
49
|
+
resolved_chmod = (@options[:override_file_permissions] & ~0111) || (0666 & ~File.umask)
|
50
50
|
FileUtils.chmod( resolved_chmod, path(style_name) )
|
51
51
|
end
|
52
52
|
file.rewind
|
@@ -84,6 +84,17 @@ module Paperclip
|
|
84
84
|
def copy_to_local_file(style, local_dest_path)
|
85
85
|
FileUtils.cp(path(style), local_dest_path)
|
86
86
|
end
|
87
|
+
|
88
|
+
private
|
89
|
+
|
90
|
+
def move_file(src, dest)
|
91
|
+
# Support hardlinked files
|
92
|
+
if File.identical?(src, dest)
|
93
|
+
File.unlink(src)
|
94
|
+
else
|
95
|
+
FileUtils.mv(src, dest)
|
96
|
+
end
|
97
|
+
end
|
87
98
|
end
|
88
99
|
|
89
100
|
end
|
@@ -48,7 +48,7 @@ module Paperclip
|
|
48
48
|
end unless defined?(Fog)
|
49
49
|
|
50
50
|
base.instance_eval do
|
51
|
-
unless @options[:url].to_s.match(/\A:fog.*url\
|
51
|
+
unless @options[:url].to_s.match(/\A:fog.*url\z/)
|
52
52
|
@options[:path] = @options[:path].gsub(/:url/, @options[:url]).gsub(/\A:rails_root\/public\/system\//, '')
|
53
53
|
@options[:url] = ':fog_public_url'
|
54
54
|
end
|
@@ -58,7 +58,7 @@ module Paperclip
|
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
61
|
-
AWS_BUCKET_SUBDOMAIN_RESTRICTON_REGEX = /\A(?:[a-z]|\d(?!\d{0,2}(?:\.\d{1,3}){3}\
|
61
|
+
AWS_BUCKET_SUBDOMAIN_RESTRICTON_REGEX = /\A(?:[a-z]|\d(?!\d{0,2}(?:\.\d{1,3}){3}\z))(?:[a-z0-9]|\.(?![\.\-])|\-(?![\.])){1,61}[a-z0-9]\z/
|
62
62
|
|
63
63
|
def exists?(style = default_style)
|
64
64
|
if original_filename
|
@@ -86,11 +86,14 @@ module Paperclip
|
|
86
86
|
end
|
87
87
|
|
88
88
|
def fog_public(style = default_style)
|
89
|
-
if @options.
|
90
|
-
|
91
|
-
|
89
|
+
if @options.key?(:fog_public)
|
90
|
+
value = @options[:fog_public]
|
91
|
+
if value.respond_to?(:key?) && value.key?(style)
|
92
|
+
value[style]
|
93
|
+
elsif value.respond_to?(:call)
|
94
|
+
value.call(self)
|
92
95
|
else
|
93
|
-
|
96
|
+
value
|
94
97
|
end
|
95
98
|
else
|
96
99
|
true
|
@@ -114,6 +117,7 @@ module Paperclip
|
|
114
117
|
raise if retried
|
115
118
|
retried = true
|
116
119
|
directory.save
|
120
|
+
file.rewind
|
117
121
|
retry
|
118
122
|
ensure
|
119
123
|
file.rewind
|
@@ -170,6 +174,7 @@ module Paperclip
|
|
170
174
|
log("copying #{path(style)} to local file #{local_dest_path}")
|
171
175
|
::File.open(local_dest_path, 'wb') do |local_file|
|
172
176
|
file = directory.files.get(path(style))
|
177
|
+
return false unless file
|
173
178
|
local_file.write(file.body)
|
174
179
|
end
|
175
180
|
rescue ::Fog::Errors::Error => e
|
@@ -180,7 +185,7 @@ module Paperclip
|
|
180
185
|
private
|
181
186
|
|
182
187
|
def convert_time(time)
|
183
|
-
if time.is_a?(
|
188
|
+
if time.is_a?(Integer)
|
184
189
|
time = Time.now + time
|
185
190
|
end
|
186
191
|
time
|
data/lib/paperclip/storage/s3.rb
CHANGED
@@ -45,15 +45,14 @@ module Paperclip
|
|
45
45
|
#
|
46
46
|
# You can set permission on a per style bases by doing the following:
|
47
47
|
# :s3_permissions => {
|
48
|
-
# :original =>
|
48
|
+
# :original => "private"
|
49
49
|
# }
|
50
50
|
# Or globally:
|
51
|
-
# :s3_permissions =>
|
51
|
+
# :s3_permissions => "private"
|
52
52
|
#
|
53
|
-
# * +s3_protocol+: The protocol for the URLs generated to your S3 assets.
|
54
|
-
# 'http', 'https', or an empty string to generate
|
55
|
-
#
|
56
|
-
# :s3_permissions are anything else.
|
53
|
+
# * +s3_protocol+: The protocol for the URLs generated to your S3 assets.
|
54
|
+
# Can be either 'http', 'https', or an empty string to generate
|
55
|
+
# protocol-relative URLs. Defaults to empty string.
|
57
56
|
# * +s3_headers+: A hash of headers or a Proc. You may specify a hash such as
|
58
57
|
# {'Expires' => 1.year.from_now.httpdate}. If you use a Proc, headers are determined at
|
59
58
|
# runtime. Paperclip will call that Proc with attachment as the only argument.
|
@@ -66,6 +65,9 @@ module Paperclip
|
|
66
65
|
# * +s3_host_alias+: The fully-qualified domain name (FQDN) that is the alias to the
|
67
66
|
# S3 domain of your bucket. Used with the :s3_alias_url url interpolation. See the
|
68
67
|
# link in the +url+ entry for more information about S3 domains and buckets.
|
68
|
+
# * +s3_prefixes_in_alias+: The number of prefixes that is prepended by
|
69
|
+
# s3_host_alias. This will remove the prefixes from the path in
|
70
|
+
# :s3_alias_url url interpolation
|
69
71
|
# * +url+: There are four options for the S3 url. You can choose to have the bucket's name
|
70
72
|
# placed domain-style (bucket.s3.amazonaws.com) or path-style (s3.amazonaws.com/bucket).
|
71
73
|
# You can also specify a CNAME (which requires the CNAME to be specified as
|
@@ -92,24 +94,31 @@ module Paperclip
|
|
92
94
|
# to interpolate. Keys should be unique, like filenames, and despite the fact that
|
93
95
|
# S3 (strictly speaking) does not support directories, you can still use a / to
|
94
96
|
# separate parts of your file name.
|
95
|
-
# * +s3_host_name+: If you are using your bucket in Tokyo region
|
97
|
+
# * +s3_host_name+: If you are using your bucket in Tokyo region
|
98
|
+
# etc, write host_name (e.g., 's3-ap-northeast-1.amazonaws.com').
|
96
99
|
# * +s3_region+: For aws-sdk v2, s3_region is required.
|
97
100
|
# * +s3_metadata+: These key/value pairs will be stored with the
|
98
101
|
# object. This option works by prefixing each key with
|
99
102
|
# "x-amz-meta-" before sending it as a header on the object
|
100
103
|
# upload request. Can be defined both globally and within a style-specific hash.
|
101
104
|
# * +s3_storage_class+: If this option is set to
|
102
|
-
# <tt>:
|
103
|
-
# Redundancy Storage.
|
105
|
+
# <tt>:REDUCED_REDUNDANCY</tt>, the object will be stored using Reduced
|
106
|
+
# Redundancy Storage. RRS enables customers to reduce their
|
104
107
|
# costs by storing non-critical, reproducible data at lower
|
105
108
|
# levels of redundancy than Amazon S3's standard storage.
|
109
|
+
# * +use_accelerate_endpoint+: Use accelerate endpoint
|
110
|
+
# http://docs.aws.amazon.com/AmazonS3/latest/dev/transfer-acceleration.html
|
106
111
|
#
|
107
112
|
# You can set storage class on a per style bases by doing the following:
|
108
113
|
# :s3_storage_class => {
|
109
|
-
# :thumb => :
|
114
|
+
# :thumb => :REDUCED_REDUNDANCY
|
110
115
|
# }
|
116
|
+
#
|
111
117
|
# Or globally:
|
112
|
-
# :s3_storage_class => :
|
118
|
+
# :s3_storage_class => :REDUCED_REDUNDANCY
|
119
|
+
#
|
120
|
+
# Other storage classes, such as <tt>:STANDARD_IA</tt>, are also available—see the
|
121
|
+
# documentation for the <tt>aws-sdk</tt> gem for the full list.
|
113
122
|
|
114
123
|
module S3
|
115
124
|
def self.extended base
|
@@ -127,12 +136,7 @@ module Paperclip
|
|
127
136
|
base.instance_eval do
|
128
137
|
@s3_options = @options[:s3_options] || {}
|
129
138
|
@s3_permissions = set_permissions(@options[:s3_permissions])
|
130
|
-
@s3_protocol = @options[:s3_protocol]
|
131
|
-
Proc.new do |style, attachment|
|
132
|
-
permission = (@s3_permissions[style.to_s.to_sym] || @s3_permissions[:default])
|
133
|
-
permission = permission.call(attachment, style) if permission.respond_to?(:call)
|
134
|
-
(permission == :"public-read") ? 'http'.freeze : 'https'.freeze
|
135
|
-
end
|
139
|
+
@s3_protocol = @options[:s3_protocol] || "".freeze
|
136
140
|
@s3_metadata = @options[:s3_metadata] || {}
|
137
141
|
@s3_headers = {}
|
138
142
|
merge_s3_headers(@options[:s3_headers], @s3_headers, @s3_metadata)
|
@@ -147,17 +151,30 @@ module Paperclip
|
|
147
151
|
@s3_server_side_encryption = @options[:s3_server_side_encryption]
|
148
152
|
end
|
149
153
|
|
150
|
-
unless @options[:url].to_s.match(/\A:s3.*url\
|
154
|
+
unless @options[:url].to_s.match(/\A:s3.*url\z/) || @options[:url] == ":asset_host".freeze
|
151
155
|
@options[:path] = path_option.gsub(/:url/, @options[:url]).sub(/\A:rails_root\/public\/system/, "".freeze)
|
152
156
|
@options[:url] = ":s3_path_url".freeze
|
153
157
|
end
|
154
158
|
@options[:url] = @options[:url].inspect if @options[:url].is_a?(Symbol)
|
155
159
|
|
156
160
|
@http_proxy = @options[:http_proxy] || nil
|
161
|
+
|
162
|
+
if @options.has_key?(:use_accelerate_endpoint) &&
|
163
|
+
Gem::Version.new(Aws::VERSION) < Gem::Version.new("2.3.0")
|
164
|
+
raise LoadError, ":use_accelerate_endpoint is only available from aws-sdk version 2.3.0. Please upgrade aws-sdk to a newer version."
|
165
|
+
end
|
166
|
+
|
167
|
+
@use_accelerate_endpoint = @options[:use_accelerate_endpoint]
|
157
168
|
end
|
158
169
|
|
159
170
|
Paperclip.interpolates(:s3_alias_url) do |attachment, style|
|
160
|
-
|
171
|
+
protocol = attachment.s3_protocol(style, true)
|
172
|
+
host = attachment.s3_host_alias
|
173
|
+
path = attachment.path(style).
|
174
|
+
split("/")[attachment.s3_prefixes_in_alias..-1].
|
175
|
+
join("/").
|
176
|
+
sub(%r{\A/}, "".freeze)
|
177
|
+
"#{protocol}//#{host}/#{path}"
|
161
178
|
end unless Paperclip::Interpolations.respond_to? :s3_alias_url
|
162
179
|
Paperclip.interpolates(:s3_path_url) do |attachment, style|
|
163
180
|
"#{attachment.s3_protocol(style, true)}//#{attachment.s3_host_name}/#{attachment.bucket_name}/#{attachment.path(style).sub(%r{\A/}, "".freeze)}"
|
@@ -206,6 +223,10 @@ module Paperclip
|
|
206
223
|
@s3_host_alias
|
207
224
|
end
|
208
225
|
|
226
|
+
def s3_prefixes_in_alias
|
227
|
+
@s3_prefixes_in_alias ||= @options[:s3_prefixes_in_alias].to_i
|
228
|
+
end
|
229
|
+
|
209
230
|
def s3_url_options
|
210
231
|
s3_url_options = @options[:s3_url_options] || {}
|
211
232
|
s3_url_options = s3_url_options.call(instance) if s3_url_options.respond_to?(:call)
|
@@ -234,6 +255,8 @@ module Paperclip
|
|
234
255
|
config[:proxy_uri] = URI::HTTP.build(proxy_opts)
|
235
256
|
end
|
236
257
|
|
258
|
+
config[:use_accelerate_endpoint] = use_accelerate_endpoint?
|
259
|
+
|
237
260
|
[:access_key_id, :secret_access_key, :credential_provider, :credentials].each do |opt|
|
238
261
|
config[opt] = s3_credentials[opt] if s3_credentials[opt]
|
239
262
|
end
|
@@ -259,6 +282,10 @@ module Paperclip
|
|
259
282
|
s3_bucket.object style_name_as_path(style_name)
|
260
283
|
end
|
261
284
|
|
285
|
+
def use_accelerate_endpoint?
|
286
|
+
!!@use_accelerate_endpoint
|
287
|
+
end
|
288
|
+
|
262
289
|
def using_http_proxy?
|
263
290
|
!!@http_proxy
|
264
291
|
end
|
data/lib/paperclip/thumbnail.rb
CHANGED
@@ -3,10 +3,11 @@ module Paperclip
|
|
3
3
|
class Thumbnail < Processor
|
4
4
|
|
5
5
|
attr_accessor :current_geometry, :target_geometry, :format, :whiny, :convert_options,
|
6
|
-
:source_file_options, :animated, :auto_orient
|
6
|
+
:source_file_options, :animated, :auto_orient, :frame_index
|
7
7
|
|
8
8
|
# List of formats that we need to preserve animation
|
9
9
|
ANIMATED_FORMATS = %w(gif)
|
10
|
+
MULTI_FRAME_FORMATS = %w(.mkv .avi .mp4 .mov .mpg .mpeg .gif)
|
10
11
|
|
11
12
|
# Creates a Thumbnail object set to work on the +file+ given. It
|
12
13
|
# will attempt to transform the image into one defined by +target_geometry+
|
@@ -25,6 +26,7 @@ module Paperclip
|
|
25
26
|
# +whiny+ - whether to raise an error when processing fails. Defaults to true
|
26
27
|
# +format+ - the desired filename extension
|
27
28
|
# +animated+ - whether to merge all the layers in the image. Defaults to true
|
29
|
+
# +frame_index+ - the frame index of the source file to render as the thumbnail
|
28
30
|
def initialize(file, options = {}, attachment = nil)
|
29
31
|
super
|
30
32
|
|
@@ -41,12 +43,12 @@ module Paperclip
|
|
41
43
|
if @auto_orient && @current_geometry.respond_to?(:auto_orient)
|
42
44
|
@current_geometry.auto_orient
|
43
45
|
end
|
44
|
-
|
45
46
|
@source_file_options = @source_file_options.split(/\s+/) if @source_file_options.respond_to?(:split)
|
46
47
|
@convert_options = @convert_options.split(/\s+/) if @convert_options.respond_to?(:split)
|
47
48
|
|
48
49
|
@current_format = File.extname(@file.path)
|
49
50
|
@basename = File.basename(@file.path, @current_format)
|
51
|
+
@frame_index = multi_frame_format? ? options.fetch(:frame_index, 0) : 0
|
50
52
|
end
|
51
53
|
|
52
54
|
# Returns true if the +target_geometry+ is meant to crop.
|
@@ -76,10 +78,15 @@ module Paperclip
|
|
76
78
|
|
77
79
|
parameters = parameters.flatten.compact.join(" ").strip.squeeze(" ")
|
78
80
|
|
79
|
-
|
80
|
-
|
81
|
+
frame = animated? ? "" : "[#{@frame_index}]"
|
82
|
+
convert(
|
83
|
+
parameters,
|
84
|
+
source: "#{File.expand_path(src.path)}#{frame}",
|
85
|
+
dest: File.expand_path(dst.path),
|
86
|
+
)
|
87
|
+
rescue Terrapin::ExitStatusError => e
|
81
88
|
raise Paperclip::Error, "There was an error processing the thumbnail for #{@basename}" if @whiny
|
82
|
-
rescue
|
89
|
+
rescue Terrapin::CommandNotFoundError => e
|
83
90
|
raise Paperclip::Errors::CommandNotFoundError.new("Could not run the `convert` command. Please install ImageMagick.")
|
84
91
|
end
|
85
92
|
|
@@ -101,7 +108,10 @@ module Paperclip
|
|
101
108
|
|
102
109
|
protected
|
103
110
|
|
104
|
-
|
111
|
+
def multi_frame_format?
|
112
|
+
MULTI_FRAME_FORMATS.include? @current_format
|
113
|
+
end
|
114
|
+
|
105
115
|
def animated?
|
106
116
|
@animated && (ANIMATED_FORMATS.include?(@format.to_s) || @format.blank?) && identified_as_animated?
|
107
117
|
end
|
@@ -112,9 +122,9 @@ module Paperclip
|
|
112
122
|
@identified_as_animated = ANIMATED_FORMATS.include? identify("-format %m :file", :file => "#{@file.path}[0]").to_s.downcase.strip
|
113
123
|
end
|
114
124
|
@identified_as_animated
|
115
|
-
rescue
|
125
|
+
rescue Terrapin::ExitStatusError => e
|
116
126
|
raise Paperclip::Error, "There was an error running `identify` for #{@basename}" if @whiny
|
117
|
-
rescue
|
127
|
+
rescue Terrapin::CommandNotFoundError => e
|
118
128
|
raise Paperclip::Errors::CommandNotFoundError.new("Could not run the `identify` command. Please install ImageMagick.")
|
119
129
|
end
|
120
130
|
end
|
@@ -1,30 +1,34 @@
|
|
1
1
|
require 'uri'
|
2
|
+
require 'active_support/core_ext/module/delegation'
|
2
3
|
|
3
4
|
module Paperclip
|
4
5
|
class UrlGenerator
|
5
|
-
def initialize(attachment
|
6
|
+
def initialize(attachment)
|
6
7
|
@attachment = attachment
|
7
|
-
@attachment_options = attachment_options
|
8
8
|
end
|
9
9
|
|
10
10
|
def for(style_name, options)
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
11
|
+
interpolated = attachment_options[:interpolator].interpolate(
|
12
|
+
most_appropriate_url, @attachment, style_name
|
13
|
+
)
|
14
|
+
|
15
|
+
escaped = escape_url_as_needed(interpolated, options)
|
16
|
+
timestamp_as_needed(escaped, options)
|
16
17
|
end
|
17
18
|
|
18
19
|
private
|
19
20
|
|
21
|
+
attr_reader :attachment
|
22
|
+
delegate :options, to: :attachment, prefix: true
|
23
|
+
|
20
24
|
# This method is all over the place.
|
21
25
|
def default_url
|
22
|
-
if
|
23
|
-
|
24
|
-
elsif
|
25
|
-
@attachment.instance.send(
|
26
|
+
if attachment_options[:default_url].respond_to?(:call)
|
27
|
+
attachment_options[:default_url].call(@attachment)
|
28
|
+
elsif attachment_options[:default_url].is_a?(Symbol)
|
29
|
+
@attachment.instance.send(attachment_options[:default_url])
|
26
30
|
else
|
27
|
-
|
31
|
+
attachment_options[:default_url]
|
28
32
|
end
|
29
33
|
end
|
30
34
|
|
@@ -32,7 +36,7 @@ module Paperclip
|
|
32
36
|
if @attachment.original_filename.nil?
|
33
37
|
default_url
|
34
38
|
else
|
35
|
-
|
39
|
+
attachment_options[:url]
|
36
40
|
end
|
37
41
|
end
|
38
42
|
|
data/lib/paperclip/validators.rb
CHANGED
@@ -36,7 +36,7 @@ module Paperclip
|
|
36
36
|
options = attributes.extract_options!.dup
|
37
37
|
|
38
38
|
Paperclip::Validators.constants.each do |constant|
|
39
|
-
if constant.to_s =~ /\AAttachment(.+)Validator\
|
39
|
+
if constant.to_s =~ /\AAttachment(.+)Validator\z/
|
40
40
|
validator_kind = $1.underscore.to_sym
|
41
41
|
|
42
42
|
if options.has_key?(validator_kind)
|
data/lib/paperclip/version.rb
CHANGED