kamifusen 1.3 → 1.7

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: eac96058e579f9ae629576bd126de9042b25ab3faffc7b99dfa875944d576239
4
- data.tar.gz: e8480cdec01a138f28b8a725492b99a50d41c1ae107e59c4e41544bf61b4b1d5
3
+ metadata.gz: cc7dc54c21db20fd2cfd6a7aec2c5b50aa7ee13f725648293246a5972f973240
4
+ data.tar.gz: 0f6d32fbe3006abc1d018916b66a71dbd20bd9e9edacf11ea5c4e841e446e5ca
5
5
  SHA512:
6
- metadata.gz: 2d3d568386dfb35f13a820c8b6d4ec7a0381958dc1cc387932f844c50deeb40f6afd3c9041edfb4222d5506ef358dc837f3709a22fac6ba28d5169b51efe1be9
7
- data.tar.gz: 43ec54add0ff08ec20ba708db5c3de12555c2d260e17314696ee6ac2c7bc3957912e800fdfbea66412883375dbcc9d1ea8f932c4b36dff34ddd59c22081938a5
6
+ metadata.gz: ae20b1464beb842cc4a17275b2d154a3bf572405b8c7a97be7acd57e91245571460fbac7fdefff62e380cd0a6a21e6fb863df950d6f4d2552cde7a3faa80acd8
7
+ data.tar.gz: d120ad3e78b7094c352874b7fbafd611a6017eeef5cb2e621879e0863f310ef5a512b7ac58126c51d344647d40cc069837f7aa94a34c05af8733a1c40c5e1fac
data/Gemfile.lock CHANGED
@@ -1,67 +1,67 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- kamifusen (1.3)
4
+ kamifusen (1.7)
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.4.2)
78
- activesupport (>= 4.2.0)
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.10.0)
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.0)
96
- mini_portile2 (2.5.3)
95
+ mini_mime (1.1.1)
96
+ mini_portile2 (2.6.1)
97
97
  minitest (5.14.4)
98
- nio4r (2.5.7)
99
- nokogiri (1.11.7)
100
- mini_portile2 (~> 2.5.0)
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.3.0)
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.2)
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,20 +2,68 @@
2
2
  # image_tag options
3
3
  options ||= {}
4
4
  alt = options[:alt]
5
- width = options[:width]
6
- height = options[:height]
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
7
9
  klass = options[:class]
8
10
  picture_class = options[:picture_class]
9
- parameters = " loading=\"lazy\" decoding=\"async\""
10
- parameters += " alt=\"#{ options[:alt] }\"" if alt
11
- parameters += " width=\"#{ options[:width] }\"" if width
12
- parameters += " height=\"#{ options[:height]}\"" if height
13
- parameters += " class=\"#{ options[:class] }\"" if klass
11
+ width = options[:width]
12
+ height = options[:height]
13
+ if source&.metadata &&
14
+ source.metadata['analyzed'] &&
15
+ source.metadata.has_key?('width') &&
16
+ source.metadata.has_key?('height')
17
+ image_width = source.metadata['width']
18
+ image_height = source.metadata['height']
19
+ image_ratio = 1.0 * image_width / image_height
20
+ if width.nil? && height.nil?
21
+ # Prendre width et height réelles de l'image
22
+ width = image_width
23
+ height = image_height
24
+ elsif width.nil?
25
+ # Calculer la height sur ratio
26
+ width = height * image_ratio
27
+ elsif height.nil?
28
+ # Calcule la width sur ratio
29
+ height = width / image_ratio
30
+ else
31
+ # Width et height sont explicites,
32
+ # si le ratio demandé n'est pas celui de l'image,
33
+ # Redéfinir la height
34
+ width = [image_width, width].min
35
+ height = width / image_ratio
36
+ end
37
+ width = width.round
38
+ height = height.round
39
+ end
40
+ parameters = ""
41
+ parameters += " loading=\"lazy\" decoding=\"async\"" if async
42
+ parameters += " alt=\"#{ alt }\"" if alt
43
+ parameters += " width=\"#{ width }\"" if width
44
+ parameters += " height=\"#{ height }\"" if height
45
+ parameters += " class=\"#{ klass }\"" if klass
46
+
47
+ def kamifusen_process(variant, active_storage_direct_url)
48
+ if active_storage_direct_url
49
+ begin
50
+ # Pour générer la processed url, il faut savoir où sont stockées les images
51
+ # https://discuss.rubyonrails.org/t/define-host-so-absolute-urls-work-in-development-and-test/75085
52
+ # https://stackoverflow.com/questions/60425407/uriinvalidurierror-bad-uriis-not-uri-nil-active-storage-service-url
53
+ # Not compatible with Disk storage, will return nil
54
+ url = variant.processed.url
55
+ rescue
56
+ end
57
+ end
58
+ url = url_for(variant) if url.nil?
59
+ url
60
+ end
14
61
  %>
15
62
  <% if source.variable? %>
63
+ <%#= "#{image_width} x #{image_height}, #{image_ratio} ratio => #{width} x #{height}<br>".html_safe %>
16
64
  <%
17
65
  # kamifusen settings
18
- sizes = [320, 576, 640, 768, 992, 1152, 1200, 1400, 1536, 1984, 2400]
66
+ sizes = [360, 375, 414, 576, 640, 750, 768, 828, 992, 1152, 1200, 1366, 1400, 1536, 1920, 1984, 2400]
19
67
  quality = 80
20
68
  # Computing
21
69
  if width
@@ -28,13 +76,16 @@ parameters += " class=\"#{ options[:class] }\"" if klass
28
76
  default_width = width_retina if width_retina && width_retina > default_width
29
77
  if Kamifusen.with_webp
30
78
  srcset_webp = sizes.map { |size|
31
- "#{ url_for source.variant(resize: "#{size}>", format: :webp, quality: quality) } #{ size }w"
79
+ variant = source.variant(resize: "#{size}>", format: :webp, quality: quality)
80
+ "#{ kamifusen_process(variant, active_storage_direct_url) } #{ size }w"
32
81
  }.join(', ')
33
82
  end
34
83
  srcset_default = sizes.map { |size|
35
- "#{ url_for source.variant(resize: "#{size}>", quality: quality) } #{ size }w"
84
+ variant = source.variant(resize: "#{size}>", quality: quality)
85
+ "#{ kamifusen_process(variant, active_storage_direct_url) } #{ size }w"
36
86
  }.join(', ')
37
- default = url_for source.variant(resize: "#{default_width}>", quality: quality)
87
+ variant = source.variant(resize: "#{default_width}>", quality: quality)
88
+ default = kamifusen_process(variant, active_storage_direct_url)
38
89
  %>
39
90
  <picture<%= " class=\"#{picture_class}\"".html_safe unless picture_class.blank? %>>
40
91
  <% if Kamifusen.with_webp %>
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Kamifusen
4
- VERSION = "1.3"
4
+ VERSION = "1.7"
5
5
  end
@@ -2,7 +2,6 @@
2
2
  module Kamifusen
3
3
  module ViewHelper
4
4
  def kamifusen_tag(source, options = {})
5
- image_tag(source, options)
6
5
  render "kamifusen/view", source: source, options: options
7
6
  end
8
7
  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.3'
4
+ version: '1.7'
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-07-02 00:00:00.000000000 Z
12
+ date: 2021-09-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails