kamifusen 1.11.2 → 1.12.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: 65c261931b31f7261f7ecb8eef7c33acefffc4d376277bbf51849a2bef265e72
4
- data.tar.gz: 2e9a99e1178698daa9e755a3c57255b5b64d9bed7e325abc7fa2c674dbf0d02d
3
+ metadata.gz: 267a1dc5741237d4a1255563dcb2f7fccb7717233ae02ad17b32d8829e9dd8d8
4
+ data.tar.gz: 24662f9214bbbc62cfb9268ff88a071d4d0bb5cf85e82902b0b1cf20f7cf409b
5
5
  SHA512:
6
- metadata.gz: 1060a04a694115c734ddf368d103094de0eddafdcf3c82a9cfdb13b66f01aa9325dbb097ebcbd065d960c6d408bc75096bb7cdc4ad282ec807cb7d8251910ca4
7
- data.tar.gz: f5bb7e006824b81be617c50901c61fa93ae871a307fc1a75b948ddefdc8b298ceb263d191083992a1a0c8356d281abf2b4f3f9c8cee85bf9d14c233a23de58e7
6
+ metadata.gz: bbe200dc7c4335380d89fd878fbc3bee55deadddd5cc30a3ca920c0df0c9f86c4ab6199486d67f8959bb2e14154492587cc8898b2f4e97dcdb191a447a4df62a
7
+ data.tar.gz: cb0a63d0b2ae76002bb2455aae1e7ed2c706a6580518b5ac06cb4189b2b760f05a184711558ed2e9ee4c4cae4bc110ac1eb5b575cb3b17b95447c3a85d6456e7
data/Gemfile.lock CHANGED
@@ -1,194 +1,232 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- kamifusen (1.11.2)
4
+ kamifusen (1.12.0)
5
5
  image_processing
6
6
  rails
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- actioncable (7.0.2.2)
12
- actionpack (= 7.0.2.2)
13
- activesupport (= 7.0.2.2)
11
+ actioncable (7.1.3.4)
12
+ actionpack (= 7.1.3.4)
13
+ activesupport (= 7.1.3.4)
14
14
  nio4r (~> 2.0)
15
15
  websocket-driver (>= 0.6.1)
16
- actionmailbox (7.0.2.2)
17
- actionpack (= 7.0.2.2)
18
- activejob (= 7.0.2.2)
19
- activerecord (= 7.0.2.2)
20
- activestorage (= 7.0.2.2)
21
- activesupport (= 7.0.2.2)
16
+ zeitwerk (~> 2.6)
17
+ actionmailbox (7.1.3.4)
18
+ actionpack (= 7.1.3.4)
19
+ activejob (= 7.1.3.4)
20
+ activerecord (= 7.1.3.4)
21
+ activestorage (= 7.1.3.4)
22
+ activesupport (= 7.1.3.4)
22
23
  mail (>= 2.7.1)
23
24
  net-imap
24
25
  net-pop
25
26
  net-smtp
26
- actionmailer (7.0.2.2)
27
- actionpack (= 7.0.2.2)
28
- actionview (= 7.0.2.2)
29
- activejob (= 7.0.2.2)
30
- activesupport (= 7.0.2.2)
27
+ actionmailer (7.1.3.4)
28
+ actionpack (= 7.1.3.4)
29
+ actionview (= 7.1.3.4)
30
+ activejob (= 7.1.3.4)
31
+ activesupport (= 7.1.3.4)
31
32
  mail (~> 2.5, >= 2.5.4)
32
33
  net-imap
33
34
  net-pop
34
35
  net-smtp
35
- rails-dom-testing (~> 2.0)
36
- actionpack (7.0.2.2)
37
- actionview (= 7.0.2.2)
38
- activesupport (= 7.0.2.2)
39
- rack (~> 2.0, >= 2.2.0)
36
+ rails-dom-testing (~> 2.2)
37
+ actionpack (7.1.3.4)
38
+ actionview (= 7.1.3.4)
39
+ activesupport (= 7.1.3.4)
40
+ nokogiri (>= 1.8.5)
41
+ racc
42
+ rack (>= 2.2.4)
43
+ rack-session (>= 1.0.1)
40
44
  rack-test (>= 0.6.3)
