kamifusen 0.9.5 → 1.2

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: d8dbbcc4c66d0ec53374d889f4ef4a52179bbaf62e1ea7403b565e4069dbaa37
4
- data.tar.gz: 1c2686b087fa169f0683589f5af410376dc56795f73d42c18fca08e701c09d0d
3
+ metadata.gz: 851589d8842495c0ec86ca05f50f1d31dc8b2bfd1529f5489ace33d2389c7685
4
+ data.tar.gz: bdacde7a5ece34a1e28bf81afe73e2819c810b2cef85644ab8f86ffd1537a030
5
5
  SHA512:
6
- metadata.gz: 19c174b39b9a4a03dac5991ee6f75c0db7c3935ee945551a4804d3e66348017f44685177caf8af7e06a2794b5f8654b6c2c5d8f7a50089d732b368904849ddc6
7
- data.tar.gz: 5fdba79b302e2f80c4f04f12ba49d610deef2ab4526128109b516f01730fed226369e51543d94ca24c6bd31404ec2e70246da22c37c8c35fdb03fb5ee44cfe2e
6
+ metadata.gz: 48ee33fa22558e94422fa8238689a3264e5e2f3fbe97b955b0d06b9b0b5bf84c0afa9cf2703b853181fce9c4e7bba63a618def3f7d83bc3422c2f847e3e55a0a
7
+ data.tar.gz: ce384764e41270902b94a25bc7de4b0a961fb198b99b099e76b3c148fad146043d82903b08620aa360cc5224cc68a6f3b20bb58aee4257be07e5b41a366e1671
data/Gemfile CHANGED
@@ -8,3 +8,5 @@ gemspec
8
8
  gem "rake", "~> 13.0"
9
9
 
10
10
  gem "rubocop", "~> 1.7"
11
+
12
+ gem "byebug"
data/Gemfile.lock CHANGED
@@ -1,67 +1,67 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- kamifusen (0.9.5)
4
+ kamifusen (1.2)
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.3.2)
12
- actionpack (= 6.1.3.2)
13
- activesupport (= 6.1.3.2)
11
+ actioncable (6.1.4)
12
+ actionpack (= 6.1.4)
13
+ activesupport (= 6.1.4)
14
14
  nio4r (~> 2.0)
15
15
  websocket-driver (>= 0.6.1)
16
- actionmailbox (6.1.3.2)
17
- actionpack (= 6.1.3.2)
18
- activejob (= 6.1.3.2)
19
- activerecord (= 6.1.3.2)
20
- activestorage (= 6.1.3.2)
21
- activesupport (= 6.1.3.2)
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)
22
22
  mail (>= 2.7.1)
23
- actionmailer (6.1.3.2)
24
- actionpack (= 6.1.3.2)
25
- actionview (= 6.1.3.2)
26
- activejob (= 6.1.3.2)
27
- activesupport (= 6.1.3.2)
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)
28
28
  mail (~> 2.5, >= 2.5.4)
29
29
  rails-dom-testing (~> 2.0)
30
- actionpack (6.1.3.2)
31
- actionview (= 6.1.3.2)
32
- activesupport (= 6.1.3.2)
30
+ actionpack (6.1.4)
31
+ actionview (= 6.1.4)
32
+ activesupport (= 6.1.4)
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.3.2)
38
- actionpack (= 6.1.3.2)
39
- activerecord (= 6.1.3.2)
40
- activestorage (= 6.1.3.2)
41
- activesupport (= 6.1.3.2)
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)
42
42
  nokogiri (>= 1.8.5)
43
- actionview (6.1.3.2)
44
- activesupport (= 6.1.3.2)
43
+ actionview (6.1.4)
44
+ activesupport (= 6.1.4)
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.3.2)
50
- activesupport (= 6.1.3.2)
49
+ activejob (6.1.4)
50
+ activesupport (= 6.1.4)
51
51
  globalid (>= 0.3.6)
52
- activemodel (6.1.3.2)
53
- activesupport (= 6.1.3.2)
54
- activerecord (6.1.3.2)
55
- activemodel (= 6.1.3.2)
56
- activesupport (= 6.1.3.2)
57
- activestorage (6.1.3.2)
58
- actionpack (= 6.1.3.2)
59
- activejob (= 6.1.3.2)
60
- activerecord (= 6.1.3.2)
61
- activesupport (= 6.1.3.2)
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)
62
62
  marcel (~> 1.0.0)
