Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into interpolations_tu…
Browse files Browse the repository at this point in the history
…ning
  • Loading branch information
dgynn committed Aug 21, 2015
2 parents f3172b3 + 6e0c9e9 commit 372c499
Show file tree
Hide file tree
Showing 18 changed files with 567 additions and 232 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ gemfile:
- gemfiles/3.2.gemfile
- gemfiles/4.1.gemfile
- gemfiles/4.2.gemfile
- gemfiles/3.2.awsv1.gemfile
- gemfiles/4.1.awsv1.gemfile
- gemfiles/4.2.awsv1.gemfile

matrix:
fast_finish: true
Expand Down
18 changes: 18 additions & 0 deletions Appraisals
Original file line number Diff line number Diff line change
@@ -1,11 +1,29 @@
appraise "3.2" do
gem "rails", "~> 3.2.0"
gem "aws-sdk", "~> 2.0"
end

appraise "4.1" do
gem "rails", "~> 4.1.0"
gem "aws-sdk", "~> 2.0"
end

appraise "4.2" do
gem "rails", "~> 4.2.0"
gem "aws-sdk", "~> 2.0"
end

appraise "3.2.awsv1" do
gem "rails", "~> 3.2.0"
gem "aws-sdk", "~> 1.5"
end

appraise "4.1.awsv1" do
gem "rails", "~> 4.1.0"
gem "aws-sdk", "~> 1.5"
end

appraise "4.2.awsv1" do
gem "rails", "~> 4.2.0"
gem "aws-sdk", "~> 1.5"
end
64 changes: 32 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ gem "paperclip", "~> 2.7"
Or, if you want to get the latest, you can get master from the main paperclip repository:

```ruby
gem "paperclip", :git => "git://github.com/thoughtbot/paperclip.git"
gem "paperclip", git: "git://github.com/thoughtbot/paperclip.git"
```

If you're trying to use features that don't seem to be in the latest released gem, but are
Expand Down Expand Up @@ -188,17 +188,17 @@ Quick Start
```ruby
class User < ActiveRecord::Base
attr_accessible :avatar
has_attached_file :avatar, :styles => { :medium => "300x300>", :thumb => "100x100>" }, :default_url => "/images/:style/missing.png"
validates_attachment_content_type :avatar, :content_type => /\Aimage\/.*\Z/
has_attached_file :avatar, styles: { medium: "300x300>", thumb: "100x100>" }, default_url: "/images/:style/missing.png"
validates_attachment_content_type :avatar, content_type: /\Aimage\/.*\Z/
end
```

**Rails 4**

```ruby
class User < ActiveRecord::Base
has_attached_file :avatar, :styles => { :medium => "300x300>", :thumb => "100x100>" }, :default_url => "/images/:style/missing.png"
validates_attachment_content_type :avatar, :content_type => /\Aimage\/.*\Z/
has_attached_file :avatar, styles: { medium: "300x300>", thumb: "100x100>" }, default_url: "/images/:style/missing.png"
validates_attachment_content_type :avatar, content_type: /\Aimage\/.*\Z/
end
```

Expand All @@ -221,7 +221,7 @@ end
### Edit and New Views

```erb
<%= form_for @user, :url => users_path, :html => { :multipart => true } do |form| %>
<%= form_for @user, url: users_path, html: { multipart: true } do |form| %>
<%= form.file_field :avatar %>
<% end %>
```
Expand Down Expand Up @@ -312,9 +312,9 @@ For validations, Paperclip introduces several validators to validate your attach
Example Usage:

```ruby
validates :avatar, :attachment_presence => true
validates_with AttachmentPresenceValidator, :attributes => :avatar
validates_with AttachmentSizeValidator, :attributes => :avatar, :less_than => 1.megabytes
validates :avatar, attachment_presence: true
validates_with AttachmentPresenceValidator, attributes: :avatar
validates_with AttachmentSizeValidator, attributes: :avatar, less_than: 1.megabytes

```

Expand All @@ -333,9 +333,9 @@ validates_attachment_presence :avatar
Lastly, you can also define multiple validations on a single attachment using `validates_attachment`:

```ruby
validates_attachment :avatar, :presence => true,
:content_type => { :content_type => "image/jpeg" },
:size => { :in => 0..10.kilobytes }
validates_attachment :avatar, presence: true,
content_type: { content_type: "image/jpeg" },
size: { in: 0..10.kilobytes }
```

_NOTE: Post-processing will not even **start** if the attachment is not valid
Expand Down Expand Up @@ -393,7 +393,7 @@ image-y ones:

```ruby
validates_attachment :avatar,
:content_type => { :content_type => ["image/jpeg", "image/gif", "image/png"] }
content_type: { content_type: ["image/jpeg", "image/gif", "image/png"] }
```

