imgix 3.1.0 → 3.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c260521282fd6b24c05cf774caaf4b140fef9b5a
4
- data.tar.gz: d7b53e8cce58a50020eeba7d9c4ad6aa556dfbb5
3
+ metadata.gz: 93aa8838354b1565c1691c817c4ed212d76b3222
4
+ data.tar.gz: bc28c0311f08510f4fc4ff96c73774b59d83e59f
5
5
  SHA512:
6
- metadata.gz: 33ff8d7ea4e778dcea4ade90283896b034c40b9d6cbd613920ec2712390b925d39041f996b3d44698a76dd279b829ab1d0a55e86e05dd57fbb2a417a03cf3b7b
7
- data.tar.gz: 87ab1ed154e7ea3bfa69538a8904d3f8e9145f3cfa9175b3db60dc9855a20ca0f9845663be9a12eadcf340e8bf3cd1e29de630fa6561c092a0e7e9700a493b22
6
+ metadata.gz: e7e492f9c63a641a6c2dc6f3f86ef96008c965187ce5439448e878d37a0b825871672447b8f113eba1137c97353a358e7cc6a3be68b8720c5a37472bc5f4515f
7
+ data.tar.gz: b2b3799e866a64680842a6193d5ca1e0794ff5d918052c732bfe704de63bc9bb5b29a7e6f4f608fc5642344e01ee38b22990951273e16402ccd98022a1906252
@@ -1,16 +1,6 @@
1
+ dist: trusty
1
2
  language: ruby
2
3
  bundler_args: --without development
3
- before_install:
4
- # Extracts the ruby version number
5
- - RUBY_VERS="$(bc -l<<<$(ruby -v | cut -d' ' -f 2 | cut -d'.' -f 1,2))"
6
- # Bundler 2.0 requires at least ruby vers 2.3.0
7
- - LATEST_VERS=2.3
8
- # Based on a given job's ruby version, install either
9
- # Bundler 2.x or 1.17
10
- - if (( $(echo "$RUBY_VERS >= $LATEST_VERS" | bc -l) ));
11
- then echo $(gem install bundler);
12
- else echo $(gem install bundler -v '< 2');
13
- fi
14
4
  rvm:
15
5
  - 2.3.0
16
6
  - 2.2.4
