paperclip 3.0.3 → 3.0.4

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of paperclip might be problematic. Click here for more details.

data/Appraisals CHANGED
@@ -9,6 +9,6 @@ appraise "3.1" do
9
9
  end
10
10
 
11
11
  appraise "3.2" do
12
- gem "rails", "~> 3.2.2"
12
+ gem "rails", "~> 3.2.3"
13
13
  gem "paperclip", :path => "../"
14
14
  end
data/README.md CHANGED
@@ -244,7 +244,7 @@ This would load the hypothetical class Paperclip::Ocr, which would have the
244
244
  hash "{ :quality => :better }" passed to it along with the uploaded file. For
245
245
  more information about defining processors, see Paperclip::Processor.
246
246
 
247
- The default processor is Paperclip::Thumbnail. For backwards compatability
247
+ The default processor is Paperclip::Thumbnail. For backwards compatibility
248
248
  reasons, you can pass a single geometry string or an array containing a
249
249
  geometry and a format, which the file will be converted to, like so:
250
250
 
@@ -400,10 +400,10 @@ processors, where a defined `watermark` processor is invoked after the
400
400
  attr_accessor :watermark
401
401
  end
402
402
 
403
- Deploy
404
- ------
403
+ Deployment
404
+ ----------
405
405
 
406
- Paperclip is aware of new attachment styles you have added in previous deploy. The only thing you should do after each deployment is to call
406
+ 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
407
407
  `rake paperclip:refresh:missing_styles`. It will store current attachment styles in `RAILS_ROOT/public/system/paperclip_attachments.yml`
408
408
  by default. You can change it by:
409
409
 
@@ -420,11 +420,11 @@ Here is an example for Capistrano:
420
420
 
421
421
  after("deploy:update_code", "deploy:build_missing_paperclip_styles")
422
422
 
423
- Now you don't have to remember to refresh thumbnails in production everytime you add new style.
423
+ Now you don't have to remember to refresh thumbnails in production every time you add a new style.
424
424
  Unfortunately it does not work with dynamic styles - it just ignores them.
425
425
 
426
- If you already have working app and don't want `rake paperclip:refresh:missing_styles` to refresh old pictures, you need to tell
427
- Paperclip about existing styles. Simply create paperclip\_attachments.yml file by hand. For example:
426
+ If you already have a working app and don't want `rake paperclip:refresh:missing_styles` to refresh old pictures, you need to tell
427
+ Paperclip about existing styles. Simply create a `paperclip_attachments.yml` file by hand. For example:
428
428
 
429
429
  class User < ActiveRecord::Base
430
430
  has_attached_file :avatar, :styles => {:thumb => 'x100', :croppable => '600x600>', :big => '1000x1000>'}
@@ -5,7 +5,7 @@ source "http://rubygems.org"
5
5
  gem "jruby-openssl", :platform=>:jruby
6
6
  gem "activerecord-jdbcsqlite3-adapter", :platform=>:jruby
7
7
  gem "sqlite3", :platform=>:ruby
8
- gem "rails", "~> 3.2.2"
8
+ gem "rails", "~> 3.2.3"
9
9
  gem "paperclip", :path=>"../"
10
10
 
11
11
  gemspec :path=>"../"
@@ -32,6 +32,18 @@ module Paperclip
32
32
  def self.make file, options = {}, attachment = nil
33
33
  new(file, options, attachment).make
34
34
  end
35
+
36
+ # The convert method runs the convert binary with the provided arguments.
37
+ # See Paperclip.run for the available options.
38
+ def convert(arguments = "", local_options = {})
39
+ Paperclip.run('convert', arguments, local_options)
40
+ end
41
+
42
+ # The identify method runs the identify binary with the provided arguments.
43
+ # See Paperclip.run for the available options.
44
+ def identify(arguments = "", local_options = {})
45
+ Paperclip.run('identify', arguments, local_options)
46
+ end
35
47
  end
36
48
 
37
49
  module ProcessorHelpers
@@ -39,8 +39,9 @@ module Paperclip
39
39
  # :s3_permissions => :private
