Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/anthonator/paperclip-dimension-validator
Validate image height and width for Paperclip
https://github.com/anthonator/paperclip-dimension-validator
paperclip rails-validations
Last synced: about 2 months ago
JSON representation
Validate image height and width for Paperclip
- Host: GitHub
- URL: https://github.com/anthonator/paperclip-dimension-validator
- Owner: anthonator
- License: mit
- Created: 2014-07-22T21:33:31.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2016-06-07T13:58:00.000Z (over 8 years ago)
- Last Synced: 2024-10-12T03:53:02.914Z (2 months ago)
- Topics: paperclip, rails-validations
- Language: Ruby
- Size: 196 KB
- Stars: 15
- Watchers: 3
- Forks: 11
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# paperclip-dimension-validator
Validate them dimensions!
## Installation
Add this line to your application's Gemfile:
gem 'paperclip-dimension-validator'
And then execute:
$ bundle
Or install it yourself as:
$ gem install paperclip-dimension-validator
## Usage
This gem introduces the ```dimensions``` validator for Paperclip's
```validates_attachment```. ```dimensions``` accepts a hash of ```height``` and
``` width``` integer pixel values.**Example**
```ruby
class Image < ActiveRecord::Base
has_attached_file :avatarvalidates_attachment :avatar, dimensions: { height: 30, width: 30 }
end
```## Testing
paperclip-dimension-validator includes rspec-compatible matchers for testing.
**Note** In order to use these matchers make sure to include either [chunky_png](https://github.com/wvanbergen/chunky_png) or
[oily_png](https://github.com/wvanbergen/oily_png) as a dependency in your Gemfile.**Gemfile**
```ruby
group :test do
gem 'chunky_png'
end
```**RSpec**
In spec_helper.rb, you'll need to require the matchers:
```ruby
require 'paperclip/matchers/validate_attachment_dimesions_matcher'
```And include the paperclip matchers module:
```ruby
RSpec.configure do |config|
config.include Paperclip::Shoulda::Matchers
end
```**Example**
```ruby
it { should validate_attachment_dimensions(:avatar).height(30).width(30) }
```## Contributing
1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request