63
- mini_mime (~> 1.0.2)
64
- activesupport (6.1.3.2)
63
+ mini_mime (>= 1.1.0)
64
+ activesupport (6.1.4)
65
65
  concurrent-ruby (~> 1.0, >= 1.0.2)
66
66
  i18n (>= 1.6, < 2)
67
67
  minitest (>= 5.1)
@@ -69,10 +69,11 @@ GEM
69
69
  zeitwerk (~> 2.3)
70
70
  ast (2.4.2)
71
71
  builder (3.2.4)
72
- concurrent-ruby (1.1.8)
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.0)
76
+ ffi (1.15.3)
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.9.1)
87
+ loofah (2.10.0)
87
88
  crass (~> 1.0.2)
88
89
  nokogiri (>= 1.5.9)
89
90
  mail (2.7.1)
@@ -91,10 +92,12 @@ GEM
91
92
  marcel (1.0.1)
92
93
  method_source (1.0.0)
93
94
  mini_magick (4.11.0)
94
- mini_mime (1.0.3)
95
+ mini_mime (1.1.0)
96
+ mini_portile2 (2.5.3)
95
97
  minitest (5.14.4)
96
98
  nio4r (2.5.7)
97
- nokogiri (1.11.6-x86_64-darwin)
99
+ nokogiri (1.11.7)
100
+ mini_portile2 (~> 2.5.0)
98
101
  racc (~> 1.4)
99
102
  parallel (1.20.1)
100
103
  parser (3.0.1.1)
@@ -103,31 +106,31 @@ GEM
103
106
  rack (2.2.3)
104
107
  rack-test (1.1.0)
105
108
  rack (>= 1.0, < 3)
106
- rails (6.1.3.2)
107
- actioncable (= 6.1.3.2)
108
- actionmailbox (= 6.1.3.2)
109
- actionmailer (= 6.1.3.2)
110
- actionpack (= 6.1.3.2)
111
- actiontext (= 6.1.3.2)
112
- actionview (= 6.1.3.2)
113
- activejob (= 6.1.3.2)
114
- activemodel (= 6.1.3.2)
115
- activerecord (= 6.1.3.2)
116
- activestorage (= 6.1.3.2)
117
- activesupport (= 6.1.3.2)
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)
118
121
  bundler (>= 1.15.0)
119
- railties (= 6.1.3.2)
122
+ railties (= 6.1.4)
120
123
  sprockets-rails (>= 2.0.0)
121
124
  rails-dom-testing (2.0.3)
122
125
  activesupport (>= 4.2.0)
123
126
  nokogiri (>= 1.6)
124
127
  rails-html-sanitizer (1.3.0)
125
128
  loofah (~> 2.3)
126
- railties (6.1.3.2)
127
- actionpack (= 6.1.3.2)
128
- activesupport (= 6.1.3.2)
129
+ railties (6.1.4)
130
+ actionpack (= 6.1.4)
131
+ activesupport (= 6.1.4)
129
132
  method_source
130
- rake (>= 0.8.7)
133
+ rake (>= 0.13)
131
134
  thor (~> 1.0)
132
135
  rainbow (3.0.0)
133
136
  rake (13.0.3)
@@ -136,16 +139,16 @@ GEM
136
139
  ffi (~> 1.0)
137
140
  regexp_parser (2.1.1)
138
141
  rexml (3.2.5)
139
- rubocop (1.15.0)
142
+ rubocop (1.18.2)
140
143
  parallel (~> 1.10)
141
144
  parser (>= 3.0.0.0)
142
145
  rainbow (>= 2.2.2, < 4.0)
143
146
  regexp_parser (>= 1.8, < 3.0)
144
147
  rexml
145
- rubocop-ast (>= 1.5.0, < 2.0)
148
+ rubocop-ast (>= 1.7.0, < 2.0)
146
149
  ruby-progressbar (~> 1.7)
147
150
  unicode-display_width (>= 1.4.0, < 3.0)
148
- rubocop-ast (1.5.0)
151
+ rubocop-ast (1.7.0)
149
152
  parser (>= 3.0.1.1)
150
153
  ruby-progressbar (1.11.0)
151
154
  ruby-vips (2.1.2)
@@ -162,15 +165,17 @@ GEM
162
165
  tzinfo (2.0.4)
163
166
  concurrent-ruby (~> 1.0)
164
167
  unicode-display_width (2.0.0)
165
- websocket-driver (0.7.4)
168
+ websocket-driver (0.7.5)
166
169
  websocket-extensions (>= 0.1.0)
167
170
  websocket-extensions (0.1.5)
168
171
  zeitwerk (2.4.2)
169
172
 
170
173
  PLATFORMS
174
+ ruby
171
175
  x86_64-darwin-20
172
176
 
173
177
  DEPENDENCIES
178
+ byebug
174
179
  kamifusen!
175
180
  listen
176
181
  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
@@ -5,6 +5,7 @@ alt = options[:alt]
5
5
  width = options[:width]
6
6
  height = options[:height]
7
7
  klass = options[:class]
8
+ picture_class = options[:picture_class]
8
9
  parameters = " loading=\"lazy\" decoding=\"async\""
9
10
  parameters += " alt=\"#{ options[:alt] }\"" if alt
10
11
  parameters += " width=\"#{ options[:width] }\"" if width
@@ -17,17 +18,32 @@ parameters += " class=\"#{ options[:class] }\"" if klass
17
18
  sizes = [320, 576, 640, 768, 992, 1152, 1200, 1400, 1536, 1984, 2400]
18
19
  quality = 80
19
20
  # Computing
20
- sizes.reject! { |size| size > width * 2 } if width
21
- srcset_webp = sizes.map { |size| "#{ url_for source.variant(resize: "#{size}>", format: :webp, quality: quality) } #{ size }w" }.join(', ')
22
- srcset_default = sizes.map { |size| "#{ url_for source.variant(resize: "#{size}>", quality: quality) } #{ size }w" }.join(', ')
23
- default = url_for source.variant(resize: "#{sizes.max}>", quality: quality)
21
+ if width
22
+ width_retina = width * 2
23
+ sizes.reject! { |size| size > width_retina }
24
+ sizes << width_retina
25
+ sizes.uniq!
26
+ end
27
+ default_width = sizes.max
28
+ default_width = width_retina if width_retina && width_retina > default_width
29
+ if Kamifusen.with_webp
30
+ srcset_webp = sizes.map { |size|
31
+ "#{ url_for source.variant(resize: "#{size}>", format: :webp, quality: quality) } #{ size }w"
32
+ }.join(', ')
33
+ end
34
+ srcset_default = sizes.map { |size|
35
+ "#{ url_for source.variant(resize: "#{size}>", quality: quality) } #{ size }w"
36
+ }.join(', ')
37
+ default = url_for source.variant(resize: "#{default_width}>", quality: quality)
24
38
  %>
25
- <picture>
26
- <source srcset="<%= srcset_webp %>">
27
- <img src="<%= default %>" srcset="<%= srcset_default %>"<%= raw parameters %>>
39
+ <picture<%= " class=\"#{picture_class}\"" unless picture_class.blank? %>>
40
+ <% if Kamifusen.with_webp %>
41
+ <source srcset="<%= srcset_webp %>" type="image/webp">
42
+ <% end %>
43
+ <img src="<%= default %>" srcset="<%= srcset_default %>" type="<%= source.content_type %>"<%= raw parameters %>>
28
44
  </picture>
29
45
  <% else %>
30
46
  <picture>
31
- <img src="<%= url_for source %>"<%= raw parameters %>>
47
+ <img src="<%= url_for source %>" type="<%= source.content_type %>"<%= raw parameters %>>
32
48
  </picture>
33
49
  <% end %>
data/lib/kamifusen.rb CHANGED
@@ -5,8 +5,13 @@ require "kamifusen/railtie"
5
5
  require "kamifusen/view_helper"
6
6
 
7
7
  module Kamifusen
8
+
9
+ mattr_accessor :with_webp
10
+ @@with_webp = true
11
+
8
12
  class Engine < ::Rails::Engine
9
13
  end
14
+
10
15
  class Error < StandardError
11
16
  end
12
17
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Kamifusen
4
- VERSION = "0.9.5"
4
+ VERSION = "1.2"
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: 0.9.5
4
+ version: '1.2'
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-05-31 00:00:00.000000000 Z
12
+ date: 2021-07-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -116,7 +116,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
116
116
  - !ruby/object:Gem::Version
117
117
  version: '0'
118
118
  requirements: []
119
- rubygems_version: 3.1.4
119
+ rubygems_version: 3.1.6
120
120
  signing_key:
121
121
  specification_version: 4
122
122
  summary: Images, light as balloons