kamifusen 1.8 → 1.10.2

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: 05b8beb4ef9751b96229c3b9d267a9c6fc99f34d4bb869228495ce51779b06e0
4
- data.tar.gz: 879e686e9b394b0b34aecabaa35469ffc063c4c815fbd6b92fabc226c2fc6894
3
+ metadata.gz: 2fdd71ccadb407398ff0e93515e68ab5baf952c6126b21253f7eed7ed7a23ffe
4
+ data.tar.gz: bcf6bb686e133972a594c28992d2e4c44b8f481da07ebc48667871f1909f41a3
5
5
  SHA512:
6
- metadata.gz: 9cf81c743cf040ed1beb800be796fbbdc9883d75efbea3ed17951598fcd32d2dbe095235fbe7d2d568a320de1a7a476d0889eea737dd1b3d7531fe667790d804
7
- data.tar.gz: 0ccb61359dbe83cca6b6ae7a6c1a27fae0e0d52616d448582de9314deb8a1964e4fd5c1b23d11d4f3908cef7c0476813ab47dc1b8e2892b4ac9dcda8cf6259a9
6
+ metadata.gz: ea108d4ec53a1083f9c9f25ebcefeef09653f5929049cb6e7e7acb927e7e19fd83575967b2cd56531301e48758f287f748ffbc8dab9414251fd28b672c8009eb
7
+ data.tar.gz: 963dd8eef230ae2fe292a65ad3e74b01a2e1b47ebd264ca6dfbc3e6acda7a753af1acfa8faaf3e87c9dd90b426cc57d67589476dba2413fd12ce3fcf06831fa7
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.2)
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)
@@ -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.2.2)
160
- actionpack (>= 4.0)
161
- activesupport (>= 4.0)
161
+ sprockets-rails (3.3.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.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
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?
@@ -1,53 +1,48 @@
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
- # kamifusen settings
15
- sizes = [360, 375, 414, 576, 640, 750, 768, 828, 992, 1152, 1200, 1366, 1400, 1536, 1920, 1984, 2400]
16
- quality = 80
11
+ variant_sizes = Kamifusen.sizes.dup
12
+ quality = Kamifusen.quality.dup
17
13
 
18
- if source&.metadata &&
19
- source.metadata['analyzed'] &&
20
- source.metadata.has_key?('width') &&
21
- source.metadata.has_key?('height')
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')
22
18
  image_width = source.metadata['width']
23
19
  image_height = source.metadata['height']
24
20
  image_ratio = 1.0 * image_width / image_height
25
21
  if width.nil? && height.nil?
26
- # Prendre width et height réelles de l'image
27
- width = [image_width, sizes.last].min
22
+ # Image real dimensions
23
+ width = [image_width, variant_sizes.last].min
28
24
  height = width * image_ratio
29
25
  elsif width.nil?
30
- # Calculer la height sur ratio
26
+ # Calculated width, preserving the aspect ratio
31
27
  width = height * image_ratio
32
28
  elsif height.nil?
33
- # Calcule la width sur ratio
29
+ # Calculated height, preserving the aspect ratio
34
30
  height = width / image_ratio
35
31
  else
36
- # Width et height sont explicites,
37
- # si le ratio demandé n'est pas celui de l'image,
38
- # Redéfinir la height
32
+ # Explicit dimensions. We redefine the height if aspect ratio is not preserved.
39
33
  width = [image_width, width].min
40
34
  height = width / image_ratio
41
35
  end
42
36
  width = width.round
43
37
  height = height.round
44
38
  end
39
+
45
40
  parameters = ""
46
41
  parameters += " loading=\"lazy\" decoding=\"async\"" if async
47
- parameters += " alt=\"#{ alt }\"" if alt
48
- parameters += " width=\"#{ width }\"" if width
49
- parameters += " height=\"#{ height }\"" if height
50
- parameters += " class=\"#{ klass }\"" if klass
42
+ parameters += " alt=\"#{alt}\"" if alt
43
+ parameters += " width=\"#{width}\"" if width
44
+ parameters += " height=\"#{height}\"" if height
45
+ parameters += " class=\"#{klass}\"" if klass
51
46
 
52
47
  def kamifusen_process(variant, active_storage_direct_url)
53
48
  if active_storage_direct_url
@@ -55,45 +50,49 @@ def kamifusen_process(variant, active_storage_direct_url)
55
50
  # Pour générer la processed url, il faut savoir où sont stockées les images
56
51
  # https://discuss.rubyonrails.org/t/define-host-so-absolute-urls-work-in-development-and-test/75085
57
52
  # 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
53
  url = variant.processed.url
60
54
  rescue
55
+ # Not compatible with DiskService, which returns a URI::InvalidURIError
61
56
  end
62
57
  end
63
- url = url_for(variant) if url.nil?
58
+ url ||= url_for(variant)
64
59
  url
65
60
  end
66
61
  %>
67
62
  <% if source.variable? %>
68
- <%#= "#{image_width} x #{image_height}, #{image_ratio} ratio => #{width} x #{height}<br>".html_safe %>
69
63
  <%
70
64
  # Computing
71
65
  if width
72
66
  width_retina = width * 2
73
- sizes.reject! { |size| size > width_retina }
74
- sizes << width_retina
75
- sizes.uniq!
67
+ variant_sizes.reject! { |size| size > width_retina }
68
+ variant_sizes << width_retina
69
+ variant_sizes.uniq!
76
70
  end
77
- default_width = sizes.max
71
+ default_width = variant_sizes.max
78
72
  default_width = width_retina if width_retina && width_retina > default_width
79
73
  if Kamifusen.with_webp
80
- srcset_webp = sizes.map { |size|
74
+ srcset_webp = variant_sizes.map { |size|
81
75
  variant = source.variant(resize: "#{size}>", format: :webp, quality: quality)
82
- "#{ kamifusen_process(variant, active_storage_direct_url) } #{ size }w"
76
+ "#{ kamifusen_process(variant, active_storage_direct_url) } #{size}w"
83
77
  }.join(', ')
84
78
  end
85
- srcset_default = sizes.map { |size|
79
+ srcset_default = variant_sizes.map { |size|
86
80
  variant = source.variant(resize: "#{size}>", quality: quality)
87
- "#{ kamifusen_process(variant, active_storage_direct_url) } #{ size }w"
81
+ "#{ kamifusen_process(variant, active_storage_direct_url) } #{size}w"
88
82
  }.join(', ')
89
83
  variant = source.variant(resize: "#{default_width}>", quality: quality)
90
84
  default = kamifusen_process(variant, active_storage_direct_url)
91
85
  %>
92
86
  <picture<%= " class=\"#{picture_class}\"".html_safe unless picture_class.blank? %>>
93
87
  <% if Kamifusen.with_webp %>
94
- <source srcset="<%= srcset_webp %>" type="image/webp">
88
+ <source srcset="<%= srcset_webp %>"
89
+ <%= " sizes=\"#{sizes_value}\"".html_safe unless sizes.empty? %>
90
+ type="image/webp">
95
91
  <% end %>
96
- <img src="<%= default %>" srcset="<%= srcset_default %>" type="<%= source.content_type %>"<%= raw parameters %>>
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 %>>
97
96
  </picture>
98
97
  <% else %>
99
98
  <picture>
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Kamifusen
4
- VERSION = "1.8"
4
+ VERSION = "1.10.2"
5
5
  end
data/lib/kamifusen.rb CHANGED
@@ -9,6 +9,36 @@ module Kamifusen
9
9
  mattr_accessor :with_webp
10
10
  @@with_webp = true
11
11
 
12
+ mattr_accessor :sizes
13
+ @@sizes = [
14
+ # 360, # Old android
15
+ 375, # Old iPhone
16
+ # 414, # ?
17
+ 576, # Tablets desktop
18
+ 640, # iPhone SE, some tablets
19
+ 750, # iPhone 6/7/8, 375@2x
20
+ 768, # Old iPads, Old desktops
21
+ # 828, # ?
22
+ # 992, # Breakpoint bootstrap
23
+ 1080, # iPhone 6/7/8 plus, 414@2.608 (sorry)
24
+ # 1125, # iPhone 10, 375@3x
25
+ 1152,
26
+ # 1172, # iPhone 12, 390@3x
27
+ 1200, # Desktop
28
+ 1366, # Desktop
29
+ # 1400, # Breakpoint boostrap
30
+ 1440, # Samsung Galaxy S20, 360@4x
31
+ 1536, # Desktop, some iPads
32
+ 1920, # Desktop 2k
33
+ 2048, # Some iPad
34
+ 2240, # Desktop iMac M1 chipset
35
+ 2880, # Desktop MacBook Pro/Air 13" @2x
36
+ 3072 # Desktop MacBook Pro 16" @2x
37
+ ]
38
+
39
+ mattr_accessor :quality
40
+ @@quality = 80
41
+
12
42
  class Engine < ::Rails::Engine
13
43
  end
14
44
 
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.8'
4
+ version: 1.10.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-09-17 00:00:00.000000000 Z
12
+ date: 2021-11-15 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.