kamifusen 0.9.4 → 1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -0
- data/Gemfile.lock +10 -8
- data/README.md +30 -16
- data/app/views/kamifusen/_view.html.erb +22 -7
- data/lib/kamifusen.rb +5 -0
- data/lib/kamifusen/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 87b7ea289164bd1a3be5022b75ac1f9c9b8a0151b08219579d44a83403ad03cf
|
4
|
+
data.tar.gz: ed491636014069469b311b19c7d80175ed2cd6d757b87ce938a1170129ea9f88
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 418792aa2edb5b1534a5450a893fa74338a43bd92d773715b303eb8e675bfc0359abb3925aec6cb70cc7e2e0bf1286f16e1d2bb0d3aea6e62cc16e402dffbee4
|
7
|
+
data.tar.gz: d00ba390039160dee9ae0e4f5c7354f2f0300becf19c794aa10665688403361ea0625673a3253eb66b9c8ca3cb26ad7512f688f5587daca93bdb9ae990b63036
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
kamifusen (
|
4
|
+
kamifusen (1.1)
|
5
5
|
image_processing
|
6
6
|
rails
|
7
7
|
|
@@ -69,10 +69,11 @@ GEM
|
|
69
69
|
zeitwerk (~> 2.3)
|
70
70
|
ast (2.4.2)
|
71
71
|
builder (3.2.4)
|
72
|
-
|
72
|
+
byebug (11.1.3)
|
73
|
+
concurrent-ruby (1.1.9)
|
73
74
|
crass (1.0.6)
|
74
75
|
erubi (1.10.0)
|
75
|
-
ffi (1.15.
|
76
|
+
ffi (1.15.1)
|
76
77
|
globalid (0.4.2)
|
77
78
|
activesupport (>= 4.2.0)
|
78
79
|
i18n (1.8.10)
|
@@ -83,7 +84,7 @@ GEM
|
|
83
84
|
listen (3.5.1)
|
84
85
|
rb-fsevent (~> 0.10, >= 0.10.3)
|
85
86
|
rb-inotify (~> 0.9, >= 0.9.10)
|
86
|
-
loofah (2.
|
87
|
+
loofah (2.10.0)
|
87
88
|
crass (~> 1.0.2)
|
88
89
|
nokogiri (>= 1.5.9)
|
89
90
|
mail (2.7.1)
|
@@ -94,7 +95,7 @@ GEM
|
|
94
95
|
mini_mime (1.0.3)
|
95
96
|
minitest (5.14.4)
|
96
97
|
nio4r (2.5.7)
|
97
|
-
nokogiri (1.11.
|
98
|
+
nokogiri (1.11.7-x86_64-darwin)
|
98
99
|
racc (~> 1.4)
|
99
100
|
parallel (1.20.1)
|
100
101
|
parser (3.0.1.1)
|
@@ -136,16 +137,16 @@ GEM
|
|
136
137
|
ffi (~> 1.0)
|
137
138
|
regexp_parser (2.1.1)
|
138
139
|
rexml (3.2.5)
|
139
|
-
rubocop (1.
|
140
|
+
rubocop (1.16.1)
|
140
141
|
parallel (~> 1.10)
|
141
142
|
parser (>= 3.0.0.0)
|
142
143
|
rainbow (>= 2.2.2, < 4.0)
|
143
144
|
regexp_parser (>= 1.8, < 3.0)
|
144
145
|
rexml
|
145
|
-
rubocop-ast (>= 1.
|
146
|
+
rubocop-ast (>= 1.7.0, < 2.0)
|
146
147
|
ruby-progressbar (~> 1.7)
|
147
148
|
unicode-display_width (>= 1.4.0, < 3.0)
|
148
|
-
rubocop-ast (1.
|
149
|
+
rubocop-ast (1.7.0)
|
149
150
|
parser (>= 3.0.1.1)
|
150
151
|
ruby-progressbar (1.11.0)
|
151
152
|
ruby-vips (2.1.2)
|
@@ -171,6 +172,7 @@ PLATFORMS
|
|
171
172
|
x86_64-darwin-20
|
172
173
|
|
173
174
|
DEPENDENCIES
|
175
|
+
byebug
|
174
176
|
kamifusen!
|
175
177
|
listen
|
176
178
|
rake (~> 13.0)
|
data/README.md
CHANGED
@@ -2,6 +2,34 @@
|
|
2
2
|
|
3
3
|
![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)
|
4
4
|
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'kamifusen'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle install
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install kamifusen
|
20
|
+
|
21
|
+
In the views, use (where object is an active record model, and image is an active storage attachment):
|
22
|
+
|
23
|
+
```erb
|
24
|
+
<%= kamifusen_tag object.image, alt: 'A nice image' %>
|
25
|
+
```
|
26
|
+
|
27
|
+
If you want to disable webp, in config/initializers/kamifusen.rb:
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
Kamifusen.with_webp = false
|
31
|
+
```
|
32
|
+
|
5
33
|
## Usage
|
6
34
|
|
7
35
|
Simply use `kamifusen_tag` instead of `image_tag` in your rails views.## What's the problem?
|
@@ -76,11 +104,13 @@ Webp and AVIF are more efficient formats than jpg and png. They allow better com
|
|
76
104
|
https://sebousan.github.io/kamifusen/
|
77
105
|
|
78
106
|
The new helper is:
|
107
|
+
|
79
108
|
```erb
|
80
109
|
<%= kamifusen_tag object.image, alt: 'A nice image' %>
|
81
110
|
```
|
82
111
|
|
83
112
|
It generates a code like:
|
113
|
+
|
84
114
|
```html
|
85
115
|
<picture>
|
86
116
|
<source srcset="image-800w.avif, image-1600w.avif 2x" type="image/avif" media="(min-width: 800px)">
|
@@ -93,22 +123,6 @@ It generates a code like:
|
|
93
123
|
</picture>
|
94
124
|
```
|
95
125
|
|
96
|
-
## Installation
|
97
|
-
|
98
|
-
Add this line to your application's Gemfile:
|
99
|
-
|
100
|
-
```ruby
|
101
|
-
gem 'kamifusen'
|
102
|
-
```
|
103
|
-
|
104
|
-
And then execute:
|
105
|
-
|
106
|
-
$ bundle install
|
107
|
-
|
108
|
-
Or install it yourself as:
|
109
|
-
|
110
|
-
$ gem install kamifusen
|
111
|
-
|
112
126
|
## References
|
113
127
|
|
114
128
|
- https://developer.mozilla.org/fr/docs/Learn/HTML/Multimedia_and_embedding/Responsive_images
|
@@ -17,17 +17,32 @@ parameters += " class=\"#{ options[:class] }\"" if klass
|
|
17
17
|
sizes = [320, 576, 640, 768, 992, 1152, 1200, 1400, 1536, 1984, 2400]
|
18
18
|
quality = 80
|
19
19
|
# Computing
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
20
|
+
if width
|
21
|
+
width_retina = width * 2
|
22
|
+
sizes.reject! { |size| size > width_retina }
|
23
|
+
sizes << width_retina
|
24
|
+
sizes.uniq!
|
25
|
+
end
|
26
|
+
default_width = sizes.max
|
27
|
+
default_width = width_retina if width_retina && width_retina > default_width
|
28
|
+
if Kamifusen.with_webp
|
29
|
+
srcset_webp = sizes.map { |size|
|
30
|
+
"#{ url_for source.variant(resize: "#{size}>", format: :webp, quality: quality) } #{ size }w"
|
31
|
+
}.join(', ')
|
32
|
+
end
|
33
|
+
srcset_default = sizes.map { |size|
|
34
|
+
"#{ url_for source.variant(resize: "#{size}>", quality: quality) } #{ size }w"
|
35
|
+
}.join(', ')
|
36
|
+
default = url_for source.variant(resize: "#{default_width}>", quality: quality)
|
24
37
|
%>
|
25
38
|
<picture>
|
26
|
-
|
27
|
-
|
39
|
+
<% if Kamifusen.with_webp %>
|
40
|
+
<source srcset="<%= srcset_webp %>" type="image/webp">
|
41
|
+
<% end %>
|
42
|
+
<img src="<%= default %>" srcset="<%= srcset_default %>" type="<%= source.content_type %>"<%= raw parameters %>>
|
28
43
|
</picture>
|
29
44
|
<% else %>
|
30
45
|
<picture>
|
31
|
-
<img src="<%= url_for source %>"<%= raw parameters %>>
|
46
|
+
<img src="<%= url_for source %>" type="<%= source.content_type %>"<%= raw parameters %>>
|
32
47
|
</picture>
|
33
48
|
<% end %>
|
data/lib/kamifusen.rb
CHANGED
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.1'
|
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-06-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|