@@ -3,7 +3,12 @@
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
- ## [3.1.0](https://github.com/imgix/imgix-rb/compare/2.1.0...3.1.0) - July 28, 2019
6
+ ## [3.1.1](https://github.com/imgix/imgix-rb/compare/3.1.0...3.1.1) - July 28, 2019
7
+
8
+ * fix: include dpr parameter when generating a DPR srcset ([#48](https://github.com/imgix/imgix-rb/pull/48))
9
+ * ci(travis): change build dist to trusty and remove bundler script ([#49](https://github.com/imgix/imgix-rb/pull/49))
10
+
11
+ ## [3.1.0](https://github.com/imgix/imgix-rb/compare/3.0.0...3.1.0) - July 28, 2019
7
12
 
8
13
  * feat: add srcset generation ([#47](https://github.com/imgix/imgix-rb/pull/47))
9
14
 
data/README.md CHANGED
@@ -68,23 +68,23 @@ https://your-subdomain.imgix.net/images/demo.png?w=7400&s=a5dd7dda1dbac613f0475f
68
68
  https://your-subdomain.imgix.net/images/demo.png?w=8192&s=9fbd257c53e770e345ce3412b64a3452 8192w
69
69
  ```
70
70
 
71
- In cases where enough information is provided about an image's dimensions, `to_srcset` 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 `to_srcset` with either a width **or** the height and aspect ratio provided, a different `srcset` will be generated for a fixed-size image instead.
71
+ In cases where enough information is provided about an image's dimensions, `to_srcset` 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 `to_srcset` 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.
72
72
 
73
73
  ```rb
74
- client = Imgix::Client.new(host: 'your-subdomain.imgix.net', secure_url_token: 'your-token')
74
+ client = Imgix::Client.new(host: 'your-subdomain.imgix.net', secure_url_token: 'your-token', include_library_param: false)
75
75
  path = client.path('/images/demo.png')
76
76
 
77
- srcset = path.to_srcset(h:800, ar:'3:2')
77
+ srcset = path.to_srcset(h:800, ar:'3:2', fit:'crop')
78
78
  ```
79
79
 
80
80
  Will produce the following attribute value:
81
81
 
82
82
  ```html
83
- https://your-subdomain.imgix.net/images/demo.png?h=800&ar=3%3A2&s=be8c153bb9ed0dd152e846414a8fdc86 1x,
84
- https://your-subdomain.imgix.net/images/demo.png?h=800&ar=3%3A2&s=be8c153bb9ed0dd152e846414a8fdc86 2x,
85
- https://your-subdomain.imgix.net/images/demo.png?h=800&ar=3%3A2&s=be8c153bb9ed0dd152e846414a8fdc86 3x,
86
- https://your-subdomain.imgix.net/images/demo.png?h=800&ar=3%3A2&s=be8c153bb9ed0dd152e846414a8fdc86 4x,
87
- https://your-subdomain.imgix.net/images/demo.png?h=800&ar=3%3A2&s=be8c153bb9ed0dd152e846414a8fdc86 5x
83
+ https://your-subdomain.imgix.net/images/demo.png?h=800&ar=3%3A2&fit=crop&dpr=1&s=f97f2dccf85beac33a3824b57ef4ddc6 1x,
84
+ https://your-subdomain.imgix.net/images/demo.png?h=800&ar=3%3A2&fit=crop&dpr=2&s=e1727167fef53cdb0a89dd66b8672410 2x,
85
+ https://your-subdomain.imgix.net/images/demo.png?h=800&ar=3%3A2&fit=crop&dpr=3&s=7718db8457345419c30214f1d1a3a5d3 3x,
86
+ https://your-subdomain.imgix.net/images/demo.png?h=800&ar=3%3A2&fit=crop&dpr=4&s=000c50a7f97ccdbb9bb2f00bc5241ed4 4x,
87
+ https://your-subdomain.imgix.net/images/demo.png?h=800&ar=3%3A2&fit=crop&dpr=5&s=970b6fc12a410f3dd2959674dd1f4120 5x
88
88
  ```
89
89
 
90
90
  For more information to better understand `srcset`, we highly recommend [Eric Portis' "Srcset and sizes" article](https://ericportis.com/posts/2014/srcset-sizes/) which goes into depth about the subject.
@@ -85,16 +85,21 @@ module Imgix
85
85
  end
86
86
 
87
87
  def to_srcset(params = {})
88
+ prev_options = @options.dup
88
89
  @options.merge!(params)
90
+
89
91
  width = @options['w'.to_sym]
90
92
  height = @options['h'.to_sym]
91
93
  aspect_ratio = @options['ar'.to_sym]
92
94
 
93
95
  if ((width) || (height && aspect_ratio))
94
- build_dpr_srcset(@options)
96
+ srcset = build_dpr_srcset(@options)
95
97
  else
96
- build_srcset_pairs(@options)
98
+ srcset = build_srcset_pairs(@options)
97
99
  end
100
+
101
+ @options = prev_options
102
+ return srcset
98
103
  end
99
104
 
100
105
  private
@@ -123,24 +128,24 @@ module Imgix
123
128
  query.length > 0
124
129
  end
125
130
 
126
- def build_srcset_pairs(params = {})
131
+ def build_srcset_pairs(params)
127
132
  srcset = ''
133
+
128
134
  for width in @target_widths do
129
- currentParams = params || {}
130
- currentParams['w'] = width
131
- srcset += "#{to_url(currentParams)} #{width}w,\n"
135
+ params['w'.to_sym] = width
136
+ srcset += "#{to_url(params)} #{width}w,\n"
132
137
  end
133
138
 
134
139
  return srcset[0..-3]
135
140
  end
136
141
 
137
- def build_dpr_srcset(params = {})
142
+ def build_dpr_srcset(params)
138
143
  srcset = ''
139
144
  target_ratios = [1,2,3,4,5]
140
- url = to_url(params)
141
145
 
142
146
  for ratio in target_ratios do
143
- srcset += "#{url} #{ratio}x,\n"
147
+ params['dpr'.to_sym] = ratio
148
+ srcset += "#{to_url(params)} #{ratio}x,\n"
144
149
  end
145
150
 
146
151
  return srcset[0..-3]
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Imgix
4
- VERSION = '3.1.0'
4
+ VERSION = '3.1.1'
5
5
  end
@@ -9,6 +9,21 @@ module SrcsetTest
9
9
  assert_equal expected_number_of_pairs, srcset.split(',').length
10
10
  end
11
11
 
12
+ def test_srcset_pair_values
13
+ resolutions = [100, 116, 134, 156, 182, 210, 244, 282,
14
+ 328, 380, 442, 512, 594, 688, 798, 926,
15
+ 1074, 1246, 1446, 1678, 1946, 2258, 2618,
16
+ 3038, 3524, 4088, 4742, 5500, 6380, 7400, 8192]
17
+ srcset = path.to_srcset()
18
+ srclist = srcset.split(',').map { |srcset_split|
19
+ srcset_split.split(' ')[1].to_i
20
+ }
21
+
22
+ for i in 0..srclist.length-1 do
23
+ assert_equal(srclist[i], resolutions[i])
24
+ end
25
+ end
26
+
12
27
  private
13
28
  def path
14
29
  @client ||= Imgix::Client.new(host: 'testing.imgix.net', secure_url_token: 'MYT0KEN', include_library_param: false).path('image.jpg')
@@ -26,14 +41,29 @@ module SrcsetTest
26
41
  }
27
42
  end
28
43
 
44
+ def test_srcset_has_dpr_params
45
+ i = 1
46
+ srcset.split(',').map { |srcset_split|
47
+ src = srcset_split.split(' ')[0]
48
+ assert_includes src, "dpr=#{i}"
49
+ i += 1
50
+ }
51
+ end
52
+
29
53
  def test_srcset_signs_urls
30
- expected_signature = 'b95cfd915f4a198442bff4ce5befe5b8'
54
+ srcset.split(',').map { |srcset_split|
55
+ src = srcset_split.split(' ')[0]
56
+ assert_includes src, 's='
31
57
 
32
- srcset.split(',').map { |src|
33
- url = src.split(' ')[0]
34
- assert_includes url, "s="
58
+ # parses out all parameters except for 's=...'
59
+ params = src[src.index('?')..src.index('s=')-2]
35
60
 
36
- generated_signature = url.slice(url.index("s=")+2, url.length)
61
+ # parses out the 's=...' parameter
62
+ generated_signature = src.slice(src.index('s=')+2, src.length)
63
+
64
+ signature_base = 'MYT0KEN' + '/image.jpg' + params;
65
+ expected_signature = Digest::MD5.hexdigest(signature_base)
66
+
37
67
  assert_equal expected_signature, generated_signature
38
68
  }
39
69
  end
@@ -50,6 +80,20 @@ module SrcsetTest
50
80
  assert_equal expected_number_of_pairs, srcset.split(',').length
51
81
  end
52
82
 
83
+ def test_srcset_pair_values
84
+ resolutions = [100, 116, 134, 156, 182, 210, 244, 282,
85
+ 328, 380, 442, 512, 594, 688, 798, 926,
86
+ 1074, 1246, 1446, 1678, 1946, 2258, 2618,
87
+ 3038, 3524, 4088, 4742, 5500, 6380, 7400, 8192]
88
+ srclist = srcset.split(',').map { |srcset_split|
89
+ srcset_split.split(' ')[1].to_i
90
+ }
91
+
92
+ for i in 0..srclist.length-1 do
93
+ assert_equal(srclist[i], resolutions[i])
94
+ end
95
+ end
96
+
53
97
  def test_srcset_respects_height_parameter
54
98
  srcset.split(',').map { |src|
55
99
  assert_includes src, 'h='
@@ -90,8 +134,8 @@ module SrcsetTest
90
134
  assert_includes src, 's='
91
135
 
92
136
  # parses out all parameters except for 's=...'
93
- params = src.slice(src.index('?'), src.length)
94
- params = params.slice(0, params.index('s=')-1)
137
+ params = src[src.index('?')..src.index('s=')-2]
138
+
95
139
  # parses out the 's=...' parameter
96
140
  generated_signature = src.slice(src.index('s=')+2, src.length)
97
141
 
@@ -119,14 +163,29 @@ module SrcsetTest
119
163
  }
120
164
  end
121
165
 
166
+ def test_srcset_has_dpr_params
167
+ i = 1
168
+ srcset.split(',').map { |srcset_split|
169
+ src = srcset_split.split(' ')[0]
170
+ assert_includes src, "dpr=#{i}"
171
+ i += 1
172
+ }
173
+ end
174
+
122
175
  def test_srcset_signs_urls
123
- expected_signature = 'fb081a45c449b28f69e012d474943df3'
176
+ srcset.split(',').map { |srcset_split|
177
+ src = srcset_split.split(' ')[0]
178
+ assert_includes src, 's='
124
179
 
125
- srcset.split(',').map { |src|
126
- url = src.split(' ')[0]
127
- assert_includes url, "s="
180
+ # parses out all parameters except for 's=...'
181
+ params = src[src.index('?')..src.index('s=')-2]
128
182
 
129
- generated_signature = url.slice(url.index("s=")+2, url.length)
183
+ # parses out the 's=...' parameter
184
+ generated_signature = src.slice(src.index('s=')+2, src.length)
185
+
186
+ signature_base = 'MYT0KEN' + '/image.jpg' + params;
187
+ expected_signature = Digest::MD5.hexdigest(signature_base)
188
+
130
189
  assert_equal expected_signature, generated_signature
131
190
  }
132
191
  end
@@ -143,6 +202,20 @@ module SrcsetTest
143
202
  assert_equal expected_number_of_pairs, srcset.split(',').length
144
203
  end
145
204
 
205
+ def test_srcset_pair_values
206
+ resolutions = [100, 116, 134, 156, 182, 210, 244, 282,
207
+ 328, 380, 442, 512, 594, 688, 798, 926,
208
+ 1074, 1246, 1446, 1678, 1946, 2258, 2618,
209
+ 3038, 3524, 4088, 4742, 5500, 6380, 7400, 8192]
210
+ srclist = srcset.split(',').map { |srcset_split|
211
+ srcset_split.split(' ')[1].to_i
212
+ }
213
+
214
+ for i in 0..srclist.length-1 do
215
+ assert_equal(srclist[i], resolutions[i])
216
+ end
217
+ end
218
+
146
219
  def test_srcset_within_bounds
147
220
  min, *max = srcset.split(',')
148
221
 
@@ -177,8 +250,8 @@ module SrcsetTest
177
250
  assert_includes src, 's='
178
251
 
179
252
  # parses out all parameters except for 's=...'
180
- params = src.slice(src.index('?'), src.length)
181
- params = params.slice(0, params.index('s=')-1)
253
+ params = src[src.index('?')..src.index('s=')-2]
254
+
182
255
  # parses out the 's=...' parameter
183
256
  generated_signature = src.slice(src.index('s=')+2, src.length)
184
257
 
@@ -206,14 +279,29 @@ module SrcsetTest
206
279
  }
207
280
  end
208
281
 
282
+ def test_srcset_has_dpr_params
283
+ i = 1
284
+ srcset.split(',').map { |srcset_split|
285
+ src = srcset_split.split(' ')[0]
286
+ assert_includes src, "dpr=#{i}"
287
+ i += 1
288
+ }
289
+ end
290
+
209
291
  def test_srcset_signs_urls
210
- expected_signature = '84db8cb226483fc0130b4fb58e1e6ff2'
292
+ srcset.split(',').map { |srcset_split|
293
+ src = srcset_split.split(' ')[0]
294
+ assert_includes src, 's='
211
295
 
212
- srcset.split(',').map { |src|
213
- url = src.split(' ')[0]
214
- assert_includes url, "s="
296
+ # parses out all parameters except for 's=...'
297
+ params = src[src.index('?')..src.index('s=')-2]
298
+
299
+ # parses out the 's=...' parameter
300
+ generated_signature = src.slice(src.index('s=')+2, src.length)
215
301
 
216
- generated_signature = url.slice(url.index("s=")+2, url.length)
302
+ signature_base = 'MYT0KEN' + '/image.jpg' + params;
303
+ expected_signature = Digest::MD5.hexdigest(signature_base)
304
+
217
305
  assert_equal expected_signature, generated_signature
218
306
  }
219
307
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: imgix
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.0
4
+ version: 3.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kelly Sutton
@@ -13,7 +13,7 @@ authors:
13
13
  autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
- date: 2019-07-29 00:00:00.000000000 Z
16
+ date: 2019-09-05 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: addressable