`Paperclip::ContentTypeDetector` will attempt to match a file's extension to an
Expand All @@ -417,9 +417,9 @@ do this.
class ActiveRecord::Base
has_attached_file :avatar
# Validate content type
validates_attachment_content_type :avatar, :content_type => /\Aimage/
validates_attachment_content_type :avatar, content_type: /\Aimage/
# Validate filename
validates_attachment_file_name :avatar, :matches => [/png\Z/, /jpe?g\Z/]
validates_attachment_file_name :avatar, matches: [/png\Z/, /jpe?g\Z/]
# Explicitly do not validate
do_not_validate_attachment_file_type :avatar
end
Expand Down Expand Up @@ -462,7 +462,7 @@ module YourApp
class Application < Rails::Application
# Other code...

config.paperclip_defaults = {:storage => :fog, :fog_credentials => {:provider => "Local", :local_root => "#{Rails.root}/public"}, :fog_directory => "", :fog_host => "localhost"}
config.paperclip_defaults = { storage: :fog, fog_credentials: { provider: "Local", local_root: "#{Rails.root}/public"}, fog_directory: "", fog_host: "localhost"}
end
end
```
Expand All @@ -473,7 +473,7 @@ An example Rails initializer would look something like this:

```ruby
Paperclip::Attachment.default_options[:storage] = :fog
Paperclip::Attachment.default_options[:fog_credentials] = {:provider => "Local", :local_root => "#{Rails.root}/public"}
Paperclip::Attachment.default_options[:fog_credentials] = { provider: "Local", local_root: "#{Rails.root}/public"}
Paperclip::Attachment.default_options[:fog_directory] = ""
Paperclip::Attachment.default_options[:fog_host] = "http://localhost:3000"
```
Expand Down Expand Up @@ -612,20 +612,20 @@ processors. You can specify a processor with the `:processors` option to
`has_attached_file`:

```ruby
has_attached_file :scan, :styles => { :text => { :quality => :better } },
:processors => [:ocr]
has_attached_file :scan, styles: { text: { quality: :better } },
processors: [:ocr]
```

This would load the hypothetical class Paperclip::Ocr, which would have the
hash "{ :quality => :better }" passed to it along with the uploaded file. For
hash "{ quality: :better }" passed to it along with the uploaded file. For
more information about defining processors, see Paperclip::Processor.

The default processor is Paperclip::Thumbnail. For backwards compatibility
reasons, you can pass a single geometry string or an array containing a
geometry and a format that the file will be converted to, like so:

```ruby
has_attached_file :avatar, :styles => { :thumb => ["32x32#", :png] }
has_attached_file :avatar, styles: { thumb: ["32x32#", :png] }
```

This will convert the "thumb" style to a 32x32 square in PNG format, regardless
Expand All @@ -640,12 +640,12 @@ receive the same parameters, which are defined in the `:styles` hash.
For example, assuming we had this definition:

```ruby
has_attached_file :scan, :styles => { :text => { :quality => :better } },
:processors => [:rotator, :ocr]
has_attached_file :scan, styles: { text: { quality: :better } },
processors: [:rotator, :ocr]
```

then both the :rotator processor and the :ocr processor would receive the
options `{ :quality => :better }`. This parameter may not mean anything to one
options `{ quality: :better }`. This parameter may not mean anything to one
or more or the processors, and they are expected to ignore it.

_NOTE: Because processors operate by turning the original attachment into the
Expand Down Expand Up @@ -701,8 +701,8 @@ Example Usage:

```ruby
has_attached_file :avatar, {
:url => "/system/:hash.:extension",
:hash_secret => "longSecretString"
url: "/system/:hash.:extension",
hash_secret: "longSecretString"
}
```

Expand Down Expand Up @@ -740,7 +740,7 @@ An option is available to preserve attachments in order to play nicely with soft

```ruby
has_attached_file :some_attachment, {
:preserve_files => "true",
preserve_files: "true",
}
```

Expand Down Expand Up @@ -788,7 +788,7 @@ look as follows where a boss will receive a `300x300` thumbnail otherwise a

```ruby
class User < ActiveRecord::Base
has_attached_file :avatar, :styles => lambda { |attachment| { :thumb => (attachment.instance.boss? ? "300x300>" : "100x100>") } }
has_attached_file :avatar, styles: lambda { |attachment| { thumb: (attachment.instance.boss? ? "300x300>" : "100x100>") } }
end
```

Expand All @@ -805,7 +805,7 @@ processors, where a defined `watermark` processor is invoked after the

```ruby
class User < ActiveRecord::Base
has_attached_file :avatar, :processors => lambda { |instance| instance.processors }
has_attached_file :avatar, processors: lambda { |instance| instance.processors }
attr_accessor :processors
end
```
Expand Down Expand Up @@ -866,12 +866,12 @@ Paperclip about existing styles. Simply create a `paperclip_attachments.yml` fil

```ruby
class User < ActiveRecord::Base
has_attached_file :avatar, :styles => {:thumb => 'x100', :croppable => '600x600>', :big => '1000x1000>'}
has_attached_file :avatar, styles: { thumb: 'x100', croppable: '600x600>', big: '1000x1000>' }
end