41
- rails-dom-testing (~> 2.0)
42
- rails-html-sanitizer (~> 1.0, >= 1.2.0)
43
- actiontext (7.0.2.2)
44
- actionpack (= 7.0.2.2)
45
- activerecord (= 7.0.2.2)
46
- activestorage (= 7.0.2.2)
47
- activesupport (= 7.0.2.2)
45
+ rails-dom-testing (~> 2.2)
46
+ rails-html-sanitizer (~> 1.6)
47
+ actiontext (7.1.3.4)
48
+ actionpack (= 7.1.3.4)
49
+ activerecord (= 7.1.3.4)
50
+ activestorage (= 7.1.3.4)
51
+ activesupport (= 7.1.3.4)
48
52
  globalid (>= 0.6.0)
49
53
  nokogiri (>= 1.8.5)
50
- actionview (7.0.2.2)
51
- activesupport (= 7.0.2.2)
54
+ actionview (7.1.3.4)
55
+ activesupport (= 7.1.3.4)
52
56
  builder (~> 3.1)
53
- erubi (~> 1.4)
54
- rails-dom-testing (~> 2.0)
55
- rails-html-sanitizer (~> 1.1, >= 1.2.0)
56
- activejob (7.0.2.2)
57
- activesupport (= 7.0.2.2)
57
+ erubi (~> 1.11)
58
+ rails-dom-testing (~> 2.2)
59
+ rails-html-sanitizer (~> 1.6)
60
+ activejob (7.1.3.4)
61
+ activesupport (= 7.1.3.4)
58
62
  globalid (>= 0.3.6)
59
- activemodel (7.0.2.2)
60
- activesupport (= 7.0.2.2)
61
- activerecord (7.0.2.2)
62
- activemodel (= 7.0.2.2)
63
- activesupport (= 7.0.2.2)
64
- activestorage (7.0.2.2)
65
- actionpack (= 7.0.2.2)
66
- activejob (= 7.0.2.2)
67
- activerecord (= 7.0.2.2)
68
- activesupport (= 7.0.2.2)
63
+ activemodel (7.1.3.4)
64
+ activesupport (= 7.1.3.4)
65
+ activerecord (7.1.3.4)
66
+ activemodel (= 7.1.3.4)
67
+ activesupport (= 7.1.3.4)
68
+ timeout (>= 0.4.0)
69
+ activestorage (7.1.3.4)
70
+ actionpack (= 7.1.3.4)
71
+ activejob (= 7.1.3.4)
72
+ activerecord (= 7.1.3.4)
73
+ activesupport (= 7.1.3.4)
69
74
  marcel (~> 1.0)
70
- mini_mime (>= 1.1.0)
71
- activesupport (7.0.2.2)
75
+ activesupport (7.1.3.4)
76
+ base64
77
+ bigdecimal
72
78
  concurrent-ruby (~> 1.0, >= 1.0.2)
79
+ connection_pool (>= 2.2.5)
80
+ drb
73
81
  i18n (>= 1.6, < 2)
74
82
  minitest (>= 5.1)
83
+ mutex_m
75
84
  tzinfo (~> 2.0)
76
85
  ast (2.4.2)
77
- builder (3.2.4)
86
+ base64 (0.2.0)
87
+ bigdecimal (3.1.8)
88
+ builder (3.3.0)
78
89
  byebug (11.1.3)
79
- concurrent-ruby (1.1.9)
90
+ concurrent-ruby (1.3.3)
91
+ connection_pool (2.4.1)
80
92
  crass (1.0.6)
81
- digest (3.1.0)
82
- erubi (1.10.0)
83
- ffi (1.15.4)
84
- globalid (1.0.0)
85
- activesupport (>= 5.0)
86
- i18n (1.10.0)
93
+ date (3.3.4)
94
+ drb (2.2.1)
95
+ erubi (1.13.0)
96
+ ffi (1.17.0)
97
+ ffi (1.17.0-x86_64-darwin)
98
+ globalid (1.2.1)
99
+ activesupport (>= 6.1)
100
+ i18n (1.14.5)
87
101
  concurrent-ruby (~> 1.0)
88
- image_processing (1.12.1)
102
+ image_processing (1.12.2)
89
103
  mini_magick (>= 4.9.5, < 5)
90
104
  ruby-vips (>= 2.0.17, < 3)
91
- io-wait (0.2.1)
92
- listen (3.7.0)
105
+ io-console (0.7.2)
106
+ irb (1.14.0)
107
+ rdoc (>= 4.0.0)
108
+ reline (>= 0.4.2)
109
+ json (2.7.2)
110
+ language_server-protocol (3.17.0.3)
111
+ listen (3.9.0)
93
112
  rb-fsevent (~> 0.10, >= 0.10.3)
94
113
  rb-inotify (~> 0.9, >= 0.9.10)
95
- loofah (2.14.0)
114
+ loofah (2.22.0)
96
115
  crass (~> 1.0.2)
97
- nokogiri (>= 1.5.9)
98
- mail (2.7.1)
116
+ nokogiri (>= 1.12.0)
117
+ mail (2.8.1)
99
118
  mini_mime (>= 0.1.1)
100
- marcel (1.0.2)
101
- method_source (1.0.0)
102
- mini_magick (4.11.0)
103
- mini_mime (1.1.2)
104
- mini_portile2 (2.8.0)
105
- minitest (5.15.0)
106
- net-imap (0.2.3)
107
- digest
119
+ net-imap
120
+ net-pop
121
+ net-smtp
122
+ marcel (1.0.4)
123
+ mini_magick (4.13.2)
124
+ mini_mime (1.1.5)
125
+ mini_portile2 (2.8.7)
126
+ minitest (5.24.1)
127
+ mutex_m (0.2.0)
128
+ net-imap (0.4.14)
129
+ date
108
130
  net-protocol
109
- strscan
110
- net-pop (0.1.1)
111
- digest
131
+ net-pop (0.1.2)
112
132
  net-protocol
133
+ net-protocol (0.2.2)
113
134
  timeout
114
- net-protocol (0.1.2)
115
- io-wait
116
- timeout
117
- net-smtp (0.3.1)
118
- digest
135
+ net-smtp (0.5.0)
119
136
  net-protocol
120
- timeout
121
- nio4r (2.5.8)
122
- nokogiri (1.13.3)
123
- mini_portile2 (~> 2.8.0)
137
+ nio4r (2.7.3)
138
+ nokogiri (1.16.6)
139
+ mini_portile2 (~> 2.8.2)
124
140
  racc (~> 1.4)
125
- nokogiri (1.13.3-x86_64-darwin)
141
+ nokogiri (1.16.6-x86_64-darwin)
126
142
  racc (~> 1.4)
127
- parallel (1.21.0)
128
- parser (3.0.2.0)
143
+ parallel (1.25.1)
144
+ parser (3.3.4.0)
129
145
  ast (~> 2.4.1)
