imgix-rails 4.1.0 → 4.2.0

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
2
  SHA256:
3
- metadata.gz: ee4ca6aecc3acbcbb35b5c9b68731403e423f9b76421e14bbf270b727aa0c75d
4
- data.tar.gz: 5397fee06ecb6b23d2e5fb0464736681b3d68976a87e5959b1b33f890a164acf
3
+ metadata.gz: 88a3092191fe9ded77bf15aa47ab9dece604fe75b68da6066d1d26623b792885
4
+ data.tar.gz: ff00a1456055f474ac7bbde0e5174a33f21dfe8410e313f5add68308c31d1537
5
5
  SHA512:
6
- metadata.gz: 54700c22ae9e911dd22139e4e03b45bff2c07b38ca8a23f6253a9311420424903babb1189db3a31bd0eaa70e88f8babeefe26cd95ce3d1691ab0804cdca782dc
7
- data.tar.gz: df2ef3b2ba35d0f1296c6a161ff37ecbbe11a1dfda97c69b4c330b6049cdacf8129363db6b39394e6ce1146daed6f33049807763d4045753690ada32db276c98
6
+ metadata.gz: 0f8b5d87b939ad76463cf2dcdfed8a21dbf57abce525f7f5cbcacb9dcfb7dcd254198fc6a2537ca54220661095bec81784990bda59f7eec23c45bd23e034673a
7
+ data.tar.gz: d9d499115d9bd1173f5bf5c1bb54c9d2645caf4ea87e332a50dab64dab0786ff29bf63379b5c4700c9e360027053e4ea3176fd13196227fb48dbce03d7164f95
@@ -1,5 +1,8 @@
1
1
  language: ruby
2
2
  rvm:
3
+ - 2.7.1
4
+ - 2.6.6
5
+ - 2.5.8
3
6
  - 2.3.1
4
7
  - 2.2.5
5
8
  - jruby
@@ -3,9 +3,14 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  This project adheres to [Semantic Versioning](http://semver.org/).
5
5
 
6
+ ## [4.2.0](https://github.com/imgix/imgix-rb/compare/4.1.0...4.2.0) - January 05, 2021
7
+
8
+ - Add support for lazy image loading ([#108](https://github.com/imgix/imgix-rails/pull/108))
9
+
6
10
  ## [4.1.0](https://github.com/imgix/imgix-rb/compare/4.0.2...4.1.0) - October 13, 2020
7
11
 
8
12
  ### Release Notes
13
+
9
14
  Version 4.1.0 has been released! The goal of this release is to offer flexibility to those using imgix-rb's purger capabilities through imgix-rails.
10
15
 
11
16
  Prior to this release, this gem offered purging capability through `imgix '~> 3.0'`. However, that purging capability has been deprecated in favor of the new-style purging API––available now in [imgix-rb v4.0.0](https://github.com/imgix/imgix-rb/releases/tag/4.0.0).
@@ -17,9 +22,11 @@ To upgrade to the new purging API used in `imgix '~> 4.0'`:
17
22
  - use this new key in your imgix client: `Imgix::Client.new(domain: '...', api_key: NEW_API_KEY)`
18
23
 
19
24
  ### Changes
25
+
20
26
  - build: use optimistic constraint for imgix >= 3.0 ([#104](https://github.com/imgix/imgix-rails/pull/104))
21
27
 
22
28
  ## [4.0.2](https://github.com/imgix/imgix-rb/compare/4.0.1...4.0.2) - July 31, 2020
29
+
23
30
  - fix: replace `opts[:host`] with `opts[:domain]` to resolve deprecation warnings ([#96](https://github.com/imgix/imgix-rails/pull/96))
24
31
 
25
32
  ## [4.0.1](https://github.com/imgix/imgix-rb/compare/4.0.0...4.0.1) - June 10, 2020
@@ -40,13 +47,13 @@ For users migrating to version 4.0 or later, it is important that all srcset-rel
40
47
 
41
48
  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.
42
49
 
43
- * feat: utilize Imgix::Path#to_srcset when constructing srcsets ([#83](https://github.com/imgix/imgix-rails/pull/83))
44
- * chore: remove deprecated domain sharding behavior ([#80](https://github.com/imgix/imgix-rails/pull/80))
45
- * fix: deprecate resizing height when maintaining aspect ratio ([#78](https://github.com/imgix/imgix-rails/pull/78))
50
+ - feat: utilize Imgix::Path#to_srcset when constructing srcsets ([#83](https://github.com/imgix/imgix-rails/pull/83))
51
+ - chore: remove deprecated domain sharding behavior ([#80](https://github.com/imgix/imgix-rails/pull/80))
52
+ - fix: deprecate resizing height when maintaining aspect ratio ([#78](https://github.com/imgix/imgix-rails/pull/78))
46
53
 
47
54
  ## [3.1.0](https://github.com/imgix/imgix-rb/compare/3.0.2...3.1.0) - October 25, 2019
48
55
 
49
- * Update bundler dev dependency to include new major version 2.x ([#71](https://github.com/imgix/imgix-rb/pull/71))
50
- * README: Fix typo ([#73](https://github.com/imgix/imgix-rb/pull/73))
51
- * docs: add ActiveStorage instructions to README ([#74](https://github.com/imgix/imgix-rb/pull/74))
52
- * 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))
56
+ - Update bundler dev dependency to include new major version 2.x ([#71](https://github.com/imgix/imgix-rb/pull/71))
57
+ - README: Fix typo ([#73](https://github.com/imgix/imgix-rb/pull/73))
58
+ - docs: add ActiveStorage instructions to README ([#74](https://github.com/imgix/imgix-rb/pull/74))
59
+ - 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
@@ -4,7 +4,7 @@
4
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
5
 
6
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=main)](https://travis-ci.org/imgix/imgix-rails)
7
+ [![Build Status](https://travis-ci.com/imgix/imgix-rails.svg?branch=main)](https://travis-ci.com/imgix/imgix-rails)
8
8
  ![Downloads](https://img.shields.io/gem/dt/imgix-rails)
9
9
  [![License](https://img.shields.io/github/license/imgix/imgix-rails)](https://github.com/imgix/imgix-rails/blob/main/LICENSE)
10
10
 
@@ -17,8 +17,10 @@
17
17
  - [Multi-source configuration](#multi-source-configuration)
18
18
  - [`ix_image_tag`](#iximagetag)
19
19
  - [Fixed image rendering](#fixed-image-rendering)
20
+ - [Lazy Loading](#lazy-loading)
20
21
  - [`ix_picture_tag`](#ixpicturetag)
21
22
  - [`ix_image_url`](#iximageurl)
23
+ - [Usage in Model](#usage-in-model)
22
24
  - [Usage in Sprockets](#usage-in-sprockets)
23
25
  - [Using With Image Uploading Libraries](#using-with-image-uploading-libraries)
24
26
  - [Paperclip and CarrierWave](#paperclip-and-carrierwave)
@@ -108,6 +110,8 @@ The `ix_image_tag` helper method makes it easy to pass parameters to imgix to ha
108
110
  * [`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.
109
111
  * [`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.
110
112
  * [`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`.
113
+ * `attribute_options`: Allow you to change where imgix-rails renders
114
+ attributes. This can be helpful if you want to add lazy-loading.
111
115
 
112
116
  ```erb
113
117
  <%= 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' }) %>
@@ -177,6 +181,29 @@ https://assets.imgix.net/image.jpg?ixlib=rails-3.0.2&amp;w=1000&amp;dpr=5&amp;q=
177
181
 
178
182
  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 }`.
179
183
 
184
+ #### Lazy loading
185
+
186
+ If you'd like to lazy load images, we recommend using [lazysizes](https://github.com/aFarkas/lazysizes). In order to use imgix-rails with lazysizes, you need to use `attribute_options` as well as set `tag_options[:src]`:
187
+
188
+ ```erb
189
+ <%= ix_image_tag('image.jpg', attribute_options: {src: "data-src",
190
+ srcset: "data-srcset", sizes: "data-sizes"}, url_params: {w: 1000},
191
+ tag_options: {src: "lqip.jpg"}) %>
192
+ ```
193
+
194
+ Will render the following HTML:
195
+
196
+ ```html
197
+ <img data-srcset="https://assets.imgix.net/image.jpg?ixlib=rails-3.0.2&amp;w=1000&amp;dpr=1&amp;q=75 1x,
198
+ https://assets.imgix.net/image.jpg?ixlib=rails-3.0.2&amp;w=1000&amp;dpr=2&amp;q=50 2x,
199
+ https://assets.imgix.net/image.jpg?ixlib=rails-3.0.2&amp;w=1000&amp;dpr=3&amp;q=35 3x,
200
+ https://assets.imgix.net/image.jpg?ixlib=rails-3.0.2&amp;w=1000&amp;dpr=4&amp;q=23 4x,
201
+ https://assets.imgix.net/image.jpg?ixlib=rails-3.0.2&amp;w=1000&amp;dpr=5&amp;q=20 5x"
202
+ data-sizes="100vw"
203
+ data-src="https://assets.imgix.net/image.jpg?ixlib=rails-3.0.2&amp;w=1000"
204
+ src="lqip.jpg">
205
+ ```
206
+
180
207
  ### `ix_picture_tag`
181
208
 
182
209
  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.
@@ -252,7 +279,7 @@ To generate a `picture` element on a different source:
252
279
 
253
280
  The `ix_image_url` helper makes it easy to generate a URL to an image in your Rails app.
254
281
 
255
- `ix_image_url` takes four arguments:
282
+ `ix_image_url` takes three arguments:
256
283
 
257
284
  * `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.
258
285
  * `path`: The path or URL of the image to display.
@@ -270,6 +297,8 @@ https://assets.imgix.net/users/1/avatar.png?w=400&h=300
270
297
  https://assets2.imgix.net/users/1/avatar.png?w=400&h=300
271
298
  ```
272
299
 
300
+ #### Usage in Model
301
+
273
302
  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.
274
303
 
275
304
  ```rb
@@ -279,6 +308,8 @@ puts ix_image_url('/users/1/avatar.png', { w: 400, h: 300 })
279
308
  # => https://assets.imgix.net/users/1/avatar.png?w=400&h=300
280
309
  ```
281
310
 
311
+ Alternatively, you can also use the imgix [Ruby client](https://github.com/imgix/imgix-rb) in the same way.
312
+
282
313
  #### Usage in Sprockets
283
314
 
284
315
  `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:
@@ -3,9 +3,28 @@ require "imgix/rails/tag"
3
3
  class Imgix::Rails::ImageTag < Imgix::Rails::Tag
4
4
 
5
5
  def render
6
- @tag_options[:srcset] = srcset
7
- @tag_options[:sizes] ||= '100vw'
6
+ url = ix_image_url(@source, @path, @url_params)
8
7
 
9
- image_tag(ix_image_url(@source, @path, @url_params), @tag_options)
8
+ if @attribute_options[:srcset].present?
9
+ @tag_options[@attribute_options[:srcset]] = srcset
10
+ else
11
+ @tag_options[:srcset] = srcset
12
+ end
13
+
14
+ if @attribute_options[:size].present?
15
+ @tag_options[@attribute_options[:size]] ||= '100vw'
16
+ else
17
+ @tag_options[:sizes] ||= '100vw'
18
+ end
19
+
20
+ if @attribute_options[:src].present?
21
+ @tag_options[@attribute_options[:src]] = url
22
+ end
23
+
24
+ if @tag_options[:src].present?
25
+ image_tag(@tag_options[:src], @tag_options)
26
+ else
27
+ image_tag(url, @tag_options)
28
+ end
10
29
  end
11
30
  end
@@ -5,12 +5,13 @@ class Imgix::Rails::Tag
5
5
  include Imgix::Rails::UrlHelper
6
6
  include ActionView::Helpers
7
7
 
8
- def initialize(path, source: nil, tag_options: {}, url_params: {}, srcset_options: {})
8
+ def initialize(path, source: nil, tag_options: {}, url_params: {}, srcset_options: {}, attribute_options: {})
9
9
  @path = path
10
10
  @source = source
11
11
  @tag_options = tag_options
12
12
  @url_params = url_params
13
13
  @srcset_options = srcset_options
14
+ @attribute_options = attribute_options
14
15
  end
15
16
 
16
17
  protected
@@ -1,5 +1,5 @@
1
1
  module Imgix
2
2
  module Rails
3
- VERSION = '4.1.0'
3
+ VERSION = '4.2.0'
4
4
  end
5
5
  end
@@ -8,8 +8,8 @@ module Imgix
8
8
  module ViewHelper
9
9
  include UrlHelper
10
10
 
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
11
+ def ix_image_tag(source=nil, path, tag_options: {}, url_params: {}, srcset_options: {}, attribute_options: {})
12
+ return Imgix::Rails::ImageTag.new(path, source: source, tag_options: tag_options, url_params: url_params, srcset_options: srcset_options, attribute_options: attribute_options).render
13
13
  end
14
14
 
15
15
  def ix_picture_tag(source=nil, path, tag_options: {}, url_params: {}, breakpoints: {}, srcset_options: {})
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: 4.1.0
4
+ version: 4.2.0
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: 2020-10-15 00:00:00.000000000 Z
12
+ date: 2021-01-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: imgix
@@ -121,8 +121,8 @@ licenses:
121
121
  metadata:
122
122
  bug_tracker_uri: https://github.com/imgix/imgix-rails/issues
123
123
  changelog_uri: https://github.com/imgix/imgix-rails/blob/main/CHANGELOG.md
124
- documentation_uri: https://www.rubydoc.info/gems/imgix-rails/4.1.0
125
- source_code_uri: https://github.com/imgix/imgix-rails/tree/v4.1.0
124
+ documentation_uri: https://www.rubydoc.info/gems/imgix-rails/4.2.0
125
+ source_code_uri: https://github.com/imgix/imgix-rails/tree/v4.2.0
126
126
  allowed_push_host: https://rubygems.org
127
127
  post_install_message:
128
128
  rdoc_options: []
@@ -139,7 +139,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
139
139
  - !ruby/object:Gem::Version
140
140
  version: '0'
141
141
  requirements: []
142
- rubygems_version: 3.1.2
142
+ rubygems_version: 3.1.4
143
143
  signing_key:
144
144
  specification_version: 4
145
145
  summary: Makes integrating imgix into your Rails app easier. It builds on imgix-rb