kamifusen 1.11.1 → 1.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +173 -135
- data/README.md +43 -5
- data/app/views/kamifusen/_view.html.erb +98 -88
- data/lib/kamifusen/processor.rb +3 -3
- data/lib/kamifusen/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 267a1dc5741237d4a1255563dcb2f7fccb7717233ae02ad17b32d8829e9dd8d8
|
4
|
+
data.tar.gz: 24662f9214bbbc62cfb9268ff88a071d4d0bb5cf85e82902b0b1cf20f7cf409b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
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.
|
12
|
-
actionpack (= 7.
|
13
|
-
activesupport (= 7.
|
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
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
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.
|
27
|
-
actionpack (= 7.
|
28
|
-
actionview (= 7.
|
29
|
-
activejob (= 7.
|
30
|
-
activesupport (= 7.
|
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.
|
36
|
-
actionpack (7.
|
37
|
-
actionview (= 7.
|
38
|
-
activesupport (= 7.
|
39
|
-
|
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.
|
42
|
-
rails-html-sanitizer (~> 1.
|
43
|
-
actiontext (7.
|
44
|
-
actionpack (= 7.
|
45
|
-
activerecord (= 7.
|
46
|
-
activestorage (= 7.
|
47
|
-
activesupport (= 7.
|
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.
|
51
|
-
activesupport (= 7.
|
54
|
+
actionview (7.1.3.4)
|
55
|
+
activesupport (= 7.1.3.4)
|
52
56
|
builder (~> 3.1)
|
53
|
-
erubi (~> 1.
|
54
|
-
rails-dom-testing (~> 2.
|
55
|
-
rails-html-sanitizer (~> 1.
|
56
|
-
activejob (7.
|
57
|
-
activesupport (= 7.
|
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.
|
60
|
-
activesupport (= 7.
|
61
|
-
activerecord (7.
|
62
|
-
activemodel (= 7.
|
63
|
-
activesupport (= 7.
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
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
|
-
|
71
|
-
|
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
|
-
|
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.
|
90
|
+
concurrent-ruby (1.3.3)
|
91
|
+
connection_pool (2.4.1)
|
80
92
|
crass (1.0.6)
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
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.
|
102
|
+
image_processing (1.12.2)
|
89
103
|
mini_magick (>= 4.9.5, < 5)
|
90
104
|
ruby-vips (>= 2.0.17, < 3)
|
91
|
-
io-
|
92
|
-
|
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.
|
114
|
+
loofah (2.22.0)
|
96
115
|
crass (~> 1.0.2)
|
97
|
-
nokogiri (>= 1.
|
98
|
-
mail (2.
|
116
|
+
nokogiri (>= 1.12.0)
|
117
|
+
mail (2.8.1)
|
99
118
|
mini_mime (>= 0.1.1)
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
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
|
-
|
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-
|
115
|
-
io-wait
|
116
|
-
timeout
|
117
|
-
net-smtp (0.3.1)
|
118
|
-
digest
|
135
|
+
net-smtp (0.5.0)
|
119
136
|
net-protocol
|
120
|
-
|
121
|
-
|
122
|
-
|
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.
|
141
|
+
nokogiri (1.16.6-x86_64-darwin)
|
126
142
|
racc (~> 1.4)
|
127
|
-
parallel (1.
|
128
|
-
parser (3.
|
143
|
+
parallel (1.25.1)
|
144
|
+
parser (3.3.4.0)
|
129
145
|
ast (~> 2.4.1)
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
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.
|
148
|
-
rails-dom-testing (2.0
|
149
|
-
activesupport (>=
|
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.
|
152
|
-
loofah (~> 2.
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
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.
|
160
|
-
rainbow (3.
|
161
|
-
rake (13.
|
162
|
-
rb-fsevent (0.11.
|
163
|
-
rb-inotify (0.
|
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
|
-
|
166
|
-
|
167
|
-
|
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.
|
203
|
+
parser (>= 3.3.0.2)
|
170
204
|
rainbow (>= 2.2.2, < 4.0)
|
171
|
-
regexp_parser (>=
|
172
|
-
rexml
|
173
|
-
rubocop-ast (>= 1.
|
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 (>=
|
176
|
-
rubocop-ast (1.
|
177
|
-
parser (>= 3.
|
178
|
-
ruby-progressbar (1.
|
179
|
-
ruby-vips (2.1
|
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 (
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
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.
|
188
|
-
|
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.
|
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.
|
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
|
-
|
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
|
-
|
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
|
-
|
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/
|
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
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
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
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
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
|
-
|
51
|
-
|
52
|
-
|
53
|
-
end
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
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
|
-
|
86
|
-
<%= " sizes=\"#{sizes_value}\"".html_safe unless sizes.empty? %>
|
87
|
-
type="<%= source.content_type %>">
|
88
|
-
<img src="<%= 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 %>
|
data/lib/kamifusen/processor.rb
CHANGED
@@ -17,14 +17,14 @@ module Kamifusen
|
|
17
17
|
def keycdn_url
|
18
18
|
url = "#{Kamifusen.keycdn}/#{variant.blob.key}?"
|
19
19
|
transformations = variant.variation.transformations
|
20
|
-
url += "
|
21
|
-
url += "
|
20
|
+
url += "format=#{transformations[:format]}&" if transformations.has_key? :format
|
21
|
+
url += "quality=#{transformations[:quality]}&" if transformations.has_key? :quality
|
22
22
|
if transformations.has_key? :resize
|
23
23
|
resize = transformations[:resize]
|
24
24
|
# 100>
|
25
25
|
if '>'.in? resize
|
26
26
|
width = resize.split('>').first.to_i
|
27
|
-
url += "
|
27
|
+
url += "width=#{width}&"
|
28
28
|
end
|
29
29
|
end
|
30
30
|
url
|
data/lib/kamifusen/version.rb
CHANGED
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.
|
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:
|
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.
|
120
|
+
rubygems_version: 3.4.10
|
121
121
|
signing_key:
|
122
122
|
specification_version: 4
|
123
123
|
summary: Images, light as balloons
|