130
- racc (1.6.0)
131
- rack (2.2.3)
132
- rack-test (1.1.0)
133
- rack (>= 1.0, < 3)
134
- rails (7.0.2.2)
135
- actioncable (= 7.0.2.2)
136
- actionmailbox (= 7.0.2.2)
137
- actionmailer (= 7.0.2.2)
138
- actionpack (= 7.0.2.2)
139
- actiontext (= 7.0.2.2)
140
- actionview (= 7.0.2.2)
141
- activejob (= 7.0.2.2)
142
- activemodel (= 7.0.2.2)
143
- activerecord (= 7.0.2.2)
144
- activestorage (= 7.0.2.2)
145
- activesupport (= 7.0.2.2)
146
+ racc
147
+ psych (5.1.2)
148
+ stringio
149
+ racc (1.8.0)
150
+ rack (3.1.6)
151
+ rack-session (2.0.0)
152
+ rack (>= 3.0.0)
153
+ rack-test (2.1.0)
154
+ rack (>= 1.3)
155
+ rackup (2.1.0)
156
+ rack (>= 3)
157
+ webrick (~> 1.8)
158
+ rails (7.1.3.4)
159
+ actioncable (= 7.1.3.4)
160
+ actionmailbox (= 7.1.3.4)
161
+ actionmailer (= 7.1.3.4)
162
+ actionpack (= 7.1.3.4)
163
+ actiontext (= 7.1.3.4)
164
+ actionview (= 7.1.3.4)
165
+ activejob (= 7.1.3.4)
166
+ activemodel (= 7.1.3.4)
167
+ activerecord (= 7.1.3.4)
168
+ activestorage (= 7.1.3.4)
169
+ activesupport (= 7.1.3.4)
146
170
  bundler (>= 1.15.0)
147
- railties (= 7.0.2.2)
148
- rails-dom-testing (2.0.3)
149
- activesupport (>= 4.2.0)
171
+ railties (= 7.1.3.4)
172
+ rails-dom-testing (2.2.0)
173
+ activesupport (>= 5.0.0)
174
+ minitest
150
175
  nokogiri (>= 1.6)
151
- rails-html-sanitizer (1.4.2)
152
- loofah (~> 2.3)
153
- railties (7.0.2.2)
154
- actionpack (= 7.0.2.2)
155
- activesupport (= 7.0.2.2)
156
- method_source
176
+ rails-html-sanitizer (1.6.0)
177
+ loofah (~> 2.21)
178
+ nokogiri (~> 1.14)
179
+ railties (7.1.3.4)
180
+ actionpack (= 7.1.3.4)
181
+ activesupport (= 7.1.3.4)
182
+ irb
183
+ rackup (>= 1.0.0)
157
184
  rake (>= 12.2)
158
- thor (~> 1.0)
159
- zeitwerk (~> 2.5)
160
- rainbow (3.0.0)
161
- rake (13.0.6)
162
- rb-fsevent (0.11.0)
163
- rb-inotify (0.10.1)
185
+ thor (~> 1.0, >= 1.2.2)
186
+ zeitwerk (~> 2.6)
187
+ rainbow (3.1.1)
188
+ rake (13.2.1)
189
+ rb-fsevent (0.11.2)
190
+ rb-inotify (0.11.1)
164
191
  ffi (~> 1.0)
165
- regexp_parser (2.1.1)
166
- rexml (3.2.5)
167
- rubocop (1.23.0)
192
+ rdoc (6.7.0)
193
+ psych (>= 4.0.0)
194
+ regexp_parser (2.9.2)
195
+ reline (0.5.9)
196
+ io-console (~> 0.5)
197
+ rexml (3.3.1)
198
+ strscan
199
+ rubocop (1.65.0)
200
+ json (~> 2.3)
201
+ language_server-protocol (>= 3.17.0)
168
202
  parallel (~> 1.10)
169
- parser (>= 3.0.0.0)
203
+ parser (>= 3.3.0.2)
170
204
  rainbow (>= 2.2.2, < 4.0)
171
- regexp_parser (>= 1.8, < 3.0)
172
- rexml
173
- rubocop-ast (>= 1.12.0, < 2.0)
205
+ regexp_parser (>= 2.4, < 3.0)
206
+ rexml (>= 3.2.5, < 4.0)
207
+ rubocop-ast (>= 1.31.1, < 2.0)
174
208
  ruby-progressbar (~> 1.7)