class Book < ActiveRecord::Base
has_attached_file :cover, :styles => {:small => 'x100', :large => '1000x1000>'}
has_attached_file :sample, :styles => {:thumb => 'x100'}
has_attached_file :cover, styles: { small: 'x100', large: '1000x1000>' }
has_attached_file :sample, styles: { thumb: 'x100' }
end
```

Expand Down
1 change: 1 addition & 0 deletions features/basic_integration.feature
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ Feature: Rails integration
bucket: paperclip
access_key_id: access_key
secret_access_key: secret_key
s3_region: us-west-2
"""
And I start the rails application
When I go to the new user page
Expand Down
8 changes: 6 additions & 2 deletions features/step_definitions/s3_steps.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
When /^I attach the file "([^"]*)" to "([^"]*)" on S3$/ do |file_path, field|
definition = Paperclip::AttachmentRegistry.definitions_for(User)[field.downcase.to_sym]
path = "https://paperclip.s3.amazonaws.com#{definition[:path]}"
path = if defined?(::AWS)
"https://paperclip.s3.amazonaws.com#{definition[:path]}"
else
"https://paperclip.s3-us-west-2.amazonaws.com#{definition[:path]}"
end
path.gsub!(':filename', File.basename(file_path))
path.gsub!(/:([^\/\.]+)/) do |match|
"([^\/\.]+)"
end
FakeWeb.register_uri(:put, Regexp.new(path), :body => "OK")
FakeWeb.register_uri(:put, Regexp.new(path), :body => defined?(::AWS) ? "OK" : "<xml></xml>")
step "I attach the file \"#{file_path}\" to \"#{field}\""
end

Expand Down
20 changes: 20 additions & 0 deletions gemfiles/3.2.awsv1.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "sqlite3", "~> 1.3.8", :platforms => :ruby
gem "jruby-openssl", :platforms => :jruby
gem "activerecord-jdbcsqlite3-adapter", :platforms => :jruby
gem "rubysl", :platforms => :rbx
gem "racc", :platforms => :rbx
gem "pry"
gem "rails", "~> 3.2.0"
gem "aws-sdk", "~> 1.5"

group :development, :test do
gem "mime-types", "~> 1.16"
gem "builder"
gem "rubocop", :require => false
end

gemspec :path => "../"
1 change: 1 addition & 0 deletions gemfiles/3.2.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ gem "rubysl", :platforms => :rbx
gem "racc", :platforms => :rbx
gem "pry"
gem "rails", "~> 3.2.0"
gem "aws-sdk", "~> 2.0"

group :development, :test do
gem "mime-types", "~> 1.16"
Expand Down
20 changes: 20 additions & 0 deletions gemfiles/4.1.awsv1.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "sqlite3", "~> 1.3.8", :platforms => :ruby
gem "jruby-openssl", :platforms => :jruby
gem "activerecord-jdbcsqlite3-adapter", :platforms => :jruby
gem "rubysl", :platforms => :rbx
gem "racc", :platforms => :rbx
gem "pry"
gem "rails", "~> 4.1.0"
gem "aws-sdk", "~> 1.5"

group :development, :test do
gem "mime-types", "~> 1.16"
gem "builder"
gem "rubocop", :require => false
end

gemspec :path => "../"
1 change: 1 addition & 0 deletions gemfiles/4.1.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ gem "rubysl", :platforms => :rbx
gem "racc", :platforms => :rbx
gem "pry"
gem "rails", "~> 4.1.0"
gem "aws-sdk", "~> 2.0"

group :development, :test do
gem "mime-types", "~> 1.16"
Expand Down
20 changes: 20 additions & 0 deletions gemfiles/4.2.awsv1.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "sqlite3", "~> 1.3.8", :platforms => :ruby
gem "jruby-openssl", :platforms => :jruby
gem "activerecord-jdbcsqlite3-adapter", :platforms => :jruby
gem "rubysl", :platforms => :rbx
gem "racc", :platforms => :rbx
gem "pry"
gem "rails", "~> 4.2.0"
gem "aws-sdk", "~> 1.5"

group :development, :test do
gem "mime-types", "~> 1.16"
gem "builder"
gem "rubocop", :require => false
end

gemspec :path => "../"
1 change: 1 addition & 0 deletions gemfiles/4.2.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ gem "rubysl", :platforms => :rbx
gem "racc", :platforms => :rbx
gem "pry"
gem "rails", "~> 4.2.0"
gem "aws-sdk", "~> 2.0"

group :development, :test do
gem "mime-types", "~> 1.16"
Expand Down
2 changes: 1 addition & 1 deletion lib/paperclip/geometry_parser_factory.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Paperclip
class GeometryParser
FORMAT = /\b(\d*)x?(\d*)\b(?:,(\d?))?([\>\<\#\@\%^!])?/i
FORMAT = /\b(\d*)x?(\d*)\b(?:,(\d?))?(\@\>|\>\@|[\>\<\#\@\%^!])?/i
def initialize(string)
@string = string
end
Expand Down
Loading

0 comments on commit 372c499

Please sign in to comment.