README.md in carrierwave-cloudflare-0.1.1 vs README.md in carrierwave-cloudflare-0.2.0
- old
+ new
@@ -1,9 +1,11 @@
# Carrierwave::Cloudflare
This gem provides a simple wrapper for transformation images via Cloudflare
+
+
## Installation
Add this line to your application's Gemfile:
```ruby
@@ -26,27 +28,26 @@
class BaseUploader < CarrierWave::Uploader::Base
include CarrierWave::Cloudflare
end
```
+Use `cdn_transform` for define Cloudflare's version (this means that now the file will not be stored on the, but will be transformed on the cloudflare side)
-Define `virtual` version in some uploader:
```ruby
class AvatarUploader < BaseUploader
version(:medium) do
cdn_transform width: 100, height: 100, dpr: 2
end
end
-
-User.avatar.medium # CarrierWave::Uploader
-User.avatar.url # "https://s3.resume.io/users/avatar/1.jpg"
-User.avatar.medium_url # "https://s3.resume.io/cdn-cgi/.../users/avatar/1.jpg"
-User.avatar.medium.url # "https://s3.resume.io/cdn-cgi/.../users/avatar/1.jpg"
-User.avatar.url(:medium) # "https://s3.resume.io/cdn-cgi/.../users/avatar/1.jpg"
-User.avatar.medium.url(dpr: 1)
-User.avatar.resize(width: 1200, fit: :cover).url
+user = User.find(some_id)
+user.avatar.medium # CarrierWave::Uploader
+user.avatar.url # "https://s3.your-website.com/users/avatar/1.jpg"
+user.avatar.medium_url # "https://s3.your-website.com/cdn-cgi/width=100,height=100,dpr=2/users/avatar/1.jpg"
+user.avatar.url(:medium) # "https://s3.your-website.com/cdn-cgi/width=100,height=100,dpr=2/users/avatar/1.jpg"
+user.avatar.medium.url(dpr: 1) # "https://s3.your-website.com/cdn-cgi/width=100,height=100,dpr=1/users/avatar/1.jpg"
+user.avatar.resize(width: 1200, fit: :cover).url # "https://s3.your-website.com/cdn-cgi/width=1200,height=100,dpr=2,fit=cover/users/avatar/1.jpg"
```
### Options
Supported options:
@@ -61,23 +62,73 @@
class BaseUploader < CarrierWave::Uploader::Base
default_cdn_options format: :auto
end
```
-## Development
+### In development env
-After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
+In development, you don't need to generate URLs for Cloudflare, because they will not work and therefore you need to disable the Cloudflare transform
-To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
+``` ruby
+CarrierWave::Cloudflare.configure do |config|
+ config.cloudflare_transform(false)
+end
+```
-## Contributing
+`cloudflare_transform: false` disables links generation and put all Cloudflare's arguments into query string (for easy debugging)
-Bug reports and pull requests are welcome on GitHub at https://github.com/resume-io/carrierwave-cloudflare. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/resume-io/carrierwave-cloudflare/blob/master/CODE_OF_CONDUCT.md).
+e.g:
+```
+/1.jpg?cdn-cgi=width-11.height-300.fit-pad
+```
-## License
+## Rails views helpers
-The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
+### cdn_transformed(url, **options)
+Returns an image URL with CDN transformations applied. Can process already transformed URLs, in that case the options will be merged together.
-## Code of Conduct
+```ruby
+cdn_transformed('/img.jpg', width: 400)
+# => '/cdn-cgi/image/width=400/img.jpg'
-Everyone interacting in the Carrierwave::Cloudflare project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/resume-io/carrierwave-cloudflare/blob/master/CODE_OF_CONDUCT.md).
+cdn_transformed('/cdn-cgi/image/width=100,fit=pad/img.jpg', width: 333)
+# => '/cdn-cgi/image/width=333,fit=pad/img.jpg'
+```
+
+
+### hidpi_image_tag(url, dprs: nil, **options)
+
+Returns an image tag with with scaled variations (via `srcset`) attribute for devices with different DPR values.
+
+
+The transformation of the original image should be specified via options.
+
+```ruby
+hidpi_image_tag('/bird.jpg', width: 400, drps: [1, 2])
+# => <img srcset="/cdn-cgi/image/width=400,dpr=1/img.jpg 1x, /cdn-cgi/image/width=400,dpr=2/img.jpg 2x" src="/cdn-cgi/image/width=400/img.jpg" />
+```
+
+
+### responsive_image_tag(url, width:, sizes: nil, dprs: [1, 2], **options)
+
+Returns a reponsive image tag with variations.
+
+```ruby
+responsive_image_tag('/bird.jpg', width: 1200, sizes: { phone: 600, tablet: 800 })
+
+# => <img srcset="/cdn-cgi/image/width=1200,dpr=0.5/bird.jpg 600w,
+# /cdn-cgi/image/width=1200,dpr=1.0/bird.jpg 1200w,
+# /cdn-cgi/image/width=1200,dpr=0.67/bird.jpg 800w,
+# /cdn-cgi/image/width=1200,dpr=1.33/bird.jpg 1600w,
+# /cdn-cgi/image/width=1200,dpr=2.0/bird.jpg 2400w"
+# sizes="(max-width: 767px) 600px, (max-width: 1023px) 800px, 1200px"
+# src="/cdn-cgi/image/width=1200/bird.jpg" />
+
+```
+
+
+## Development
+
+After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
+
+To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).