40
40
  #
41
41
  # * +s3_protocol+: The protocol for the URLs generated to your S3 assets. Can be either
42
- # 'http' or 'https'. Defaults to 'http' when your :s3_permissions are :public_read (the
43
- # default), and 'https' when your :s3_permissions are anything else.
42
+ # 'http', 'https', or an empty string to generate scheme-less URLs. Defaults to 'http'
43
+ # when your :s3_permissions are :public_read (the default), and 'https' when your
44
+ # :s3_permissions are anything else.
44
45
  # * +s3_headers+: A hash of headers or a Proc. You may specify a hash such as
45
46
  # {'Expires' => 1.year.from_now.httpdate}. If you use a Proc, headers are determined at
46
47
  # runtime. Paperclip will call that Proc with attachment as the only argument.
@@ -60,12 +61,19 @@ module Paperclip
60
61
  # Normally, this won't matter in the slightest and you can leave the default (which is
61
62
  # path-style, or :s3_path_url). But in some cases paths don't work and you need to use
62
63
  # the domain-style (:s3_domain_url). Anything else here will be treated like path-style.
63
- # NOTE: If you use a CNAME for use with CloudFront, you can NOT specify https as your
64
- # :s3_protocol; This is *not supported* by S3/CloudFront. Finally, when using the host
65
- # alias, the :bucket parameter is ignored, as the hostname is used as the bucket name
66
- # by S3. The fourth option for the S3 url is :asset_host, which uses Rails' built-in
67
- # asset_host settings. NOTE: To get the full url from a paperclip'd object, use the
68
- # image_path helper; this is what image_tag uses to generate the url for an img tag.
64
+ #
65
+ # Notes:
66
+ # * The value of this option is a string, not a symbol.
67
+ # <b>right:</b> <tt>":s3_domain_url"</tt>
68
+ # <b>wrong:</b> <tt>:s3_domain_url</tt>
69
+ # * If you use a CNAME for use with CloudFront, you can NOT specify https as your
70
+ # :s3_protocol;
71
+ # This is *not supported* by S3/CloudFront. Finally, when using the host
72
+ # alias, the :bucket parameter is ignored, as the hostname is used as the bucket name
73
+ # by S3. The fourth option for the S3 url is :asset_host, which uses Rails' built-in
74
+ # asset_host settings.
75
+ # * To get the full url from a paperclip'd object, use the
76
+ # image_path helper; this is what image_tag uses to generate the url for an img tag.
69
77
  # * +path+: This is the key under the bucket in which the file will be stored. The
70
78
  # URL will be constructed from the bucket and the path. This is what you will want
71
79
  # to interpolate. Keys should be unique, like filenames, and despite the fact that
@@ -140,14 +148,15 @@ module Paperclip
140
148
 
141
149
  @http_proxy = @options[:http_proxy] || nil
142
150
  end
151
+
143
152
  Paperclip.interpolates(:s3_alias_url) do |attachment, style|
144
- "#{attachment.s3_protocol(style)}://#{attachment.s3_host_alias}/#{attachment.path(style).gsub(%r{^/}, "")}"
153
+ "#{attachment.s3_protocol(style)}//#{attachment.s3_host_alias}/#{attachment.path(style).gsub(%r{^/}, "")}"
145
154
  end unless Paperclip::Interpolations.respond_to? :s3_alias_url
146
155
  Paperclip.interpolates(:s3_path_url) do |attachment, style|
147
- "#{attachment.s3_protocol(style)}://#{attachment.s3_host_name}/#{attachment.bucket_name}/#{attachment.path(style).gsub(%r{^/}, "")}"
156
+ "#{attachment.s3_protocol(style)}//#{attachment.s3_host_name}/#{attachment.bucket_name}/#{attachment.path(style).gsub(%r{^/}, "")}"
148
157
  end unless Paperclip::Interpolations.respond_to? :s3_path_url
149
158
  Paperclip.interpolates(:s3_domain_url) do |attachment, style|