175
- unicode-display_width (>= 1.4.0, < 3.0)
176
- rubocop-ast (1.13.0)
177
- parser (>= 3.0.1.1)
178
- ruby-progressbar (1.11.0)
179
- ruby-vips (2.1.4)
209
+ unicode-display_width (>= 2.4.0, < 3.0)
210
+ rubocop-ast (1.31.3)
211
+ parser (>= 3.3.1.0)
212
+ ruby-progressbar (1.13.0)
213
+ ruby-vips (2.2.1)
180
214
  ffi (~> 1.12)
181
- sqlite3 (1.4.2)
182
- strscan (3.0.1)
183
- thor (1.2.1)
184
- timeout (0.2.0)
185
- tzinfo (2.0.4)
215
+ sqlite3 (2.0.2)
216
+ mini_portile2 (~> 2.8.0)
217
+ sqlite3 (2.0.2-x86_64-darwin)
218
+ stringio (3.1.1)
219
+ strscan (3.1.0)
220
+ thor (1.3.1)
221
+ timeout (0.4.1)
222
+ tzinfo (2.0.6)
186
223
  concurrent-ruby (~> 1.0)
187
- unicode-display_width (2.1.0)
188
- websocket-driver (0.7.5)
224
+ unicode-display_width (2.5.0)
225
+ webrick (1.8.1)
226
+ websocket-driver (0.7.6)
189
227
  websocket-extensions (>= 0.1.0)
190
228
  websocket-extensions (0.1.5)
191
- zeitwerk (2.5.4)
229
+ zeitwerk (2.6.16)
192
230
 
193
231
  PLATFORMS
194
232
  ruby
@@ -203,4 +241,4 @@ DEPENDENCIES
203
241
  sqlite3
204
242
 
205
243
  BUNDLED WITH
206
- 2.3.2
244
+ 2.4.22
data/README.md CHANGED
@@ -2,10 +2,15 @@
2
2
 
3
3
  Images in Ruby on Rails, as lightweight as possible!
4
4
 
