imgix-rails 2.0.0 → 2.1.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
  SHA1:
3
- metadata.gz: 62c3df395875ff9ec0422abe8b6b5ab60ddc8a0c
4
- data.tar.gz: 285cbe4283c1caad13a3266dfe150e1726a6977f
3
+ metadata.gz: b03c93258d32db083dca271b49348a489b1c2f61
4
+ data.tar.gz: 2561fb0a35d24508727276d2b9cd33bb5e79bf27
5
5
  SHA512:
6
- metadata.gz: c3ecb91c1f1452f5a026bf77590d56987ab2946d7875276a95784ab9dec52c89d245ae3b73a002199513addca758848ac4fcb588570440106b076519a32154da
7
- data.tar.gz: 26927455ee9b481d06a6427176876d2f2ee5c45c28c5f96af2cada5c35eeae582de03da29ecb8649787785a855db001b7bf6387132d06c7ba65afaddb9759674
6
+ metadata.gz: 1559d5951079e2fd3b0aab23862d906e9d4bb2cb323e9bf1968d3f4692ea3ba91dd5022663267acaff2e760f9a43560cca32552eafa04cd2f0244f6cd4b7c9e4
7
+ data.tar.gz: 018673c10d607f589719475175cc38ecd67d03efc2e3823fe9aae13aaa9f09977c669a9161b22698c8217f8bedaacd310243fc387d6f4b81ffaa873cda8bbb3e
data/README.md CHANGED
@@ -102,6 +102,12 @@ Then rendering the portrait in your application is very easy:
102
102
  <%= profile_image_tag(@user) %>
103
103
  ```
104
104
 
105
+ 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`.
106
+
107
+ ```erb
108
+ <%= ix_image_tag('/unsplash/hotairballoon.jpg', { widths: [320, 640, 960, 1280] w: 300, h: 500, fit: 'crop', crop: 'right', alt: 'A hot air balloon on a sunny day' }) %>
109
+ ```
110
+
105
111
 
106
112
  <a name="ix_picture_tag"></a>
107
113
  ### ix_picture_tag
@@ -29,15 +29,17 @@ protected
29
29
 
30
30
  def srcset(opts=@options)
31
31
  @source = replace_hostname(@source)
32
- target_widths.map do |target_width|
32
+ widths = opts[:widths] || target_widths
33
+
34
+ widths.map do |width|
33
35
  srcset_options = opts.slice(*self.class.available_parameters)
34
- srcset_options[:w] = target_width
36
+ srcset_options[:w] = width
35
37
 
36
38
  if opts[:w].present? && opts[:h].present?
37
- srcset_options[:h] = (target_width * (opts[:h].to_f / opts[:w])).round
39
+ srcset_options[:h] = (width * (opts[:h].to_f / opts[:w])).round
38
40
  end
39
41
 
40
- "#{ix_image_url(@source, srcset_options)} #{target_width}w"
42
+ "#{ix_image_url(@source, srcset_options)} #{width}w"
41
43
  end.join(', ')
42
44
  end
43
45
 
@@ -137,9 +139,16 @@ private
137
139
  min_screen_width_required = @options[:min_width] || SCREEN_STEP
138
140
  max_screen_width_required = @options[:max_width] || MAXIMUM_SCREEN_WIDTH
139
141
 
140
- (device_widths + screen_widths).select do |w|
142
+ widths = (device_widths + screen_widths).select do |w|
141
143
  w <= max_screen_width_required && w >= min_screen_width_required
142
144
  end.compact.uniq.sort
145
+
146
+ # Add exact widths for 1x, 2x, and 3x devices
147
+ if @options[:w]
148
+ widths.push(@options[:w], @options[:w] * 2, @options[:w] * 3)
149
+ end
150
+
151
+ widths
143
152
  end
144
153
 
145
154
  def device_widths
@@ -1,5 +1,5 @@
1
1
  module Imgix
2
2
  module Rails
3
- VERSION = '2.0.0'
3
+ VERSION = '2.1.0'
4
4
  end
5
5
  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: 2.0.0
4
+ version: 2.1.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: 2016-05-23 00:00:00.000000000 Z
12
+ date: 2016-06-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: imgix