150
- "#{attachment.s3_protocol(style)}://#{attachment.bucket_name}.#{attachment.s3_host_name}/#{attachment.path(style).gsub(%r{^/}, "")}"
159
+ "#{attachment.s3_protocol(style)}//#{attachment.bucket_name}.#{attachment.s3_host_name}/#{attachment.path(style).gsub(%r{^/}, "")}"
151
160
  end unless Paperclip::Interpolations.respond_to? :s3_domain_url
152
161
  Paperclip.interpolates(:asset_host) do |attachment, style|
153
162
  "#{attachment.path(style).gsub(%r{^/}, "")}"
@@ -272,11 +281,14 @@ module Paperclip
272
281
  end
273
282
 
274
283
  def s3_protocol(style = default_style)
275
- if @s3_protocol.is_a?(Proc)
284
+ protocol = if @s3_protocol.is_a?(Proc)
276
285
  @s3_protocol.call(style, self)
277
286
  else
278
287
  @s3_protocol
279
288
  end
289
+
290
+ protocol = protocol.split(":").first + ":" unless protocol.empty?
291
+ protocol
280
292
  end
281
293
 
282
294
  def create_bucket
@@ -348,7 +360,7 @@ module Paperclip
348
360
  private :find_credentials
349
361
 
350
362
  def use_secure_protocol?(style_name)
351
- s3_protocol(style_name) == "https"
363
+ s3_protocol(style_name) == "https:"
352
364
  end
353
365
  private :use_secure_protocol?
354
366
  end
@@ -73,7 +73,7 @@ module Paperclip
73
73
 
74
74
  parameters = parameters.flatten.compact.join(" ").strip.squeeze(" ")
75
75
 
76
- success = Paperclip.run("convert", parameters, :source => "#{File.expand_path(src.path)}#{'[0]' unless animated?}", :dest => File.expand_path(dst.path))
76
+ success = convert(parameters, :source => "#{File.expand_path(src.path)}#{'[0]' unless animated?}", :dest => File.expand_path(dst.path))
77
77
  rescue Cocaine::ExitStatusError => e
78
78
  raise Paperclip::Error, "There was an error processing the thumbnail for #{@basename}" if @whiny
79
79
  rescue Cocaine::CommandNotFoundError => e
@@ -1,3 +1,3 @@
1
1
  module Paperclip
2
- VERSION = "3.0.3" unless defined? Paperclip::VERSION
2
+ VERSION = "3.0.4" unless defined? Paperclip::VERSION
3
3
  end
@@ -7,4 +7,20 @@ class ProcessorTest < Test::Unit::TestCase
7
7
  Paperclip::Processor.expects(:new).with(:one, :two, :three).returns(processor)
8
8
  Paperclip::Processor.make(:one, :two, :three)
9
9
  end
10
+
11
+ context "Calling #convert" do
12
+ should "run the convert command with Cocaine" do
13
+ Paperclip.options[:log_command] = false
14
+ Cocaine::CommandLine.expects(:new).with("convert", "stuff", {}).returns(stub(:run))
15
+ Paperclip::Processor.new('filename').convert("stuff")
16
+ end
17
+ end
18
+
19
+ context "Calling #identify" do
20
+ should "run the identify command with Cocaine" do
21
+ Paperclip.options[:log_command] = false
22
+ Cocaine::CommandLine.expects(:new).with("identify", "stuff", {}).returns(stub(:run))
23
+ Paperclip::Processor.new('filename').identify("stuff")
24
+ end
25
+ end
10
26
  end
@@ -128,6 +128,38 @@ class S3Test < Test::Unit::TestCase
128
128
 
129
129
  end
130
130
 
