kamifusen 1.9 → 1.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a82b418d1a07d8b33f845d6ded2bdf3d1309943e41350f8e003bbdcbfe867f08
4
- data.tar.gz: 0d20f1c01167036520f1451f1d295d8c7a32d40e315b8ac6fdee707fb3236c43
3
+ metadata.gz: fc161cf43bce3f420864d28ab413979ed4c224c163ca872e78453bbd0d950c7f
4
+ data.tar.gz: 30796fb41b0280a5be83a29016cda1651514e80386014b402a0c6da627174b6d
5
5
  SHA512:
6
- metadata.gz: 999758e2fece72df932546f261091b4ffc1584b85668fc9102852d703d4c45526a66ae980ae918f64a6884b99267d2c8c2d3c4646b78a7475ccfd5c01ccf64e0
7
- data.tar.gz: be8d74901d1bb3f1859e01e6940c00aa2c9ee67aa086c34fb241de5e5adb510e14a93f39c040ba8dfa8708b1134d7637783775b3a7225cb400575d57643c316c
6
+ metadata.gz: 6f72675f224e8e87f64f4ada42f9c0cb4e86ed7c7002ad5316b2831048d52e8b1b9691ed8381a6484d12b9717f99cf49b36d05b1313198b2356e0cf307d6960d
7
+ data.tar.gz: 0fb2c26afde61d40cbb96f84c26416d0809cccec2a0fe37188925727a011f965fdcdfc045808293c7209198a597dc2a4641ec142d1bd19cc308db10c20404f7a
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- kamifusen (1.8)
4
+ kamifusen (1.10)
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.10)
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.1)
92
+ marcel (1.0.2)
93
93
  method_source (1.0.0)
94
94
  mini_magick (4.11.0)
95
- mini_mime (1.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.4)
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.5.2)
107
+ racc (1.6.0)
106
108
  rack (2.2.3)
107
109
  rack-test (1.1.0)
108
110
  rack (>= 1.0, < 3)
@@ -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.4.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.7
188
+ 2.2.30
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2021 Sébastien Moulène
3
+ Copyright (c) 2021 noesya
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -1,52 +1,47 @@
1
1
  <%
2
- # image_tag options
3
2
  options ||= {}
4
3
  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
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
- sizes = Kamifusen.sizes
15
- quality = Kamifusen.quality
11
+ variant_sizes = Kamifusen.sizes.dup
12
+ quality = Kamifusen.quality.dup
16
13
 
17
- if source&.metadata &&
18
- source.metadata['analyzed'] &&
19
- source.metadata.has_key?('width') &&
20
- source.metadata.has_key?('height')
14
+ sizes = options[:sizes] || {}
15
+
16
+ if source&.analyzed? && source.metadata.has_key?('width') && source.metadata.has_key?('height')
21
17
  image_width = source.metadata['width']
22
18
  image_height = source.metadata['height']
23
19
  image_ratio = 1.0 * image_width / image_height
24
20
  if width.nil? && height.nil?
25
- # Prendre width et height réelles de l'image
26
- width = [image_width, sizes.last].min
21
+ # Image real dimensions
22
+ width = [image_width, variant_sizes.last].min
27
23
  height = width * image_ratio
28
24
  elsif width.nil?
29
- # Calculer la height sur ratio
25
+ # Calculated width, preserving the aspect ratio
30
26
  width = height * image_ratio
31
27
  elsif height.nil?
32
- # Calcule la width sur ratio
28
+ # Calculated height, preserving the aspect ratio
33
29
  height = width / image_ratio
34
30
  else
35
- # Width et height sont explicites,
36
- # si le ratio demandé n'est pas celui de l'image,
37
- # Redéfinir la height
31
+ # Explicit dimensions. We redefine the height if aspect ratio is not preserved.
38
32
  width = [image_width, width].min
39
33
  height = width / image_ratio
40
34
  end
41
35
  width = width.round
42
36
  height = height.round
43
37
  end
38
+
44
39
  parameters = ""
45
40
  parameters += " loading=\"lazy\" decoding=\"async\"" if async