5
- ![Kamifūsen in Yamagata](https://upload.wikimedia.org/wikipedia/commons/thumb/0/0d/%E4%B8%AD%E6%B4%A5%E5%B7%9D%E9%9B%AA%E3%81%BE%E3%81%A4%E3%82%8A.jpg/1024px-%E4%B8%AD%E6%B4%A5%E5%B7%9D%E9%9B%AA%E3%81%BE%E3%81%A4%E3%82%8A.jpg)
5
+
6
+ ![Kamifūsen in Yamagata](image.jpg?raw=true)
6
7
 
7
8
  ## Installation
8
9
 
10
+ Active Storage must be properly installed, with a solution set for the background jobs (we use Delayed Job).
11
+ - https://edgeguides.rubyonrails.org/active_storage_overview.html
12
+ - https://edgeguides.rubyonrails.org/active_job_basics.html#job-execution
13
+
9
14
  Add this line to your application's Gemfile:
10
15
 
11
16
  ```ruby
@@ -20,6 +25,10 @@ Or install it yourself as:
20
25
 
21
26
  $ gem install kamifusen
22
27
 
28
+ ## Usage
29
+
30
+ Simply use `kamifusen_tag` instead of `image_tag` in your rails views.
31
+
23
32
  In the views, use (where object is an active record model, and image is an active storage attachment):
24
33
 
25
34
  ```erb
@@ -39,9 +48,12 @@ config.action_view.sanitized_allowed_tags = ['picture', 'source', 'img']
39
48
  config.action_view.sanitized_allowed_attributes = ['src', 'type', 'srcset', 'width', 'height', 'alt', 'sizes', 'loading', 'decoding']
40
49
  ```
41
50
 
42
- ## Usage
51
+ You can use the cache for the fragment, by setting
52
+ ```erb
53
+ <%= kamifusen_tag object.image, alt: 'A nice image', cached: true %>
54
+ ```
43
55
 
44
- Simply use `kamifusen_tag` instead of `image_tag` in your rails views.## What's the problem?
56
+ ## What's the problem?
45
57
 
46
58
  ### The initial situation
47
59
 
@@ -128,10 +140,36 @@ It generates a code like:
128
140
  <source srcset="image-400w.webp, image-800w.webp 2x" type="image/webp" media="(min-width: 400px)">
129
141
  <source srcset="image-800w.jpg, image-1600w.jpg 2x" type="image/jpg" media="(min-width: 800px)">
130
142
  <source srcset="image-400w.jpg, image-800w.jpg 2x" type="image/jpg" media="(min-width: 400px)">
131
- <img src="image-800.jpg" alt="A nice image" srcset="image-800.jpg, image-1600.jpg 2x">
143
+ <img src="image-800.jpg" alt="A nice image" srcset="image-800.jpg, image-1600.jpg 2x" loading="lazy">
132
144
  </picture>
133
145
  ```
134
146
 
147
+ ### Parameters
148
+
149
+ You can set different parameters :
150
+
151
+ ```
152
+ class: "img_class",
153
+ alt: "alt",
154
+ height: height,
155
+ width: width,
156
+ sizes: sizes,
157
+ active_storage_direct_url: direct_url,
158
+ async: async
159
+ ```
160
+
161
+ Example of sizes parameter :
162
+
163
+ ```
164
+ sizes: {
165
+ '(max-width: 576px)': '315px',
166
+ '(max-width: 991px)': '210px',
167
+ '(max-width: 1199px)': '290px',
168
+ '(max-width: 1439px)': '350px',
169
+ '(min-width: 1440px)': '420px'
170
+ }
171
+ ```
172
+
135
173
  ## References
136
174
 
137
175
  - https://developer.mozilla.org/fr/docs/Learn/HTML/Multimedia_and_embedding/Responsive_images
@@ -156,7 +194,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
156
194
 
157
195
  ## Contributing
158
196
 
159
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/kamifusen. 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/[USERNAME]/kamifusen/blob/master/CODE_OF_CONDUCT.md).
197
+ Bug reports and pull requests are welcome on GitHub at https://github.com/noesya/kamifusen. 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/[USERNAME]/kamifusen/blob/master/CODE_OF_CONDUCT.md).
160
198
 
161
199
  ## License
162
200
 
@@ -1,94 +1,104 @@
1
1
  <%
2
- options ||= {}
3
- title = options[:title]
4
- alt = options[:alt]
5
- data = options[:data]
6
- async = options.has_key?(:async) ? options[:async] : true
7
- active_storage_direct_url = options.has_key?(:active_storage_direct_url) ? options[:active_storage_direct_url] : false
8
- klass = options[:class]
9
- picture_class = options[:picture_class]
10
- width = options[:width]
11
- height = options[:height]
12
-
13
- variant_sizes = Kamifusen.sizes.dup
14
- quality = Kamifusen.quality.dup
2
+ source_is_set = false
3
+ if source.is_a? ActiveStorage::Blob
4
+ source_is_set = true
5
+ elsif source.respond_to?(:attached?)
6
+ source_is_set = source.attached?
7
+ end
8
+ %>
9
+ <%
10
+ if source_is_set
11
+ options ||= {}
12
+ cached = options.dig(:cached)
13
+ cache_if(cached, [source, options]) do
14
+ title = options[:title]
15
+ alt = options[:alt]
16
+ data = options[:data]
17
+ async = options.has_key?(:async) ? options[:async] : true
18
+ active_storage_direct_url = options.has_key?(:active_storage_direct_url) ? options[:active_storage_direct_url] : false
19
+ klass = options[:class]
20
+ picture_class = options[:picture_class]
21
+ width = options[:width]
22
+ height = options[:height]
23
+ variant_sizes = Kamifusen.sizes.dup
24
+ quality = Kamifusen.quality.dup
15
25
 