131
+ context ":s3_protocol => 'https'" do
132
+ setup do
133
+ rebuild_model :storage => :s3,
134
+ :s3_credentials => {},
135
+ :s3_protocol => 'https',
136
+ :bucket => "bucket",
137
+ :path => ":attachment/:basename.:extension"
138
+ @dummy = Dummy.new
139
+ @dummy.avatar = StringIO.new(".")
140
+ end
141
+
142
+ should "return a url based on an S3 path" do
143
+ assert_match %r{^https://s3.amazonaws.com/bucket/avatars/stringio.txt}, @dummy.avatar.url
144
+ end
145
+ end
146
+
147
+ context ":s3_protocol => ''" do
148
+ setup do
149
+ rebuild_model :storage => :s3,
150
+ :s3_credentials => {},
151
+ :s3_protocol => '',
152
+ :bucket => "bucket",
153
+ :path => ":attachment/:basename.:extension"
154
+ @dummy = Dummy.new
155
+ @dummy.avatar = StringIO.new(".")
156
+ end
157
+
158
+ should "return a url based on an S3 path" do
159
+ assert_match %r{^//s3.amazonaws.com/bucket/avatars/stringio.txt}, @dummy.avatar.url
160
+ end
161
+ end
162
+
131
163
  context "An attachment that uses S3 for storage and has the style in the path" do
132
164
  setup do
133
165
  rebuild_model :storage => :s3,
@@ -113,10 +113,9 @@ class ThumbnailTest < Test::Unit::TestCase
113
113
  end
114
114
 
115
115
  should "send the right command to convert when sent #make" do
116
- Paperclip.expects(:run).with do |*arg|
117
- arg[0] == 'convert' &&
118
- arg[1] == ':source -resize "x50" -crop "100x50+114+0" +repage :dest' &&
119
- arg[2][:source] == "#{File.expand_path(@thumb.file.path)}[0]"
116
+ @thumb.expects(:convert).with do |*arg|
117
+ arg[0] == ':source -resize "x50" -crop "100x50+114+0" +repage :dest' &&
118
+ arg[1][:source] == "#{File.expand_path(@thumb.file.path)}[0]"
120
119
  end
121
120
  @thumb.make
122
121
  end
@@ -139,10 +138,9 @@ class ThumbnailTest < Test::Unit::TestCase
139
138
  end
140
139
 
141
140
  should "send the right command to convert when sent #make" do
142
- Paperclip.expects(:run).with do |*arg|
143
- arg[0] == 'convert' &&
144
- arg[1] == '-strip :source -resize "x50" -crop "100x50+114+0" +repage :dest' &&
145
- arg[2][:source] == "#{File.expand_path(@thumb.file.path)}[0]"
141
+ @thumb.expects(:convert).with do |*arg|
142
+ arg[0] == '-strip :source -resize "x50" -crop "100x50+114+0" +repage :dest' &&
143
+ arg[1][:source] == "#{File.expand_path(@thumb.file.path)}[0]"
146
144
  end
147
145
  @thumb.make
148
146
  end
@@ -181,10 +179,9 @@ class ThumbnailTest < Test::Unit::TestCase
181
179
  end
182
180
 
183
181
  should "send the right command to convert when sent #make" do
184
- Paperclip.expects(:run).with do |*arg|
185
- arg[0] == 'convert' &&
186
- arg[1] == ':source -resize "x50" -crop "100x50+114+0" +repage -strip -depth 8 :dest' &&
187
- arg[2][:source] == "#{File.expand_path(@thumb.file.path)}[0]"
182
+ @thumb.expects(:convert).with do |*arg|
183
+ arg[0] == ':source -resize "x50" -crop "100x50+114+0" +repage -strip -depth 8 :dest' &&
184
+ arg[1][:source] == "#{File.expand_path(@thumb.file.path)}[0]"
188
185
  end
189
186
  @thumb.make
190
187
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paperclip
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.3
4
+ version: 3.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-05 00:00:00.000000000 Z
12
+ date: 2012-05-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
@@ -530,7 +530,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
530
530
  requirements:
531
531
  - ImageMagick
532
532
  rubyforge_project: paperclip
533
- rubygems_version: 1.8.21
533
+ rubygems_version: 1.8.24
534
534
  signing_key:
535
535
  specification_version: 3
536
536
  summary: File attachments as attributes for ActiveRecord
@@ -601,4 +601,3 @@ test_files:
601
601
  - test/validators/attachment_presence_validator_test.rb
602
602
  - test/validators/attachment_size_validator_test.rb
603
603
  - test/validators_test.rb
604
- has_rdoc: