kamifusen 1.4 → 1.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +64 -64
- data/README.md +2 -0
- data/app/views/kamifusen/_view.html.erb +34 -9
- data/lib/kamifusen/version.rb +1 -1
- data/lib/kamifusen/view_helper.rb +0 -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: 05b8beb4ef9751b96229c3b9d267a9c6fc99f34d4bb869228495ce51779b06e0
|
4
|
+
data.tar.gz: 879e686e9b394b0b34aecabaa35469ffc063c4c815fbd6b92fabc226c2fc6894
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9cf81c743cf040ed1beb800be796fbbdc9883d75efbea3ed17951598fcd32d2dbe095235fbe7d2d568a320de1a7a476d0889eea737dd1b3d7531fe667790d804
|
7
|
+
data.tar.gz: 0ccb61359dbe83cca6b6ae7a6c1a27fae0e0d52616d448582de9314deb8a1964e4fd5c1b23d11d4f3908cef7c0476813ab47dc1b8e2892b4ac9dcda8cf6259a9
|
data/Gemfile.lock
CHANGED
@@ -1,67 +1,67 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
kamifusen (1.
|
4
|
+
kamifusen (1.8)
|
5
5
|
image_processing
|
6
6
|
rails
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
-
actioncable (6.1.4)
|
12
|
-
actionpack (= 6.1.4)
|
13
|
-
activesupport (= 6.1.4)
|
11
|
+
actioncable (6.1.4.1)
|
12
|
+
actionpack (= 6.1.4.1)
|
13
|
+
activesupport (= 6.1.4.1)
|
14
14
|
nio4r (~> 2.0)
|
15
15
|
websocket-driver (>= 0.6.1)
|
16
|
-
actionmailbox (6.1.4)
|
17
|
-
actionpack (= 6.1.4)
|
18
|
-
activejob (= 6.1.4)
|
19
|
-
activerecord (= 6.1.4)
|
20
|
-
activestorage (= 6.1.4)
|
21
|
-
activesupport (= 6.1.4)
|
16
|
+
actionmailbox (6.1.4.1)
|
17
|
+
actionpack (= 6.1.4.1)
|
18
|
+
activejob (= 6.1.4.1)
|
19
|
+
activerecord (= 6.1.4.1)
|
20
|
+
activestorage (= 6.1.4.1)
|
21
|
+
activesupport (= 6.1.4.1)
|
22
22
|
mail (>= 2.7.1)
|
23
|
-
actionmailer (6.1.4)
|
24
|
-
actionpack (= 6.1.4)
|
25
|
-
actionview (= 6.1.4)
|
26
|
-
activejob (= 6.1.4)
|
27
|
-
activesupport (= 6.1.4)
|
23
|
+
actionmailer (6.1.4.1)
|
24
|
+
actionpack (= 6.1.4.1)
|
25
|
+
actionview (= 6.1.4.1)
|
26
|
+
activejob (= 6.1.4.1)
|
27
|
+
activesupport (= 6.1.4.1)
|
28
28
|
mail (~> 2.5, >= 2.5.4)
|
29
29
|
rails-dom-testing (~> 2.0)
|
30
|
-
actionpack (6.1.4)
|
31
|
-
actionview (= 6.1.4)
|
32
|
-
activesupport (= 6.1.4)
|
30
|
+
actionpack (6.1.4.1)
|
31
|
+
actionview (= 6.1.4.1)
|
32
|
+
activesupport (= 6.1.4.1)
|
33
33
|
rack (~> 2.0, >= 2.0.9)
|
34
34
|
rack-test (>= 0.6.3)
|
35
35
|
rails-dom-testing (~> 2.0)
|
36
36
|
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
37
|
-
actiontext (6.1.4)
|
38
|
-
actionpack (= 6.1.4)
|
39
|
-
activerecord (= 6.1.4)
|
40
|
-
activestorage (= 6.1.4)
|
41
|
-
activesupport (= 6.1.4)
|
37
|
+
actiontext (6.1.4.1)
|
38
|
+
actionpack (= 6.1.4.1)
|
39
|
+
activerecord (= 6.1.4.1)
|
40
|
+
activestorage (= 6.1.4.1)
|
41
|
+
activesupport (= 6.1.4.1)
|
42
42
|
nokogiri (>= 1.8.5)
|
43
|
-
actionview (6.1.4)
|
44
|
-
activesupport (= 6.1.4)
|
43
|
+
actionview (6.1.4.1)
|
44
|
+
activesupport (= 6.1.4.1)
|
45
45
|
builder (~> 3.1)
|
46
46
|
erubi (~> 1.4)
|
47
47
|
rails-dom-testing (~> 2.0)
|
48
48
|
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
49
|
-
activejob (6.1.4)
|
50
|
-
activesupport (= 6.1.4)
|
49
|
+
activejob (6.1.4.1)
|
50
|
+
activesupport (= 6.1.4.1)
|
51
51
|
globalid (>= 0.3.6)
|
52
|
-
activemodel (6.1.4)
|
53
|
-
activesupport (= 6.1.4)
|
54
|
-
activerecord (6.1.4)
|
55
|
-
activemodel (= 6.1.4)
|
56
|
-
activesupport (= 6.1.4)
|
57
|
-
activestorage (6.1.4)
|
58
|
-
actionpack (= 6.1.4)
|
59
|
-
activejob (= 6.1.4)
|
60
|
-
activerecord (= 6.1.4)
|
61
|
-
activesupport (= 6.1.4)
|
52
|
+
activemodel (6.1.4.1)
|
53
|
+
activesupport (= 6.1.4.1)
|
54
|
+
activerecord (6.1.4.1)
|
55
|
+
activemodel (= 6.1.4.1)
|
56
|
+
activesupport (= 6.1.4.1)
|
57
|
+
activestorage (6.1.4.1)
|
58
|
+
actionpack (= 6.1.4.1)
|
59
|
+
activejob (= 6.1.4.1)
|
60
|
+
activerecord (= 6.1.4.1)
|
61
|
+
activesupport (= 6.1.4.1)
|
62
62
|
marcel (~> 1.0.0)
|
63
63
|
mini_mime (>= 1.1.0)
|
64
|
-
activesupport (6.1.4)
|
64
|
+
activesupport (6.1.4.1)
|
65
65
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
66
66
|
i18n (>= 1.6, < 2)
|
67
67
|
minitest (>= 5.1)
|
@@ -74,8 +74,8 @@ GEM
|
|
74
74
|
crass (1.0.6)
|
75
75
|
erubi (1.10.0)
|
76
76
|
ffi (1.15.3)
|
77
|
-
globalid (0.
|
78
|
-
activesupport (>=
|
77
|
+
globalid (0.5.2)
|
78
|
+
activesupport (>= 5.0)
|
79
79
|
i18n (1.8.10)
|
80
80
|
concurrent-ruby (~> 1.0)
|
81
81
|
image_processing (1.12.1)
|
@@ -84,7 +84,7 @@ GEM
|
|
84
84
|
listen (3.5.1)
|
85
85
|
rb-fsevent (~> 0.10, >= 0.10.3)
|
86
86
|
rb-inotify (~> 0.9, >= 0.9.10)
|
87
|
-
loofah (2.
|
87
|
+
loofah (2.12.0)
|
88
88
|
crass (~> 1.0.2)
|
89
89
|
nokogiri (>= 1.5.9)
|
90
90
|
mail (2.7.1)
|
@@ -92,12 +92,12 @@ GEM
|
|
92
92
|
marcel (1.0.1)
|
93
93
|
method_source (1.0.0)
|
94
94
|
mini_magick (4.11.0)
|
95
|
-
mini_mime (1.1.
|
96
|
-
mini_portile2 (2.
|
95
|
+
mini_mime (1.1.1)
|
96
|
+
mini_portile2 (2.6.1)
|
97
97
|
minitest (5.14.4)
|
98
|
-
nio4r (2.5.
|
99
|
-
nokogiri (1.
|
100
|
-
mini_portile2 (~> 2.
|
98
|
+
nio4r (2.5.8)
|
99
|
+
nokogiri (1.12.4)
|
100
|
+
mini_portile2 (~> 2.6.1)
|
101
101
|
racc (~> 1.4)
|
102
102
|
parallel (1.20.1)
|
103
103
|
parser (3.0.1.1)
|
@@ -106,29 +106,29 @@ GEM
|
|
106
106
|
rack (2.2.3)
|
107
107
|
rack-test (1.1.0)
|
108
108
|
rack (>= 1.0, < 3)
|
109
|
-
rails (6.1.4)
|
110
|
-
actioncable (= 6.1.4)
|
111
|
-
actionmailbox (= 6.1.4)
|
112
|
-
actionmailer (= 6.1.4)
|
113
|
-
actionpack (= 6.1.4)
|
114
|
-
actiontext (= 6.1.4)
|
115
|
-
actionview (= 6.1.4)
|
116
|
-
activejob (= 6.1.4)
|
117
|
-
activemodel (= 6.1.4)
|
118
|
-
activerecord (= 6.1.4)
|
119
|
-
activestorage (= 6.1.4)
|
120
|
-
activesupport (= 6.1.4)
|
109
|
+
rails (6.1.4.1)
|
110
|
+
actioncable (= 6.1.4.1)
|
111
|
+
actionmailbox (= 6.1.4.1)
|
112
|
+
actionmailer (= 6.1.4.1)
|
113
|
+
actionpack (= 6.1.4.1)
|
114
|
+
actiontext (= 6.1.4.1)
|
115
|
+
actionview (= 6.1.4.1)
|
116
|
+
activejob (= 6.1.4.1)
|
117
|
+
activemodel (= 6.1.4.1)
|
118
|
+
activerecord (= 6.1.4.1)
|
119
|
+
activestorage (= 6.1.4.1)
|
120
|
+
activesupport (= 6.1.4.1)
|
121
121
|
bundler (>= 1.15.0)
|
122
|
-
railties (= 6.1.4)
|
122
|
+
railties (= 6.1.4.1)
|
123
123
|
sprockets-rails (>= 2.0.0)
|
124
124
|
rails-dom-testing (2.0.3)
|
125
125
|
activesupport (>= 4.2.0)
|
126
126
|
nokogiri (>= 1.6)
|
127
|
-
rails-html-sanitizer (1.
|
127
|
+
rails-html-sanitizer (1.4.2)
|
128
128
|
loofah (~> 2.3)
|
129
|
-
railties (6.1.4)
|
130
|
-
actionpack (= 6.1.4)
|
131
|
-
activesupport (= 6.1.4)
|
129
|
+
railties (6.1.4.1)
|
130
|
+
actionpack (= 6.1.4.1)
|
131
|
+
activesupport (= 6.1.4.1)
|
132
132
|
method_source
|
133
133
|
rake (>= 0.13)
|
134
134
|
thor (~> 1.0)
|
@@ -151,7 +151,7 @@ GEM
|
|
151
151
|
rubocop-ast (1.7.0)
|
152
152
|
parser (>= 3.0.1.1)
|
153
153
|
ruby-progressbar (1.11.0)
|
154
|
-
ruby-vips (2.1.
|
154
|
+
ruby-vips (2.1.3)
|
155
155
|
ffi (~> 1.12)
|
156
156
|
sprockets (4.0.2)
|
157
157
|
concurrent-ruby (~> 1.0)
|
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# Kamifūsen
|
2
2
|
|
3
|
+
Images in Ruby on Rails, as lightweight as possible!
|
4
|
+
|
3
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)
|
4
6
|
|
5
7
|
## Installation
|
@@ -2,10 +2,19 @@
|
|
2
2
|
# image_tag options
|
3
3
|
options ||= {}
|
4
4
|
alt = options[:alt]
|
5
|
+
async = options.has_key?(:async) ? options[:async]
|
6
|
+
: true
|
7
|
+
active_storage_direct_url = options.has_key?(:active_storage_direct_url) ? options[:active_storage_direct_url]
|
8
|
+
: false
|
5
9
|
klass = options[:class]
|
6
10
|
picture_class = options[:picture_class]
|
7
11
|
width = options[:width]
|
8
12
|
height = options[:height]
|
13
|
+
|
14
|
+
# kamifusen settings
|
15
|
+
sizes = [360, 375, 414, 576, 640, 750, 768, 828, 992, 1152, 1200, 1366, 1400, 1536, 1920, 1984, 2400]
|
16
|
+
quality = 80
|
17
|
+
|
9
18
|
if source&.metadata &&
|
10
19
|
source.metadata['analyzed'] &&
|
11
20
|
source.metadata.has_key?('width') &&
|
@@ -15,8 +24,8 @@ if source&.metadata &&
|
|
15
24
|
image_ratio = 1.0 * image_width / image_height
|
16
25
|
if width.nil? && height.nil?
|
17
26
|
# Prendre width et height réelles de l'image
|
18
|
-
width = image_width
|
19
|
-
height =
|
27
|
+
width = [image_width, sizes.last].min
|
28
|
+
height = width * image_ratio
|
20
29
|
elsif width.nil?
|
21
30
|
# Calculer la height sur ratio
|
22
31
|
width = height * image_ratio
|
@@ -33,18 +42,31 @@ if source&.metadata &&
|
|
33
42
|
width = width.round
|
34
43
|
height = height.round
|
35
44
|
end
|
36
|
-
parameters = "
|
45
|
+
parameters = ""
|
46
|
+
parameters += " loading=\"lazy\" decoding=\"async\"" if async
|
37
47
|
parameters += " alt=\"#{ alt }\"" if alt
|
38
48
|
parameters += " width=\"#{ width }\"" if width
|
39
49
|
parameters += " height=\"#{ height }\"" if height
|
40
50
|
parameters += " class=\"#{ klass }\"" if klass
|
51
|
+
|
52
|
+
def kamifusen_process(variant, active_storage_direct_url)
|
53
|
+
if active_storage_direct_url
|
54
|
+
begin
|
55
|
+
# Pour générer la processed url, il faut savoir où sont stockées les images
|
56
|
+
# https://discuss.rubyonrails.org/t/define-host-so-absolute-urls-work-in-development-and-test/75085
|
57
|
+
# https://stackoverflow.com/questions/60425407/uriinvalidurierror-bad-uriis-not-uri-nil-active-storage-service-url
|
58
|
+
# Not compatible with Disk storage, will return nil
|
59
|
+
url = variant.processed.url
|
60
|
+
rescue
|
61
|
+
end
|
62
|
+
end
|
63
|
+
url = url_for(variant) if url.nil?
|
64
|
+
url
|
65
|
+
end
|
41
66
|
%>
|
42
67
|
<% if source.variable? %>
|
43
68
|
<%#= "#{image_width} x #{image_height}, #{image_ratio} ratio => #{width} x #{height}<br>".html_safe %>
|
44
69
|
<%
|
45
|
-
# kamifusen settings
|
46
|
-
sizes = [320, 576, 640, 768, 992, 1152, 1200, 1400, 1536, 1984, 2400]
|
47
|
-
quality = 80
|
48
70
|
# Computing
|
49
71
|
if width
|
50
72
|
width_retina = width * 2
|
@@ -56,13 +78,16 @@ parameters += " class=\"#{ klass }\"" if klass
|
|
56
78
|
default_width = width_retina if width_retina && width_retina > default_width
|
57
79
|
if Kamifusen.with_webp
|
58
80
|
srcset_webp = sizes.map { |size|
|
59
|
-
|
81
|
+
variant = source.variant(resize: "#{size}>", format: :webp, quality: quality)
|
82
|
+
"#{ kamifusen_process(variant, active_storage_direct_url) } #{ size }w"
|
60
83
|
}.join(', ')
|
61
84
|
end
|
62
85
|
srcset_default = sizes.map { |size|
|
63
|
-
|
86
|
+
variant = source.variant(resize: "#{size}>", quality: quality)
|
87
|
+
"#{ kamifusen_process(variant, active_storage_direct_url) } #{ size }w"
|
64
88
|
}.join(', ')
|
65
|
-
|
89
|
+
variant = source.variant(resize: "#{default_width}>", quality: quality)
|
90
|
+
default = kamifusen_process(variant, active_storage_direct_url)
|
66
91
|
%>
|
67
92
|
<picture<%= " class=\"#{picture_class}\"".html_safe unless picture_class.blank? %>>
|
68
93
|
<% if Kamifusen.with_webp %>
|
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.8'
|
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-09-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|