16
- sizes = options[:sizes] || {}
17
- sizes_value = sizes.map { |key, value| [key, value].join(' ').strip }.join(', ')
26
+ sizes = options[:sizes] || {}
27
+ sizes_value = sizes.map { |key, value| [key, value].join(' ').strip }.join(', ')
18
28
 
19
- if source&.analyzed? && source.metadata.has_key?('width') && source.metadata.has_key?('height')
20
- image_width = source.metadata['width']
21
- image_height = source.metadata['height']
22
- image_ratio = 1.0 * image_width / image_height
23
- if width.nil? && height.nil?
24
- # Image real dimensions
25
- width = [image_width, variant_sizes.last].min
26
- height = width / image_ratio
27
- elsif width.nil?
28
- # Calculated width, preserving the aspect ratio
29
- width = height * image_ratio
30
- elsif height.nil?
31
- # Calculated height, preserving the aspect ratio
32
- height = width / image_ratio
33
- else
34
- # Explicit dimensions. We redefine the height if aspect ratio is not preserved.
35
- width = [image_width, width].min
36
- height = width / image_ratio
37
- end
38
- width = width.round
39
- height = height.round
40
- end
29
+ if source&.analyzed? && source.metadata.has_key?('width') && source.metadata.has_key?('height')
30
+ image_width = source.metadata['width']
31
+ image_height = source.metadata['height']
32
+ image_ratio = 1.0 * image_width / image_height
33
+ if width.nil? && height.nil?
34
+ # Image real dimensions
35
+ width = [image_width, variant_sizes.last].min
36
+ height = width / image_ratio
37
+ elsif width.nil?
38
+ # Calculated width, preserving the aspect ratio
39
+ width = height * image_ratio
40
+ elsif height.nil?
41
+ # Calculated height, preserving the aspect ratio
42
+ height = width / image_ratio
43
+ else
44
+ # Explicit dimensions. We redefine the height if aspect ratio is not preserved.
45
+ width = [image_width, width].min
46
+ height = width / image_ratio
47
+ end
48
+ width = width.round
49
+ height = height.round
50
+ end
41
51
 
