imgix-rails 3.0.1 → 4.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: e71702fcfd1e0307fae20e59675b30066848d923
4
- data.tar.gz: 5af8395c4981ea8209cf7a7d3b27953d36e48b61
2
+ SHA256:
3
+ metadata.gz: c682a51cc9f6b4952378aaf8251177a68572a36c651cabc80cbf56ebcdeba202
4
+ data.tar.gz: d260ef47f9a0d781682a20454be249555a72d52563fa86c78a268859e38e92d9
5
5
  SHA512:
6
- metadata.gz: 02a723f03d26f1fc366c932f90a30d04a968846aeca3a1640568084d3eed675e3b5f2e83826ef085575dc0487105f3ca8134f021b2300173d2e22a2d54b0d315
7
- data.tar.gz: 6c4c787e319cafec5ee4d59fc4241cc782862fa3137cee444b1e21cc6330e0fd44587c65bc2f4bce363167c48253482ffae9d92c775a6a23c6dcb0929465566d
6
+ metadata.gz: 0a80c18902444132eff414886eab480d74a5fe8a9e4ea3b6acb86d4f6738fb6cc78638795d96cc2cb77a099c2c62bbeebffdf0f4136591acee1ef086cb0cd321
7
+ data.tar.gz: 8731178773e4d321511b2a73922b38b87156363ffcdf39d43fd1b56bf336c493d051d2c189e13e25e7c623cca7c0dddf532e35b267a5b1b85d63f6a50f1d7128
@@ -1,8 +1,6 @@
1
1
  language: ruby
2
- before_install:
3
- - rvm get head
4
2
  rvm:
5
3
  - 2.3.1
6
4
  - 2.2.5
7
- - jruby-9.0.5.0
5
+ - jruby
8
6
  script: bundle exec rspec