46
- parameters += " alt=\"#{ alt }\"" if alt
47
- parameters += " width=\"#{ width }\"" if width
48
- parameters += " height=\"#{ height }\"" if height
49
- parameters += " class=\"#{ klass }\"" if klass
41
+ parameters += " alt=\"#{alt}\"" if alt
42
+ parameters += " width=\"#{width}\"" if width
43
+ parameters += " height=\"#{height}\"" if height
44
+ parameters += " class=\"#{klass}\"" if klass
50
45
 
51
46
  def kamifusen_process(variant, active_storage_direct_url)
52
47
  if active_storage_direct_url
@@ -54,45 +49,50 @@ def kamifusen_process(variant, active_storage_direct_url)
54
49
  # Pour générer la processed url, il faut savoir où sont stockées les images
55
50
  # https://discuss.rubyonrails.org/t/define-host-so-absolute-urls-work-in-development-and-test/75085
56
51
  # 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
52
  url = variant.processed.url
59
53
  rescue
54
+ # Not compatible with DiskService, which returns a URI::InvalidURIError
60
55
  end
61
56
  end
62
- url = url_for(variant) if url.nil?
57
+ url ||= url_for(variant)
63
58
  url
64
59
  end
65
60
  %>
66
61
  <% if source.variable? %>
67
- <%#= "#{image_width} x #{image_height}, #{image_ratio} ratio => #{width} x #{height}<br>".html_safe %>
68
62
  <%
69
63
  # Computing
70
64
  if width
71
65
  width_retina = width * 2
72
- sizes.reject! { |size| size > width_retina }
73
- sizes << width_retina
74
- sizes.uniq!
66
+ variant_sizes.reject! { |size| size > width_retina }
67
+ variant_sizes << width_retina
68
+ variant_sizes.uniq!
75
69
  end
76
- default_width = sizes.max
70
+ default_width = variant_sizes.max
77
71
  default_width = width_retina if width_retina && width_retina > default_width
78
72
  if Kamifusen.with_webp
79
- srcset_webp = sizes.map { |size|
73
+ srcset_webp = variant_sizes.map { |size|
80
74
  variant = source.variant(resize: "#{size}>", format: :webp, quality: quality)
81
- "#{ kamifusen_process(variant, active_storage_direct_url) } #{ size }w"
75
+ "#{ kamifusen_process(variant, active_storage_direct_url) } #{size}w"
82
76
  }.join(', ')
83
77
  end
84
- srcset_default = sizes.map { |size|
78
+ srcset_default = variant_sizes.map { |size|
85
79
  variant = source.variant(resize: "#{size}>", quality: quality)
86
- "#{ kamifusen_process(variant, active_storage_direct_url) } #{ size }w"
80
+ "#{ kamifusen_process(variant, active_storage_direct_url) } #{size}w"
87
81
  }.join(', ')
88
82
  variant = source.variant(resize: "#{default_width}>", quality: quality)
89
83
  default = kamifusen_process(variant, active_storage_direct_url)
90
84
  %>
91
85
  <picture<%= " class=\"#{picture_class}\"".html_safe unless picture_class.blank? %>>
92
86
  <% if Kamifusen.with_webp %>
93
- <source srcset="<%= srcset_webp %>" type="image/webp">
87
+ <source srcset="<%= srcset_webp %>"
88
+ type="image/webp"
89
+ <%= " sizes=\"#{sizes.map { |key, value| [key, value].join(' ') }.join(', ')}\"".html_safe unless sizes.empty? %>>
94
90
  <% end %>
95
- <img src="<%= default %>" srcset="<%= srcset_default %>" type="<%= source.content_type %>"<%= raw parameters %>>
91
+ <img src="<%= default %>"
92
+ srcset="<%= srcset_default %>"
93
+ type="<%= source.content_type %>"
94
+ <%= " sizes=\"#{sizes.map { |key, value| [key, value].join(' ') }.join(', ')}\"".html_safe unless sizes.empty? %>
95
+ <%= raw parameters %>>
96
96
  </picture>
97
97
  <% else %>
98
98
  <picture>
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Kamifusen
4
- VERSION = "1.9"
4
+ VERSION = "1.10"
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: '1.9'
4
+ version: '1.10'
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-09-17 00:00:00.000000000 Z
12
+ date: 2021-11-09 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.