42
- parameters = ""
43
- parameters += " loading=\"lazy\" decoding=\"async\"" if async
44
- parameters += " alt=\"#{alt}\"" if alt
45
- parameters += " title=\"#{title}\"" if title
46
- parameters += " width=\"#{width}\"" if width
47
- parameters += " height=\"#{height}\"" if height
48
- parameters += " class=\"#{klass}\"" if klass
49
- if data
50
- data.each do |entry|
51
- parameters += " data-#{entry.first.to_s}=\"#{entry.last}\""
52
- end
53
- end
54
- %>
55
- <% if source.variable? %>
56
- <%
57
- # Computing
58
- if width
59
- width_retina = width * 2
60
- variant_sizes.reject! { |size| size > width_retina }
61
- variant_sizes << width_retina
62
- variant_sizes.uniq!
63
- end
64
- default_width = variant_sizes.max
65
- default_width = width_retina if width_retina && width_retina > default_width
66
- if Kamifusen.with_webp
67
- srcset_webp = variant_sizes.map { |size|
68
- variant = source.variant(resize: "#{size}>", format: :webp, quality: quality)
69
- "#{ Kamifusen.process(variant, active_storage_direct_url) } #{size}w"
70
- }.join(', ')
71
- end
72
- srcset_default = variant_sizes.map { |size|
73
- variant = source.variant(resize: "#{size}>", quality: quality)
74
- "#{ Kamifusen.process(variant, active_storage_direct_url) } #{size}w"
75
- }.join(', ')
76
- variant = source.variant(resize: "#{default_width}>", quality: quality)
77
- default = Kamifusen.process(variant, active_storage_direct_url)
78
- %>
79
- <picture<%= " class=\"#{picture_class}\"".html_safe unless picture_class.blank? %>>
80
- <% if Kamifusen.with_webp %>
81
- <source srcset="<%= raw srcset_webp %>"
82
- <%= " sizes=\"#{sizes_value}\"".html_safe unless sizes.empty? %>
83
- type="image/webp">
52
+ parameters = ""
53
+ parameters += " loading=\"lazy\" decoding=\"async\"" if async
54
+ parameters += " alt=\"#{alt}\"" if alt
55
+ parameters += " title=\"#{title}\"" if title
56
+ parameters += " width=\"#{width}\"" if width
57
+ parameters += " height=\"#{height}\"" if height
58
+ parameters += " class=\"#{klass}\"" if klass
59
+ if data
60
+ data.each do |entry|
61
+ parameters += " data-#{entry.first.to_s}=\"#{entry.last}\""
62
+ end
63
+ end
64
+ if source.variable?
65
+ # Computing
66
+ if width
67
+ width_retina = width * 2
68
+ variant_sizes.reject! { |size| size > width_retina }
69
+ variant_sizes << width_retina
70
+ variant_sizes.uniq!
71
+ end
72
+ default_width = variant_sizes.max
73
+ default_width = width_retina if width_retina && width_retina > default_width
74
+ if Kamifusen.with_webp
75
+ srcset_webp = variant_sizes.map { |size|
76
+ variant = source.variant(resize: "#{size}>", format: :webp, quality: quality)
77
+ "#{ Kamifusen.process(variant, active_storage_direct_url) } #{size}w"
78
+ }.join(', ')
79
+ end
80
+ srcset_default = variant_sizes.map { |size|
81
+ variant = source.variant(resize: "#{size}>", quality: quality)
82
+ "#{ Kamifusen.process(variant, active_storage_direct_url) } #{size}w"
83
+ }.join(', ')
84
+ variant = source.variant(resize: "#{default_width}>", quality: quality)
85
+ default = Kamifusen.process(variant, active_storage_direct_url)
86
+ %>
87
+ <picture<%= " class=\"#{picture_class}\"".html_safe unless picture_class.blank? %>>
88
+ <% if Kamifusen.with_webp %>
89
+ <source srcset="<%= raw srcset_webp %>"
90
+ <%= " sizes=\"#{sizes_value}\"".html_safe unless sizes.empty? %>
91
+ type="image/webp">
92
+ <% end %>
93
+ <source srcset="<%= raw srcset_default %>"
94
+ <%= " sizes=\"#{sizes_value}\"".html_safe unless sizes.empty? %>
95
+ type="<%= source.content_type %>">
96
+ <img src="<%= raw default %>" <%= raw parameters %>>
97
+ </picture>
98
+ <% else %>
99
+ <picture>
100
+ <img src="<%= url_for source %>" type="<%= source.content_type %>"<%= raw parameters %>>
101
+ </picture>
84
102
  <% end %>
85
- <source srcset="<%= raw srcset_default %>"
86
- <%= " sizes=\"#{sizes_value}\"".html_safe unless sizes.empty? %>
87
- type="<%= source.content_type %>">
88
- <img src="<%= raw default %>" <%= raw parameters %>>
89
- </picture>
90
- <% else %>
91
- <picture>
92
- <img src="<%= url_for source %>" type="<%= source.content_type %>"<%= raw parameters %>>
93
- </picture>
103
+ <% end %>
94
104
  <% end %>
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Kamifusen
4
- VERSION = "1.11.2"
4
+ VERSION = "1.12.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kamifusen
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.11.2
4
+ version: 1.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sébastien Moulène
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2022-02-23 00:00:00.000000000 Z
12
+ date: 2024-07-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -117,7 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
117
  - !ruby/object:Gem::Version
118
118
  version: '0'
119
119
  requirements: []
120
- rubygems_version: 3.1.6
120
+ rubygems_version: 3.4.10
121
121
  signing_key:
122
122
  specification_version: 4
123
123
  summary: Images, light as balloons