@@ -0,0 +1,36 @@
1
+ # Change Log
2
+
3
+ All notable changes to this project will be documented in this file.
4
+ This project adheres to [Semantic Versioning](http://semver.org/).
5
+
6
+ ## [4.0.2](https://github.com/imgix/imgix-rb/compare/4.0.1...4.0.2) - July 31, 2020
7
+ - fix: replace `opts[:host`] with `opts[:domain]` to resolve deprecation warnings ([#96](https://github.com/imgix/imgix-rails/pull/96))
8
+
9
+ ## [4.0.1](https://github.com/imgix/imgix-rb/compare/4.0.0...4.0.1) - June 10, 2020
10
+
11
+ - fix: update rake version ([#94](https://github.com/imgix/imgix-rails/pull/94))
12
+
13
+ ## [4.0.0](https://github.com/imgix/imgix-rb/compare/3.1.0...4.0.0) - December 03, 2019
14
+
15
+ The v4.0.0 release of imgix-rails introduces a variety of improvements relating to how this gem handles and generates `srcset` attributes. However, in releasing this version there are some significant interface/behavioral changes that users need to be aware of. Users should note that the `min_width` and `max_width` fields (passed via `tag_options`), as well as the `widths` field, have all been moved to their own encompassing `srcset_options` field. This is done with the intention of providing a more organized and intuitive experience when fine-tuning how `srcset` width pairs are generated. See the following example demonstrating this new pattern:
16
+
17
+ ```erb
18
+ <%= ix_image_tag('/unsplash/hotairballoon.jpg',
19
+ srcset_options: { min_width: 1000, max_width: 2500},
20
+ tag_options: { alt: 'A hot air balloon on a sunny day' }) %>
21
+ ```
22
+
23
+ For users migrating to version 4.0 or later, it is important that all srcset-related modifiers be passed via `srcset_options`, as doing so through `tag_options` or `widths` directly will result in errors. For more details on these modifiers, please see the [ix_image_tag](https://github.com/imgix/imgix-rails#ix_image_tag) or [ix_picture_tag](https://github.com/imgix/imgix-rails#ix_picture_tag) sections.
24
+
25
+ In addition to these changes, imgix-rails is now capable of producing [fixed-image srcsets](https://github.com/imgix/imgix-rb#fixed-image-rendering). Users should note that when certain dimension information is provided, imgix-rails will produce a `srcset` at different screen resolutions rather than the typical width pairs. This feature provides expanded functionality to cover more `srcset` use cases that users can take advantage of. We are always happy to provide our users with more tools to assist them in their efforts to build out responsive images on the web.
26
+
27
+ * feat: utilize Imgix::Path#to_srcset when constructing srcsets ([#83](https://github.com/imgix/imgix-rails/pull/83))
28
+ * chore: remove deprecated domain sharding behavior ([#80](https://github.com/imgix/imgix-rails/pull/80))
29
+ * fix: deprecate resizing height when maintaining aspect ratio ([#78](https://github.com/imgix/imgix-rails/pull/78))
30
+
31
+ ## [3.1.0](https://github.com/imgix/imgix-rb/compare/3.0.2...3.1.0) - October 25, 2019
32
+
33
+ * Update bundler dev dependency to include new major version 2.x ([#71](https://github.com/imgix/imgix-rb/pull/71))
34
+ * README: Fix typo ([#73](https://github.com/imgix/imgix-rb/pull/73))
35
+ * docs: add ActiveStorage instructions to README ([#74](https://github.com/imgix/imgix-rb/pull/74))
36
+ * chore(deprecate): emit warning when generating srcsets ([ccc906b](https://github.com/imgix/imgix-rails/commit/ccc906be749945f6f843b5eeb04ab03a292ccbfb)) ([e2ffc2b](https://github.com/imgix/imgix-rails/commit/e2ffc2b4f847c15ea73fa161b673885e704e4cf2))
data/README.md CHANGED
@@ -1,52 +1,58 @@
1
- [![imgix logo](https://assets.imgix.net/imgix-logo-web-2014.pdf?page=2&fm=png&w=200&h=200)](https://imgix.com)
1
+ <!-- ix-docs-ignore -->
2
+ ![imgix logo](https://assets.imgix.net/sdk-imgix-logo.svg)
3
+
4
+ `imgix-rails` is a gem for integrating [imgix](https://www.imgix.com/) into Ruby on Rails applications. It builds on [imgix-rb](https://github.com/imgix/imgix-rb) to offer a few Rails-specific interfaces.
5
+
6
+ [![Gem Version](https://img.shields.io/gem/v/imgix-rails.svg)](https://rubygems.org/gems/imgix-rails)
7
+ [![Build Status](https://travis-ci.org/imgix/imgix-rails.svg?branch=master)](https://travis-ci.org/imgix/imgix-rails)
8
+ ![Downloads](https://img.shields.io/gem/dt/imgix-rails)
9
+ [![License](https://img.shields.io/github/license/imgix/imgix-rails)](https://github.com/imgix/imgix-rails/blob/master/LICENSE)
10
+
11
+ ---
12
+ <!-- /ix-docs-ignore -->
13
+
14
+ - [Installation](#installation)
15
+ - [Usage](#usage)
16
+ - [Configuration](#configuration)
17
+ - [Multi-source configuration](#multi-source-configuration)
18
+ - [`ix_image_tag`](#iximagetag)
19
+ - [Fixed image rendering](#fixed-image-rendering)
20
+ - [`ix_picture_tag`](#ixpicturetag)
21
+ - [`ix_image_url`](#iximageurl)
22
+ - [Usage in Sprockets](#usage-in-sprockets)
23
+ - [Using With Image Uploading Libraries](#using-with-image-uploading-libraries)
24
+ - [Paperclip and CarrierWave](#paperclip-and-carrierwave)
25
+ - [Refile](#refile)
26
+ - [Active Storage](#active-storage)
27
+ - [Upgrade Guides](#upgrade-guides)
28
+ - [3.x to 4.0](#3x-to-40)
29
+ - [Development](#development)
30
+ - [Contributing](#contributing)
31
+ - [Code of Conduct](#code-of-conduct)
2
32
 
3
- # imgix-rails [![Build Status](https://travis-ci.org/imgix/imgix-rails.svg?branch=master)](https://travis-ci.org/imgix/imgix-rails)
4
-
5
- `imgix-rails` is a gem designed to make integrating imgix into your Rails app easier. It builds on [imgix-rb](https://github.com/imgix/imgix-rb) to offer a few Rails-specific interfaces.
6
-
7
- imgix is a real-time image processing service and CDN. It allows you to manipulate images merely by changing their URL parameters. For a full list of URL parameters, please see the [imgix URL API documentation](https://www.imgix.com/docs/reference).
8
-
9
- We recommend using something like [Paperclip](https://github.com/thoughtbot/paperclip), [Refile](https://github.com/refile/refile), [Carrierwave](https://github.com/carrierwaveuploader/carrierwave), or [s3_direct_upload](https://github.com/waynehoover/s3_direct_upload) to handle uploads. After they've been uploaded, you can then serve them using this gem.
10
-
11
- * [Installation](#installation)
12
- * [Usage](#usage)
13
- * [Configuration](#configuration)
14
- * [ix_image_tag](#ix_image_tag)
15
- * [ix_picture_tag](#ix_picture_tag)
16
- * [ix_image_url](#ix_image_url)
17
- * [Usage in Sprockets](#usage-in-sprockets)
18
- * [Using With Image Uploading Libraries](#using-with-image-uploading-libraries)
19
- * [Paperclip and CarrierWave](#paperclip-and-carrierwave)
20
- * [Refile](#refile)
21
- * [Development](#development)
22
- * [Contributing](#contributing)
23
-
24
-
25
- <a name="installation"></a>
26
33
  ## Installation
27
34
 
28
35
  Add this line to your application's Gemfile:
29
36
 
30
- ```ruby
37
+ ```rb
31
38
  gem 'imgix-rails'
32
39
  ```
33
40
 
34
41
  And then execute:
35
42
 
36
- $ bundle
37
-
43
+ ```bash
44
+ $ bundle
45
+ ```
38
46
 
39
- <a name="usage"></a>
40
47
  ## Usage
41
48
 
42
49
  imgix-rails provides a few different hooks to work with your existing Rails application. All current methods are drop-in replacements for the `image_tag` helper.
43
50
 
44
- <a name="configuration"></a>
45
51
  ### Configuration
46
52
 
47
53
  Before you get started, you will need to define your imgix configuration in your `config/application.rb`, or in an environment-specific configuration file.
48
54
 
49
- ```ruby
55
+ ```rb
50
56
  Rails.application.configure do
51
57
  config.imgix = {
52
58
  source: "assets.imgix.net"
@@ -56,22 +62,22 @@ end
56
62
 
57
63
  The following configuration flags will be respected:
58
64
 
59
- - `:use_https` toggles the use of HTTPS. Defaults to `true`
60
- - `:source` a String or Array that specifies the imgix Source address. Should be in the form of `"assets.imgix.net"`.
61
- - `:srcset_width_tolerance` an optional numeric value determining the maximum tolerance allowable, between the downloaded dimensions and rendered dimensions of the image (default `.08` i.e. `8%`).
62
- - `:secure_url_token` an optional secure URL token found in your dashboard (https://dashboard.imgix.com) used for signing requests
63
- - `:shard_strategy` Specify [domain sharding strategy](https://github.com/imgix/imgix-rb#domain-sharded-urls) with multiple sources. Acceptable values are `:cycle` and `:crc`. `:crc` is used by default.
65
+ - `use_https`: toggles the use of HTTPS. Defaults to `true`
66
+ - `source`: a String or Array that specifies the imgix Source address. Should be in the form of `"assets.imgix.net"`.
67
+ - `srcset_width_tolerance`: an optional numeric value determining the maximum tolerance allowable, between the downloaded dimensions and rendered dimensions of the image (default `0.08` i.e. `8%`).
68
+ - `secure_url_token`: an optional secure URL token found in your dashboard (https://dashboard.imgix.com) used for signing requests
69
+ - `include_library_param`: toggles the inclusion of the [`ixlib` parameter](https://github.com/imgix/imgix-rb#what-is-the-ixlib-param-on-every-request). Defaults to `true`.
64
70
 
65
71
  #### Multi-source configuration
66
72
 
67
73
  In addition to the standard configuration flags, the following options can be used for multi-source support.
68
74
 
69
- - `:sources` a Hash of imgix source-secure_url_token key-value pairs. If the value for a source is `nil`, URLs generated for the corresponding source won't be secured. `:sources` and `:source` *cannot* be used together.
70
- - `:default_source` optionally specify a default source for generating URLs.
75
+ - `sources`: a Hash of imgix source-secure_url_token key-value pairs. If the value for a source is `nil`, URLs generated for the corresponding source won't be secured. `sources` and `source` *cannot* be used together.
76
+ - `default_source`: optionally specify a default source for generating URLs.
71
77
 
72
78
  Example:
73
79
 
74
- ```ruby
80
+ ```rb
75
81
  Rails.application.configure do
76
82
  config.imgix = {
77
83
  sources: {
@@ -83,19 +89,23 @@ Rails.application.configure do
83
89
  end
84
90
  ```
85
91
 
86
- <a name="ix_image_tag"></a>
87
- ### ix_image_tag
92
+ ### `ix_image_tag`
88
93
 
89
- The `ix_image_tag` helper method makes it easy to pass parameters to imgix to handle resizing, cropping, etc. It also simplifies adding responsive imagery to your Rails app by automatically generating a `srcset` based on the parameters you pass. We talk a bit about using the `srcset` attribute in an application in the following blog post: [“Responsive Images with `srcset` and imgix.”](https://blog.imgix.com/2015/08/18/responsive-images-with-srcset-imgix.html).
94
+ The `ix_image_tag` helper method makes it easy to pass parameters to imgix to handle resizing, cropping, etc. It also simplifies adding responsive imagery to your Rails app by automatically generating a `srcset` based on the parameters you pass. We talk a bit about using the `srcset` attribute in an application in the following blog post: [“Responsive Images with `srcset` and imgix.”](https://docs.imgix.com/tutorials/responsive-images-srcset-imgix?_ga=utm_medium=referral&utm_source=sdk&utm_campaign=rails-readme).
90
95
 
91
- `ix_image_tag` generates `<img>` tags with a filled-out `srcset` attribute that leans on imgix to do the hard work. If you already know the minimum or maximum number of physical pixels that this image will need to be displayed at, you can pass the `min_width` and/or `max_width` options. This will result in a smaller, more tailored `srcset`.
96
+ `ix_image_tag` generates `<img>` tags with a filled-out `srcset` attribute that leans on [imgix-rb](https://github.com/imgix/imgix-rb) to do the hard work. It also makes a variety of options available for customizing how the `srcset` is generated. For example, if you already know the minimum or maximum number of physical pixels that this image will need to be displayed at, you can pass the `min_width` and/or `max_width` options. This will result in a smaller, more tailored `srcset`.
92
97
 
93
98
  `ix_image_tag` takes the following arguments:
94
99
 
95
- * `source`: an optional String indicating the source to be used. If unspecified `:source` or `:default_source` will be used. If specified, the value must be defined in the config.
100
+ * `source`: An optional String indicating the source to be used. If unspecified `:source` or `:default_source` will be used. If specified, the value must be defined in the config.
96
101
  * `path`: The path or URL of the image to display.
97
- * `tag_options`: Any options to apply to the generated `img` element. This is useful for adding class names, etc.
102
+ * `tag_options`: HTML attributes to apply to the generated `img` element. This is useful for adding class names, alt tags, etc.
98
103
  * `url_params`: The imgix URL parameters to apply to this image. These will be applied to each URL in the `srcset` attribute, as well as the fallback `src` attribute.
104
+ * `srcset_options`: A variety of options that allow for fine tuning `srcset` generation. More information on each of these modifiers can be found in the [imgix-rb documentation](https://github.com/imgix/imgix-rb#srcset-generation). Any of the following can be passed as arguments:
105
+ * [`widths`](https://github.com/imgix/imgix-rb#custom-widths): An array of exact widths that `srcset` pairs will be generated with.
106
+ * [`min_width`](https://github.com/imgix/imgix-rb#minimum-and-maximum-width-ranges): The minimum width that `srcset` pairs will be generated with. Will be ignored if `widths` are provided.
107
+ * [`max_width`](https://github.com/imgix/imgix-rb#minimum-and-maximum-width-ranges): The maximum width that `srcset` pairs will be generated with. Will be ignored if `widths` are provided.
108
+ * [`disable_variable_quality`](https://github.com/imgix/imgix-rb#variable-qualities): Pass `true` to disable variable quality parameters when generating a `srcset` ([fixed-images only](https://github.com/imgix/imgix-rails#fixed-image-rendering)). In addition, imgix-rails will respect an overriding `q` (quality) parameter if one is provided through `url_params`.
99
109
 
100
110
  ```erb
101
111
  <%= ix_image_tag('/unsplash/hotairballoon.jpg', url_params: { w: 300, h: 500, fit: 'crop', crop: 'right'}, tag_options: { alt: 'A hot air balloon on a sunny day' }) %>
@@ -127,7 +137,7 @@ Will generate URLs using `assets2.imgix.net` source.
127
137
 
128
138
  We recommend leveraging this to generate powerful helpers within your application like the following:
129
139
 
130
- ```ruby
140
+ ```rb
131
141
  def profile_image_tag(user)
132
142
  ix_image_tag(user.profile_image_url, url_params: { w: 100, h: 200, fit: 'crop' })
133
143
  end
@@ -142,12 +152,30 @@ Then rendering the portrait in your application is very easy:
142
152
  If you already know all the exact widths you need images for, you can specify that by passing the `widths` option as an array. In this case, imgix-rails will only generate `srcset` pairs for the specified `widths`.
143
153
 
144
154
  ```erb
145
- <%= ix_image_tag('/unsplash/hotairballoon.jpg', widths: [320, 640, 960, 1280], url_params: { w: 300, h: 500, fit: 'crop', crop: 'right'}, tag_options: { alt: 'A hot air balloon on a sunny day' }) %>
155
+ <%= ix_image_tag('/unsplash/hotairballoon.jpg', srcset_options: { widths: [320, 640, 960, 1280] }, tag_options: { alt: 'A hot air balloon on a sunny day' }) %>
146
156
  ```
147
157
 
158
+ #### Fixed image rendering
159
+
160
+ In cases where enough information is provided about an image's dimensions, `ix_image_tag` will instead build a `srcset` that will allow for an image to be served at different resolutions. The parameters taken into consideration when determining if an image is fixed-width are `w`, `h`, and `ar`. By invoking `ix_image_tag` with either a width or the height and aspect ratio (along with `fit=crop`, typically) provided, a different srcset will be generated for a fixed-size image instead.
161
+
162
+ ```erb
163
+ <%= ix_image_tag('/unsplash/hotairballoon.jpg', url_params: {w: 1000}) %>
164
+ ```
148
165
 
149
- <a name="ix_picture_tag"></a>
150
- ### ix_picture_tag
166
+ Will render the following HTML:
167
+
168
+ ```html
169
+ <img srcset="https://assets.imgix.net/image.jpg?ixlib=rails-3.0.2&amp;w=1000&amp;dpr=1&amp;q=75 1x,
170
+ https://assets.imgix.net/image.jpg?ixlib=rails-3.0.2&amp;w=1000&amp;dpr=2&amp;q=50 2x,
171
+ https://assets.imgix.net/image.jpg?ixlib=rails-3.0.2&amp;w=1000&amp;dpr=3&amp;q=35 3x,
172
+ https://assets.imgix.net/image.jpg?ixlib=rails-3.0.2&amp;w=1000&amp;dpr=4&amp;q=23 4x,
173
+ https://assets.imgix.net/image.jpg?ixlib=rails-3.0.2&amp;w=1000&amp;dpr=5&amp;q=20 5x" sizes="100vw" src="https://assets.imgix.net/image.jpg?ixlib=rails-3.0.2&amp;w=1000">
174
+ ```
175
+
176
+ Fixed image rendering will automatically append a variable `q` parameter mapped to each `dpr` parameter when generating a `srcset`. This technique is commonly used to compensate for the increased filesize of high-DPR images. Since high-DPR images are displayed at a higher pixel density on devices, image quality can be lowered to reduce overall filesize without sacrificing perceived visual quality. For more information and examples of this technique in action, see [this blog post](https://blog.imgix.com/2016/03/30/dpr-quality?_ga=utm_medium=referral&utm_source=sdk&utm_campaign=rails-readme). This behavior will respect any overriding `q` value passed in via `url_params` and can be disabled altogether with `srcset_options: { disable_variable_quality: true }`.
177
+
178
+ ### `ix_picture_tag`
151
179
 
152
180
  The `ix_picture_tag` helper method makes it easy to generate `picture` elements in your Rails app. `picture` elements are useful when an images needs to be art directed differently at different screen sizes.
153
181
 
@@ -158,6 +186,11 @@ The `ix_picture_tag` helper method makes it easy to generate `picture` elements
158
186
  * `tag_options`: Any options to apply to the parent `picture` element. This is useful for adding class names, etc.
159
187
  * `url_params`: Default imgix options. These will be used to generate a fallback `img` tag for older browsers, and used in each `source` unless overridden by `breakpoints`.
160
188
  * `breakpoints`: A hash describing the variants. Each key must be a media query (e.g. `(max-width: 880px)`), and each value must be a hash of parameter overrides for that media query. A `source` element will be generated for each breakpoint specified.
189
+ * `srcset_options`: A variety of options that allow for fine tuning `srcset` generation. More information on each of these modifiers can be found in the [imgix-rb documentation](https://github.com/imgix/imgix-rb#srcset-generation). Any of the following can be passed as arguments:
190
+ * [`widths`](https://github.com/imgix/imgix-rb#custom-widths): An array of exact widths that `srcset` pairs will be generated with.
191
+ * [`min_width`](https://github.com/imgix/imgix-rb#minimum-and-maximum-width-ranges): The minimum width that `srcset` pairs will be generated with. Will be ignored if `widths` are provided.
192
+ * [`max_width`](https://github.com/imgix/imgix-rb#minimum-and-maximum-width-ranges): The maximum width that `srcset` pairs will be generated with. Will be ignored if `widths` are provided.
193
+ * [`disable_variable_quality`](https://github.com/imgix/imgix-rb#variable-qualities): Pass `true` to disable variable quality parameters when generating a `srcset` ([fixed-images only](https://github.com/imgix/imgix-rails#fixed-image-rendering)). In addition, imgix-rails will respect an overriding `q` (quality) parameter if one is provided through `url_params`.
161
194
 
162
195
  ```erb
163
196
  <%= ix_picture_tag('bertandernie.jpg',
@@ -213,8 +246,7 @@ To generate a `picture` element on a different source:
213
246
  ) %>
214
247
  ```
215
248
 
216
- <a name="ix_image_url"></a>
217
- ### ix_image_url
249
+ ### `ix_image_url`
218
250
 
219
251
  The `ix_image_url` helper makes it easy to generate a URL to an image in your Rails app.
220
252
 
@@ -238,17 +270,16 @@ https://assets2.imgix.net/users/1/avatar.png?w=400&h=300
238
270
 
239
271
  Since `ix_image_url` lives inside `UrlHelper`, it can also be used in places other than your views quite easily. This is useful for things such as including imgix URLs in JSON output from a serializer class.
240
272
 
241
- ```ruby
273
+ ```rb
242
274
  include Imgix::Rails::UrlHelper
243
275
 
244
276
  puts ix_image_url('/users/1/avatar.png', { w: 400, h: 300 })
245
277
  # => https://assets.imgix.net/users/1/avatar.png?w=400&h=300
246
278
  ```
247
279
 
248
- <a name="usage-in-sprockets"></a>
249
280
  #### Usage in Sprockets
250
281
 
251
- `ix_image_url` is also pulled in as a Sprockets helper, so you can generate imgix URLs in your asset pipline files. For example, here's how it would work inside an `.scss.erb` file:
282
+ `ix_image_url` is also pulled in as a Sprockets helper, so you can generate imgix URLs in your asset pipeline files. For example, here's how it would work inside an `.scss.erb` file:
252
283
 
253
284
  ```scss
254
285
  .something {
@@ -256,13 +287,10 @@ puts ix_image_url('/users/1/avatar.png', { w: 400, h: 300 })
256
287
  }
257
288
  ```
258
289
 
259
- <a name="using-with-image-uploading-libraries"></a>
260
290
  ## Using With Image Uploading Libraries
261
291
 
262
292
  imgix-rails plays well with image uploading libraries, because it just requires a URL and optional parameters as arguments. A good way to handle this interaction is by creating helpers that bridge between your uploading library of choice and imgix-rails. Below are examples of how this can work with some common libraries. Please submit an issue if you'd like to see specific examples for another!
263
293
 
264
-
265
- <a name="paperclip-and-carrierwave"></a>
266
294
  ### Paperclip and CarrierWave
267
295
 
268
296
  Paperclip and CarrierWave can directly provide paths to uploaded images, so we can use them with imgix-rails without a bridge.
@@ -271,8 +299,6 @@ Paperclip and CarrierWave can directly provide paths to uploaded images, so we c
271
299
  <%= ix_image_tag(@user.avatar.path, { auto: 'format', fit: 'crop', w: 500}) %>
272
300
  ```
273
301
 
274
-
275
- <a name="refile"></a>
276
302
  ### Refile
277
303
 
278
304
  Since Refile doesn't actually store URLs or paths in the database (instead using a "prefix" + image identifier), the basic setup is slightly different. In this case, we use a couple helpers that bridge between Refile and imgix-rails.
@@ -303,16 +329,72 @@ end
303
329
  <%= ix_refile_image_tag(@blog_post, :hero_photo, {auto: 'format', fit: 'crop', w: 500}) %>
304
330
  ```
305
331
 
332
+ ### Active Storage
333
+
334
+ To set up imgix with ActiveStorage, first ensure that the remote source your ActiveStorage service is pointing to is the same as your imgix source — such as an s3 bucket.
335
+
336
+ **config/storage.yml**
337
+
338
+ ```yml
339
+ service: S3
340
+ access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %>
341
+ secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %>
342
+ region: us-east-1
343
+ bucket: your_own_bucket
344
+ ```
345
+
346
+ Modify your active_storage.service setting depending on what environment you are using. For example, to use Amazon s3 in production, make the following change:
347
+
348
+ **config/environments/production.rb**
349
+
350
+ ```rb
351
+ config.active_storage.service = :amazon
352
+ ```
353
+
354
+ As you would normally with imgix-rails, configure your application to point to your imgix source:
355
+
356
+ **config/application.rb**
357
+
358
+ ```rb
359
+ Rails.application.configure do
360
+ config.imgix = {
361
+ source: your_domain,
362
+ use_https: true,
363
+ include_library_param: true
364
+ }
365
+ end
366
+ ```
367
+
368
+ Finally, the two can be used together by passing in the filename of the ActiveStorage blob into the imgix-rails helper function:
369
+
370
+ **show.html.erb**
371
+
372
+ ```erb
373
+ <%= ix_image_tag(@your_model.image.key) %>
374
+ ```
375
+
376
+ ## Upgrade Guides
377
+
378
+ ### 3.x to 4.0
379
+
380
+ The v4.0.0 release of imgix-rails introduces a variety of improvements relating to how this gem handles and generates `srcset` attributes. However, in releasing this version there are some significant interface/behavioral changes that users need to be aware of. Users should note that the `min_width` and `max_width` fields (passed via `tag_options`), as well as the `widths` field, have all been moved to their own encompassing `srcset_options` field. This is done with the intention of providing a more organized and intuitive experience when fine-tuning how `srcset` width pairs are generated. See the following example demonstrating this new pattern:
381
+
382
+ ```erb
383
+ <%= ix_image_tag('/unsplash/hotairballoon.jpg',
384
+ srcset_options: { min_width: 1000, max_width: 2500},
385
+ tag_options: { alt: 'A hot air balloon on a sunny day' }) %>
386
+ ```
387
+
388
+ For users migrating to version 4.0 or later, it is important that all srcset-related modifiers be passed via `srcset_options`, as doing so through `tag_options` or `widths` directly will result in errors. For more details on these modifiers, please see the [ix_image_tag](https://github.com/imgix/imgix-rails#ix_image_tag) or [ix_picture_tag](https://github.com/imgix/imgix-rails#ix_picture_tag) sections.
389
+
390
+ In addition to these changes, imgix-rails is now capable of producing [fixed-image srcsets](https://github.com/imgix/imgix-rb#fixed-image-rendering). Users should note that when certain dimension information is provided, imgix-rails will produce a `srcset` at different screen resolutions rather than the typical width pairs. This feature provides expanded functionality to cover more `srcset` use cases that users can take advantage of. We are always happy to provide our users with more tools to assist them in their efforts to build out responsive images on the web.
306
391
 
307
- <a name="development"></a>
308
392
  ## Development
309
393
 
310
394
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
311
395
 
312
396
  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` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
313
397
 
314
-
315
- <a name="contributing"></a>
316
398
  ## Contributing
317
399
 
318
400
  1. Fork it ( https://github.com/[my-github-username]/imgix-rails/fork )
@@ -14,6 +14,12 @@ Gem::Specification.new do |spec|
14
14
  spec.description = %q{Makes integrating imgix into your Rails app easier. It builds on imgix-rb to offer a few Rails-specific interfaces. Please see https://github.com/imgix/imgix-rails for more details.}
15
15
  spec.homepage = "https://github.com/imgix/imgix-rails"
16
16
 
17
+ spec.metadata = {
18
+ 'bug_tracker_uri' => 'https://github.com/imgix/imgix-rails/issues',
19
+ 'changelog_uri' => 'https://github.com/imgix/imgix-rails/blob/master/CHANGELOG.md',
20
+ 'documentation_uri' => "https://www.rubydoc.info/gems/imgix-rails/#{spec.version}",
21
+ 'source_code_uri' => "https://github.com/imgix/imgix-rails/tree/v#{spec.version}"
22
+ }
17
23
  # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
24
  # delete this section to allow pushing this gem to any host.
19
25
  if spec.respond_to?(:metadata)
@@ -27,10 +33,10 @@ Gem::Specification.new do |spec|
27
33
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
34
  spec.require_paths = ["lib"]
29
35
 
30
- spec.add_runtime_dependency "imgix", "~> 1.1", ">= 1.1.0"
36
+ spec.add_runtime_dependency "imgix", "~> 3.0"
31
37
 
32
- spec.add_development_dependency "bundler", "~> 1.9"
33
- spec.add_development_dependency "rake", "~> 10.0"
38
+ spec.add_development_dependency "bundler", ">=1.9"
39
+ spec.add_development_dependency "rake", "~> 12.3"
34
40
  spec.add_development_dependency "rspec"
35
41
  spec.add_development_dependency "rspec-rails"
36
42
  end
@@ -8,7 +8,6 @@ require "active_support"
8
8
 
9
9
  module Imgix
10
10
  module Rails
11
- STRATEGIES = [:crc, :cycle]
12
11
  class Config < ::ActiveSupport::OrderedOptions; end
13
12
 
14
13
  def self.config
@@ -1,35 +1,42 @@
1
1
  require "imgix/rails/tag"
2
2
  require "imgix/rails/image_tag"
3
+ require "action_view"
3
4
 
4
5
  class Imgix::Rails::PictureTag < Imgix::Rails::Tag
5
6
  include ActionView::Context
6
7
 
7
- def initialize(path, source: nil, tag_options: {}, url_params: {}, breakpoints: {}, widths: [])
8
+ def initialize(path, source: nil, tag_options: {}, url_params: {}, breakpoints: {}, srcset_options: {})
8
9
  @path = path
9
10
  @source = source
10
11
  @tag_options = tag_options
11
12
  @url_params = url_params
12
13
  @breakpoints = breakpoints
13
- @widths = widths.length > 0 ? widths : target_widths
14
+ @srcset_options = srcset_options
14
15
  end
15
16
 
16
17
  def render
17
18
  content_tag(:picture, @tag_options) do
18
19
  @breakpoints.each do |media, opts|
20
+ validate_opts(opts)
21
+
19
22
  source_tag_opts = opts[:tag_options] || {}
20
23
  source_tag_url_params = opts[:url_params] || {}
21
- widths = opts[:widths]
22
- unsupported_opts = opts.except(:tag_options, :url_params, :widths)
23
- if unsupported_opts.length > 0
24
- raise "'#{unsupported_opts.keys.join("', '")}' key(s) not supported; use tag_options, url_params, widths."
25
- end
26
-
24
+ srcset_options = opts[:srcset_options] || {}
27
25
  source_tag_opts[:media] ||= media
28
- source_tag_opts[:srcset] ||= srcset(url_params: @url_params.clone.merge(source_tag_url_params), widths: widths)
26
+ source_tag_opts[:srcset] ||= srcset(url_params: @url_params.clone.merge(source_tag_url_params), srcset_options: srcset_options)
27
+
29
28
  concat(content_tag(:source, nil, source_tag_opts))
30
29
  end
31
30
 
32
- concat Imgix::Rails::ImageTag.new(@path, source: @source, url_params: @url_params).render
31
+ concat Imgix::Rails::ImageTag.new(@path, source: @source, url_params: @url_params, srcset_options: @srcset_options).render
33
32
  end
34
33
  end
34
+
35
+ private
36
+ def validate_opts(opts = {})
37
+ unsupported_opts = opts.except(:tag_options, :url_params, :srcset_options)
38
+ if unsupported_opts.length > 0
39
+ raise "'#{unsupported_opts.keys.join("', '")}' key(s) not supported; use tag_options, url_params, srcset_options."
40
+ end
41
+ end
35
42
  end
@@ -1,81 +1,30 @@
1
1
  require "imgix/rails/url_helper"
2
+ require "action_view"
2
3
 
3
4
  class Imgix::Rails::Tag
4
5
  include Imgix::Rails::UrlHelper
5
6
  include ActionView::Helpers
6
7
 
7
- def initialize(path, source: nil, tag_options: {}, url_params: {}, widths: [])
8
+ def initialize(path, source: nil, tag_options: {}, url_params: {}, srcset_options: {})
8
9
  @path = path
9
10
  @source = source
10
11
  @tag_options = tag_options
11
12
  @url_params = url_params
12
- @widths = widths.length > 0 ? widths : target_widths
13
+ @srcset_options = srcset_options
13
14
  end
14
15
 
15
16
  protected
16
17
 
17
- def srcset(url_params: @url_params, widths: @widths)
18
- widths = widths || target_widths
18
+ def srcset(source: @source, path: @path, url_params: @url_params, srcset_options: @srcset_options, tag_options: @tag_options)
19
+ params = url_params.clone
19
20
 
20
- srcset_url_params = url_params.clone
21
- srcsetvalue = widths.map do |width|
22
- srcset_url_params[:w] = width
21
+ width_tolerance = ::Imgix::Rails.config.imgix[:srcset_width_tolerance]
22
+ min_width = @srcset_options[:min_width]
23
+ max_width = @srcset_options[:max_width]
24
+ widths = @srcset_options[:widths]
25
+ disable_variable_quality = @srcset_options[:disable_variable_quality]
26
+ options = { widths: widths, width_tolerance: width_tolerance, min_width: min_width, max_width: max_width, disable_variable_quality: disable_variable_quality}
23
27
 
24
- if url_params[:w].present? && url_params[:h].present?
25
- srcset_url_params[:h] = (width * (url_params[:h].to_f / url_params[:w])).round
26
- end
27
-
28
- "#{ix_image_url(@source, @path, srcset_url_params)} #{width}w"
29
- end.join(', ')
30
-
31
- srcsetvalue += ", #{ix_image_url(@source, @path, srcset_url_params.except(:w, :h))}"
32
- end
33
-
34
- @@standard_widths = nil
35
-
36
- def compute_standard_widths
37
- tolerance = ::Imgix::Rails.config.imgix[:srcset_width_tolerance] || SRCSET_TOLERANCE
38
- prev = MINIMUM_SCREEN_WIDTH
39
- widths = []
40
- while prev <= MAXIMUM_SCREEN_WIDTH do
41
- widths.append(2 * (prev/2).round) # Ensure widths are even
42
- prev = prev * (1 + tolerance*2.0)
43
- end
44
-
45
- widths
46
- end
47
-
48
- def standard_widths
49
- return @@standard_widths if @@standard_widths
50
-
51
- @@standard_widths = compute_standard_widths
52
- @@standard_widths.freeze
53
-
54
- @@standard_widths
55
- end
56
-
57
- private
58
-
59
- MINIMUM_SCREEN_WIDTH = 100
60
- MAXIMUM_SCREEN_WIDTH = 8192 # Maximum width supported by imgix
61
- SRCSET_TOLERANCE = 0.08
62
-
63
- # Return the widths to generate given the input `sizes`
64
- # attribute.
65
- #
66
- # @return {Array} An array of {Fixnum} instances representing the unique `srcset` URLs to generate.
67
- def target_widths
68
- min_width = @tag_options[:min_width]
69
- max_width = @tag_options[:max_width]
70
- if min_width || max_width
71
- min_width = min_width || MINIMUM_SCREEN_WIDTH
72
- max_width = max_width || MAXIMUM_SCREEN_WIDTH
73
- widths = standard_widths.select { |w| min_width <= w && w <= max_width }
74
- else
75
- widths = standard_widths
76
- end
77
-
78
- widths
28
+ ix_image_srcset(@source, @path, params, options)
79
29
  end
80
-
81
30
  end
@@ -10,28 +10,65 @@ module Imgix
10
10
  when 1
11
11
  path = args[0]
12
12
  source = nil
13
- options = {}
13
+ params = {}
14
14
  when 2
15
15
  if args[0].is_a?(String) && args[1].is_a?(Hash)
16
16
  source = nil
17
17
  path = args[0]
18
- options = args[1]
18
+ params = args[1]
19
19
  elsif args[0].is_a?(String) && args[1].is_a?(String)
20
20
  source = args[0]
21
21
  path = args[1]
22
- options = {}
22
+ params = {}
23
23
  else
24
- raise RuntimeError.new("path and source must be of type String; options must be of type Hash")
24
+ raise RuntimeError.new("path and source must be of type String; params must be of type Hash")
25
25
  end
26
26
  when 3
27
27
  source = args[0]
28
28
  path = args[1]
29
- options = args[2]
29
+ params = args[2]
30
30
  else
31
31
  raise RuntimeError.new('path missing')
32
32
  end
33
33
 
34
- imgix_client(source).path(path).to_url(options).html_safe
34
+ imgix_client(source).path(path).to_url(params).html_safe
35
+ end
36
+
37
+ protected
38
+
39
+ def ix_image_srcset(*args)
40
+ validate_configuration!
41
+
42
+ case args.size
43
+ when 1
44
+ path = args[0]
45
+ source = nil
46
+ params = {}
47
+ when 2
48
+ if args[0].is_a?(String) && args[1].is_a?(Hash)
49
+ source = nil
50
+ path = args[0]
51
+ params = args[1]
52
+ elsif args[0].is_a?(String) && args[1].is_a?(String)
53
+ source = args[0]
54
+ path = args[1]
55
+ params = {}
56
+ else
57
+ raise RuntimeError.new("path and source must be of type String; params must be of type Hash")
58
+ end
59
+ when 3
60
+ source = args[0]
61
+ path = args[1]
62
+ params = args[2]
63
+ when 4
64
+ source = args[0]
65
+ path = args[1]
66
+ params = args[2]
67
+ options = args[3]
68
+ else
69
+ raise RuntimeError.new('path missing')
70
+ end
71
+ imgix_client(source).path(path).to_srcset(options: options, **params).html_safe
35
72
  end
36
73
 
37
74
  private
@@ -44,8 +81,8 @@ module Imgix
44
81
  end
45
82
 
46
83
  if imgix[:source]
47
- unless imgix[:source].is_a?(Array) || imgix[:source].is_a?(String)
48
- raise ConfigurationError.new("imgix source must be a String or an Array.")
84
+ unless imgix[:source].is_a?(String)
85
+ raise ConfigurationError.new("imgix source must be a String.")
49
86
  end
50
87
  end
51
88
 
@@ -54,10 +91,6 @@ module Imgix
54
91
  raise ConfigurationError.new(":sources must be a Hash")
55
92
  end
56
93
  end
57
-
58
- unless !imgix.key?(:shard_strategy) || STRATEGIES.include?(imgix[:shard_strategy])
59
- raise ConfigurationError.new("#{imgix[:shard_strategy]} is not supported")
60
- end
61
94
  end
62
95
 
63
96
  def imgix_client(source)
@@ -79,9 +112,7 @@ module Imgix
79
112
  }
80
113
 
81
114
  if imgix[:source].is_a?(String)
82
- opts[:host] = imgix[:source]
83
- else
84
- opts[:hosts] = imgix[:source]
115
+ opts[:domain] = imgix[:source]
85
116
  end
86
117
 
87
118
  if imgix.has_key?(:include_library_param)
@@ -92,15 +123,11 @@ module Imgix
92
123
  opts[:use_https] = imgix[:use_https]
93
124
  end
94
125
 
95
- if imgix.has_key?(:shard_strategy)
96
- opts[:shard_strategy] = imgix[:shard_strategy]
97
- end
98
-
99
126
  sources = imgix[:sources] || { imgix[:source] => imgix[:secure_url_token] }
100
127
  @imgix_clients = {}
101
128
 
102
129
  sources.map do |source, token|
103
- opts[:host] = source
130
+ opts[:domain] = source
104
131
  opts[:secure_url_token] = token
105
132
  @imgix_clients[source] = ::Imgix::Client.new(opts)
106
133
  end
@@ -1,5 +1,5 @@
1
1
  module Imgix
2
2
  module Rails
3
- VERSION = '3.0.1'
3
+ VERSION = '4.0.2'
4
4
  end
5
5
  end
@@ -8,12 +8,12 @@ module Imgix
8
8
  module ViewHelper
9
9
  include UrlHelper
10
10
 
11
- def ix_image_tag(source=nil, path, tag_options: {}, url_params: {}, widths: [])
12
- return Imgix::Rails::ImageTag.new(path, source: source, tag_options: tag_options, url_params: url_params, widths: widths).render
11
+ def ix_image_tag(source=nil, path, tag_options: {}, url_params: {}, srcset_options: {})
12
+ return Imgix::Rails::ImageTag.new(path, source: source, tag_options: tag_options, url_params: url_params, srcset_options: srcset_options).render
13
13
  end
14
14
 
15
- def ix_picture_tag(source=nil, path, tag_options: {}, url_params: {}, breakpoints: {}, widths: [])
16
- return Imgix::Rails::PictureTag.new(path, source: source, tag_options: tag_options, url_params: url_params, breakpoints: breakpoints, widths: widths).render
15
+ def ix_picture_tag(source=nil, path, tag_options: {}, url_params: {}, breakpoints: {}, srcset_options: {})
16
+ return Imgix::Rails::PictureTag.new(path, source: source, tag_options: tag_options, url_params: url_params, breakpoints: breakpoints, srcset_options: srcset_options).render
17
17
  end
18
18
  end
19
19
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: imgix-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.1
4
+ version: 4.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kelly Sutton
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2018-10-30 00:00:00.000000000 Z
12
+ date: 2020-08-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: imgix
@@ -17,32 +17,26 @@ dependencies:
17
17
  requirements:
18
18
  - - "~>"
19
19
  - !ruby/object:Gem::Version
20
- version: '1.1'
21
- - - ">="
22
- - !ruby/object:Gem::Version
23
- version: 1.1.0
20
+ version: '3.0'
24
21
  type: :runtime
25
22
  prerelease: false
26
23
  version_requirements: !ruby/object:Gem::Requirement
27
24
  requirements:
28
25
  - - "~>"
29
26
  - !ruby/object:Gem::Version
30
- version: '1.1'
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: 1.1.0
27
+ version: '3.0'
34
28
  - !ruby/object:Gem::Dependency
35
29
  name: bundler
36
30
  requirement: !ruby/object:Gem::Requirement
37
31
  requirements:
38
- - - "~>"
32
+ - - ">="
39
33
  - !ruby/object:Gem::Version
40
34
  version: '1.9'
41
35
  type: :development
42
36
  prerelease: false
43
37
  version_requirements: !ruby/object:Gem::Requirement
44
38
  requirements:
45
- - - "~>"
39
+ - - ">="
46
40
  - !ruby/object:Gem::Version
47
41
  version: '1.9'
48
42
  - !ruby/object:Gem::Dependency
@@ -51,14 +45,14 @@ dependencies:
51
45
  requirements:
52
46
  - - "~>"
53
47
  - !ruby/object:Gem::Version
54
- version: '10.0'
48
+ version: '12.3'
55
49
  type: :development
56
50
  prerelease: false
57
51
  version_requirements: !ruby/object:Gem::Requirement
58
52
  requirements:
59
53
  - - "~>"
60
54
  - !ruby/object:Gem::Version
61
- version: '10.0'
55
+ version: '12.3'
62
56
  - !ruby/object:Gem::Dependency
63
57
  name: rspec
64
58
  requirement: !ruby/object:Gem::Requirement
@@ -100,6 +94,7 @@ files:
100
94
  - ".gitignore"
101
95
  - ".rspec"
102
96
  - ".travis.yml"
97
+ - CHANGELOG.md
103
98
  - Gemfile
104
99
  - LICENSE
105
100
  - README.md
@@ -119,6 +114,10 @@ homepage: https://github.com/imgix/imgix-rails
119
114
  licenses:
120
115
  - BSD-2-Clause
121
116
  metadata:
117
+ bug_tracker_uri: https://github.com/imgix/imgix-rails/issues
118
+ changelog_uri: https://github.com/imgix/imgix-rails/blob/master/CHANGELOG.md
119
+ documentation_uri: https://www.rubydoc.info/gems/imgix-rails/4.0.2
120
+ source_code_uri: https://github.com/imgix/imgix-rails/tree/v4.0.2
122
121
  allowed_push_host: https://rubygems.org
123
122
  post_install_message:
124
123
  rdoc_options: []
@@ -135,8 +134,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
135
134
  - !ruby/object:Gem::Version
136
135
  version: '0'
137
136
  requirements: []
138
- rubyforge_project:
139
- rubygems_version: 2.5.2.3
137
+ rubygems_version: 3.1.2
140
138
  signing_key:
141
139
  specification_version: 4
142
140
  summary: Makes integrating imgix into your Rails app easier. It builds on imgix-rb