kamifusen 1.9 → 1.10.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +13 -11
- data/LICENSE +1 -1
- data/README.md +8 -1
- data/app/views/kamifusen/_view.html.erb +36 -36
- data/lib/kamifusen/version.rb +1 -1
- metadata +2 -3
- data/LICENSE.txt +0 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 56bd55356abc2f8c35701c288a89c82f0bde23ad807987eba2c129e28773e1ae
|
4
|
+
data.tar.gz: 10cc826b4de7b4de04de7ede89d3700c0fc9e9e581366df41f22d556ad56f788
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7a59010f32ab196d5228f0065eb7f46bdea8131cb1e861716346e25beb5e9458b574e9979fa63eb2469b8c36e8a69c6bf2f0742d8b365b04215bd9887aeb29be
|
7
|
+
data.tar.gz: 6ab4e8e652dca4ec6c6edd68a0c89c2301b1b9eb0e5396f322bdb26e535a2d358be4633aa29e501fdaabe95e739f9d842498807d2d03e247da801f3ef6c5b05d
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
kamifusen (1.
|
4
|
+
kamifusen (1.10.3)
|
5
5
|
image_processing
|
6
6
|
rails
|
7
7
|
|
@@ -76,7 +76,7 @@ GEM
|
|
76
76
|
ffi (1.15.3)
|
77
77
|
globalid (0.5.2)
|
78
78
|
activesupport (>= 5.0)
|
79
|
-
i18n (1.8.
|
79
|
+
i18n (1.8.11)
|
80
80
|
concurrent-ruby (~> 1.0)
|
81
81
|
image_processing (1.12.1)
|
82
82
|
mini_magick (>= 4.9.5, < 5)
|
@@ -89,20 +89,22 @@ GEM
|
|
89
89
|
nokogiri (>= 1.5.9)
|
90
90
|
mail (2.7.1)
|
91
91
|
mini_mime (>= 0.1.1)
|
92
|
-
marcel (1.0.
|
92
|
+
marcel (1.0.2)
|
93
93
|
method_source (1.0.0)
|
94
94
|
mini_magick (4.11.0)
|
95
|
-
mini_mime (1.1.
|
95
|
+
mini_mime (1.1.2)
|
96
96
|
mini_portile2 (2.6.1)
|
97
97
|
minitest (5.14.4)
|
98
98
|
nio4r (2.5.8)
|
99
|
-
nokogiri (1.12.
|
99
|
+
nokogiri (1.12.5)
|
100
100
|
mini_portile2 (~> 2.6.1)
|
101
101
|
racc (~> 1.4)
|
102
|
+
nokogiri (1.12.5-x86_64-darwin)
|
103
|
+
racc (~> 1.4)
|
102
104
|
parallel (1.20.1)
|
103
105
|
parser (3.0.1.1)
|
104
106
|
ast (~> 2.4.1)
|
105
|
-
racc (1.
|
107
|
+
racc (1.6.0)
|
106
108
|
rack (2.2.3)
|
107
109
|
rack-test (1.1.0)
|
108
110
|
rack (>= 1.0, < 3)
|
@@ -156,9 +158,9 @@ GEM
|
|
156
158
|
sprockets (4.0.2)
|
157
159
|
concurrent-ruby (~> 1.0)
|
158
160
|
rack (> 1, < 3)
|
159
|
-
sprockets-rails (3.
|
160
|
-
actionpack (>=
|
161
|
-
activesupport (>=
|
161
|
+
sprockets-rails (3.4.0)
|
162
|
+
actionpack (>= 5.2)
|
163
|
+
activesupport (>= 5.2)
|
162
164
|
sprockets (>= 3.0.0)
|
163
165
|
sqlite3 (1.4.2)
|
164
166
|
thor (1.1.0)
|
@@ -168,7 +170,7 @@ GEM
|
|
168
170
|
websocket-driver (0.7.5)
|
169
171
|
websocket-extensions (>= 0.1.0)
|
170
172
|
websocket-extensions (0.1.5)
|
171
|
-
zeitwerk (2.
|
173
|
+
zeitwerk (2.5.1)
|
172
174
|
|
173
175
|
PLATFORMS
|
174
176
|
ruby
|
@@ -183,4 +185,4 @@ DEPENDENCIES
|
|
183
185
|
sqlite3
|
184
186
|
|
185
187
|
BUNDLED WITH
|
186
|
-
2.2.
|
188
|
+
2.2.30
|
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -32,6 +32,13 @@ If you want to disable webp, in config/initializers/kamifusen.rb:
|
|
32
32
|
Kamifusen.with_webp = false
|
33
33
|
```
|
34
34
|
|
35
|
+
If you render kamifusen tags inside a sanitized text, please make sure you allow these tags and attributes in `config/application.yml`:
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
config.action_view.sanitized_allowed_tags = ['picture', 'source', 'img']
|
39
|
+
config.action_view.sanitized_allowed_attributes = ['src', 'type', 'srcset', 'width', 'height', 'alt', 'sizes', 'loading', 'decoding']
|
40
|
+
```
|
41
|
+
|
35
42
|
## Usage
|
36
43
|
|
37
44
|
Simply use `kamifusen_tag` instead of `image_tag` in your rails views.## What's the problem?
|
@@ -103,7 +110,7 @@ Webp and AVIF are more efficient formats than jpg and png. They allow better com
|
|
103
110
|
|
104
111
|
### The final situation
|
105
112
|
|
106
|
-
https://
|
113
|
+
https://noesya.github.io/kamifusen/
|
107
114
|
|
108
115
|
The new helper is:
|
109
116
|
|
@@ -1,52 +1,48 @@
|
|
1
1
|
<%
|
2
|
-
# image_tag options
|
3
2
|
options ||= {}
|
4
3
|
alt = options[:alt]
|
5
|
-
async = options.has_key?(:async)
|
6
|
-
|
7
|
-
active_storage_direct_url = options.has_key?(:active_storage_direct_url) ? options[:active_storage_direct_url]
|
8
|
-
: false
|
4
|
+
async = options.has_key?(:async) ? options[:async] : true
|
5
|
+
active_storage_direct_url = options.has_key?(:active_storage_direct_url) ? options[:active_storage_direct_url] : false
|
9
6
|
klass = options[:class]
|
10
7
|
picture_class = options[:picture_class]
|
11
8
|
width = options[:width]
|
12
9
|
height = options[:height]
|
13
10
|
|
14
|
-
|
15
|
-
quality = Kamifusen.quality
|
11
|
+
variant_sizes = Kamifusen.sizes.dup
|
12
|
+
quality = Kamifusen.quality.dup
|
16
13
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
14
|
+
sizes = options[:sizes] || {}
|
15
|
+
sizes_value = sizes.map { |key, value| [key, value].join(' ').strip }.join(', ')
|
16
|
+
|
17
|
+
if source&.analyzed? && source.metadata.has_key?('width') && source.metadata.has_key?('height')
|
21
18
|
image_width = source.metadata['width']
|
22
19
|
image_height = source.metadata['height']
|
23
20
|
image_ratio = 1.0 * image_width / image_height
|
24
21
|
if width.nil? && height.nil?
|
25
|
-
#
|
26
|
-
width = [image_width,
|
27
|
-
height = width
|
22
|
+
# Image real dimensions
|
23
|
+
width = [image_width, variant_sizes.last].min
|
24
|
+
height = width / image_ratio
|
28
25
|
elsif width.nil?
|
29
|
-
#
|
26
|
+
# Calculated width, preserving the aspect ratio
|
30
27
|
width = height * image_ratio
|
31
28
|
elsif height.nil?
|
32
|
-
#
|
29
|
+
# Calculated height, preserving the aspect ratio
|
33
30
|
height = width / image_ratio
|
34
31
|
else
|
35
|
-
#
|
36
|
-
# si le ratio demandé n'est pas celui de l'image,
|
37
|
-
# Redéfinir la height
|
32
|
+
# Explicit dimensions. We redefine the height if aspect ratio is not preserved.
|
38
33
|
width = [image_width, width].min
|
39
34
|
height = width / image_ratio
|
40
35
|
end
|
41
36
|
width = width.round
|
42
37
|
height = height.round
|
43
38
|
end
|
39
|
+
|
44
40
|
parameters = ""
|
45
41
|
parameters += " loading=\"lazy\" decoding=\"async\"" if async
|
46
|
-
parameters += " alt=\"#{
|
47
|
-
parameters += " width=\"#{
|
48
|
-
parameters += " height=\"#{
|
49
|
-
parameters += " class=\"#{
|
42
|
+
parameters += " alt=\"#{alt}\"" if alt
|
43
|
+
parameters += " width=\"#{width}\"" if width
|
44
|
+
parameters += " height=\"#{height}\"" if height
|
45
|
+
parameters += " class=\"#{klass}\"" if klass
|
50
46
|
|
51
47
|
def kamifusen_process(variant, active_storage_direct_url)
|
52
48
|
if active_storage_direct_url
|
@@ -54,45 +50,49 @@ def kamifusen_process(variant, active_storage_direct_url)
|
|
54
50
|
# Pour générer la processed url, il faut savoir où sont stockées les images
|
55
51
|
# https://discuss.rubyonrails.org/t/define-host-so-absolute-urls-work-in-development-and-test/75085
|
56
52
|
# https://stackoverflow.com/questions/60425407/uriinvalidurierror-bad-uriis-not-uri-nil-active-storage-service-url
|
57
|
-
# Not compatible with Disk storage, will return nil
|
58
53
|
url = variant.processed.url
|
59
54
|
rescue
|
55
|
+
# Not compatible with DiskService, which returns a URI::InvalidURIError
|
60
56
|
end
|
61
57
|
end
|
62
|
-
url
|
58
|
+
url ||= url_for(variant)
|
63
59
|
url
|
64
60
|
end
|
65
61
|
%>
|
66
62
|
<% if source.variable? %>
|
67
|
-
<%#= "#{image_width} x #{image_height}, #{image_ratio} ratio => #{width} x #{height}<br>".html_safe %>
|
68
63
|
<%
|
69
64
|
# Computing
|
70
65
|
if width
|
71
66
|
width_retina = width * 2
|
72
|
-
|
73
|
-
|
74
|
-
|
67
|
+
variant_sizes.reject! { |size| size > width_retina }
|
68
|
+
variant_sizes << width_retina
|
69
|
+
variant_sizes.uniq!
|
75
70
|
end
|
76
|
-
default_width =
|
71
|
+
default_width = variant_sizes.max
|
77
72
|
default_width = width_retina if width_retina && width_retina > default_width
|
78
73
|
if Kamifusen.with_webp
|
79
|
-
srcset_webp =
|
74
|
+
srcset_webp = variant_sizes.map { |size|
|
80
75
|
variant = source.variant(resize: "#{size}>", format: :webp, quality: quality)
|
81
|
-
"#{ kamifusen_process(variant, active_storage_direct_url) } #{
|
76
|
+
"#{ kamifusen_process(variant, active_storage_direct_url) } #{size}w"
|
82
77
|
}.join(', ')
|
83
78
|
end
|
84
|
-
srcset_default =
|
79
|
+
srcset_default = variant_sizes.map { |size|
|
85
80
|
variant = source.variant(resize: "#{size}>", quality: quality)
|
86
|
-
"#{ kamifusen_process(variant, active_storage_direct_url) } #{
|
81
|
+
"#{ kamifusen_process(variant, active_storage_direct_url) } #{size}w"
|
87
82
|
}.join(', ')
|
88
83
|
variant = source.variant(resize: "#{default_width}>", quality: quality)
|
89
84
|
default = kamifusen_process(variant, active_storage_direct_url)
|
90
85
|
%>
|
91
86
|
<picture<%= " class=\"#{picture_class}\"".html_safe unless picture_class.blank? %>>
|
92
87
|
<% if Kamifusen.with_webp %>
|
93
|
-
<source srcset="<%= srcset_webp %>"
|
88
|
+
<source srcset="<%= srcset_webp %>"
|
89
|
+
<%= " sizes=\"#{sizes_value}\"".html_safe unless sizes.empty? %>
|
90
|
+
type="image/webp">
|
94
91
|
<% end %>
|
95
|
-
<
|
92
|
+
<source srcset="<%= srcset_default %>"
|
93
|
+
<%= " sizes=\"#{sizes_value}\"".html_safe unless sizes.empty? %>
|
94
|
+
type="<%= source.content_type %>">
|
95
|
+
<img src="<%= default %>" <%= raw parameters %>>
|
96
96
|
</picture>
|
97
97
|
<% else %>
|
98
98
|
<picture>
|
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:
|
4
|
+
version: 1.10.3
|
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: 2021-
|
12
|
+
date: 2021-11-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -82,7 +82,6 @@ files:
|
|
82
82
|
- Gemfile
|
83
83
|
- Gemfile.lock
|
84
84
|
- LICENSE
|
85
|
-
- LICENSE.txt
|
86
85
|
- README.md
|
87
86
|
- Rakefile
|
88
87
|
- app/views/kamifusen/_view.html.erb
|
data/LICENSE.txt
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
The MIT License (MIT)
|
2
|
-
|
3
|
-
Copyright (c) 2021 Arnaud Levy
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
7
|
-
in the Software without restriction, including without limitation the rights
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
10
|
-
furnished to do so, subject to the following conditions:
|
11
|
-
|
12
|
-
The above copyright notice and this permission notice shall be included in
|
13
|
-
all copies or substantial portions of the Software.
|
14
|
-
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
-
THE SOFTWARE.
|