kamifusen 1.12.0 → 1.13.0

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: 267a1dc5741237d4a1255563dcb2f7fccb7717233ae02ad17b32d8829e9dd8d8
4
- data.tar.gz: 24662f9214bbbc62cfb9268ff88a071d4d0bb5cf85e82902b0b1cf20f7cf409b
3
+ metadata.gz: d6b3840b515b44e7d6ed8aa12a5356ebba29978d01129ce320c76f3d22a307eb
4
+ data.tar.gz: 64095c851bda7934311a8a3e02d296c4cc777d030bc3e7d418543d5b1c36ac07
5
5
  SHA512:
6
- metadata.gz: bbe200dc7c4335380d89fd878fbc3bee55deadddd5cc30a3ca920c0df0c9f86c4ab6199486d67f8959bb2e14154492587cc8898b2f4e97dcdb191a447a4df62a
7
- data.tar.gz: cb0a63d0b2ae76002bb2455aae1e7ed2c706a6580518b5ac06cb4189b2b760f05a184711558ed2e9ee4c4cae4bc110ac1eb5b575cb3b17b95447c3a85d6456e7
6
+ metadata.gz: 3dcaaa6832c838370e8912a53a024df972450fa51d95661334815e3d74779f4d756718823df8fe435f5f0cb692386c5d999a738c5ee44f0ac418ce54ddbd97ea
7
+ data.tar.gz: 3163c01dbd79f9bbcc1e13ac3b19f11b5b5bab40f681c63f23d0e419721ca7a11cac36581778bc928a5a064ebea201fbb594d9df26b16dc8864bd2712f6c8d23
data/.gitignore CHANGED
@@ -1,9 +1,4 @@
1
1
  /.bundle/
2
- /.yardoc
3
- /_yardoc/
4
- /coverage/
5
- /spec/reports/
6
- /.bundle/
7
2
  /doc/
8
3
  /log/*.log
9
4
  /pkg/
@@ -13,5 +8,3 @@
13
8
  /test/dummy/log/*.log
14
9
  /test/dummy/storage/
15
10
  /test/dummy/tmp/
16
- .byebug_history
17
- .DS_Store
data/Rakefile CHANGED
@@ -1,8 +1,3 @@
1
1
  # frozen_string_literal: true
2
-
2
+ require "bundler/setup"
3
3
  require "bundler/gem_tasks"
4
- require "rubocop/rake_task"
5
-
6
- RuboCop::RakeTask.new
7
-
8
- task default: :rubocop
@@ -6,8 +6,8 @@ elsif source.respond_to?(:attached?)
6
6
  source_is_set = source.attached?
7
7
  end
8
8
  %>
9
- <%
10
- if source_is_set
9
+ <%
10
+ if source_is_set
11
11
  options ||= {}
12
12
  cached = options.dig(:cached)
13
13
  cache_if(cached, [source, options]) do
@@ -20,8 +20,19 @@ if source_is_set
20
20
  picture_class = options[:picture_class]
21
21
  width = options[:width]
22
22
  height = options[:height]
23
+ crop = options[:crop]
24
+ if crop && (width.nil? || height.nil?)
25
+ raise ArgumentError, "Cropping needs a width and a height."
26
+ end
23
27
  variant_sizes = Kamifusen.sizes.dup
24
28
  quality = Kamifusen.quality.dup
29
+ default_variant_options = {}
30
+ case ActiveStorage.variant_processor
31
+ when :vips
32
+ default_variant_options = { saver: { quality: quality } }
33
+ when :mini_magick
34
+ default_variant_options = { quality: quality }
35
+ end
25
36
 
26
37
  sizes = options[:sizes] || {}
27
38
  sizes_value = sizes.map { |key, value| [key, value].join(' ').strip }.join(', ')
@@ -40,8 +51,8 @@ if source_is_set
40
51
  elsif height.nil?
41
52
  # Calculated height, preserving the aspect ratio
42
53
  height = width / image_ratio
43
- else
44
- # Explicit dimensions. We redefine the height if aspect ratio is not preserved.
54
+ elsif !crop
55
+ # Explicit dimensions, no crop. We redefine the height if aspect ratio is not preserved.
45
56
  width = [image_width, width].min
46
57
  height = width / image_ratio
47
58
  end
@@ -73,15 +84,36 @@ if source_is_set
73
84
  default_width = width_retina if width_retina && width_retina > default_width
74
85
  if Kamifusen.with_webp
75
86
  srcset_webp = variant_sizes.map { |size|
76
- variant = source.variant(resize: "#{size}>", format: :webp, quality: quality)
87
+ if crop
88
+ # Width: 400, height: 600 ; if width: 200, height: 300
89
+ variant_height = (height * size / width).round
90
+ variant_options = default_variant_options.merge({ resize_to_fill: [size, variant_height], format: :webp })
91
+ else
92
+ variant_options = default_variant_options.merge({ resize_to_limit: [size, nil], format: :webp })
93
+ end
94
+ variant = source.variant(variant_options)
77
95
  "#{ Kamifusen.process(variant, active_storage_direct_url) } #{size}w"
78
96
  }.join(', ')
79
97
  end
80
98
  srcset_default = variant_sizes.map { |size|
81
- variant = source.variant(resize: "#{size}>", quality: quality)
99
+ if crop
100
+ # Width: 400, height: 600 ; if width: 200, height: 300
101
+ variant_height = (height * size / width).round
102
+ variant_options = default_variant_options.merge({ resize_to_fill: [size, variant_height] })
103
+ else
104
+ variant_options = default_variant_options.merge({ resize_to_limit: [size, nil] })
105
+ end
106
+ variant = source.variant(variant_options)
82
107
  "#{ Kamifusen.process(variant, active_storage_direct_url) } #{size}w"
83
108
  }.join(', ')
84
- variant = source.variant(resize: "#{default_width}>", quality: quality)
109
+ if crop
110
+ # Width: 400, height: 600 ; if width: 200, height: 300
111
+ variant_height = (height * default_width / width).round
112
+ variant_options = default_variant_options.merge({ resize_to_fill: [default_width, variant_height] })
113
+ else
114
+ variant_options = default_variant_options.merge({ resize_to_limit: [default_width, nil] })
115
+ end
116
+ variant = source.variant(variant_options)
85
117
  default = Kamifusen.process(variant, active_storage_direct_url)
86
118
  %>
87
119
  <picture<%= " class=\"#{picture_class}\"".html_safe unless picture_class.blank? %>>
data/kamifusen.gemspec CHANGED
@@ -29,6 +29,5 @@ Gem::Specification.new do |spec|
29
29
  spec.add_dependency "rails"
30
30
  spec.add_dependency "image_processing"
31
31
 
32
- spec.add_development_dependency "listen"
33
32
  spec.add_development_dependency "sqlite3"
34
33
  end
@@ -14,28 +14,73 @@ module Kamifusen
14
14
 
15
15
  protected
16
16
 
17
- def keycdn_url
18
- url = "#{Kamifusen.keycdn}/#{variant.blob.key}?"
19
- transformations = variant.variation.transformations
20
- url += "format=#{transformations[:format]}&" if transformations.has_key? :format
21
- url += "quality=#{transformations[:quality]}&" if transformations.has_key? :quality
22
- if transformations.has_key? :resize
17
+ def transformations
18
+ @transformations ||= variant.variation.transformations
19
+ end
20
+
21
+ def format
22
+ return @format if defined?(@format)
23
+ @format = transformations.fetch(:format)
24
+ end
25
+
26
+ def quality
27
+ return @quality if defined?(@quality)
28
+ @quality = case ActiveStorage.variant_processor
29
+ when :vips
30
+ transformations.dig(:saver, :quality)
31
+ when :mini_magick
32
+ transformations.fetch(:quality)
33
+ end
34
+ end
35
+
36
+ def width
37
+ return @width if defined?(@width)
38
+ if transformations.has_key?(:resize)
39
+ Kamifusen.deprecator.warn("The `resize` transformation is deprecated. Please use `resize_to_limit` instead.")
40
+ # resize: "100>"
23
41
  resize = transformations[:resize]
24
- # 100>
25
- if '>'.in? resize
26
- width = resize.split('>').first.to_i
27
- url += "width=#{width}&"
28
- end
42
+ @width = resize.split('>').first.to_i if '>'.in?(resize)
43
+ elsif transformations.has_key?(:resize_to_limit)
44
+ # resize_to_limit: [100, nil]
45
+ @width = transformations[:resize_to_limit].first.to_i
46
+ elsif transformations.has_key?(:resize_to_fill)
47
+ # resize_to_fill: [400, 600]
48
+ @width = transformations[:resize_to_fill].first.to_i
29
49
  end
30
- url
50
+ @width
51
+ end
52
+
53
+ def height
54
+ return @height if defined?(@height)
55
+ if transformations.has_key?(:resize_to_fill)
56
+ # resize_to_fill: [400, 600]
57
+ @height = transformations[:resize_to_fill].second.to_i
58
+ end
59
+ @height
60
+ end
61
+
62
+ def crop
63
+ return @crop if defined?(@crop)
64
+ @crop = transformations.has_key?(:resize_to_fill)
65
+ end
66
+
67
+ def keycdn_url
68
+ return @keycdn_url if defined?(@keycdn_url)
69
+ @keycdn_url = "#{Kamifusen.keycdn}/#{variant.blob.key}?"
70
+ @keycdn_url += "format=#{format}&" if format.present?
71
+ @keycdn_url += "width=#{width}&" if width.present?
72
+ @keycdn_url += "height=#{height}&" if crop && height.present?
73
+ @keycdn_url += "quality=#{quality}&" if quality.present?
74
+ @keycdn_url
31
75
  end
32
76
 
33
77
  def active_storage_url
34
- url = nil
35
- url = processed_url if active_storage_direct_url
36
- url ||= smart_url
37
- url ||= explicit_url
38
- url
78
+ return @active_storage_url if defined?(@active_storage_url)
79
+ @active_storage_url = nil
80
+ @active_storage_url = processed_url if active_storage_direct_url
81
+ @active_storage_url ||= smart_url
82
+ @active_storage_url ||= explicit_url
83
+ @active_storage_url
39
84
  end
40
85
 
41
86
  def processed_url
@@ -1,6 +1,10 @@
1
1
  module Kamifusen
2
2
  class Railtie < ::Rails::Railtie
3
- initializer "my_gem.view_helpers" do
3
+ initializer "kamifusen.deprecator", before: :load_environment_config do |app|
4
+ app.deprecators[:kamifusen] = ActionMailbox.deprecator
5
+ end
6
+
7
+ initializer "kamifusen.view_helpers" do
4
8
  ActiveSupport.on_load(:action_view) { include Kamifusen::ViewHelper }
5
9
  end
6
10
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Kamifusen
4
- VERSION = "1.12.0"
4
+ VERSION = "1.13.0"
5
5
  end
data/lib/kamifusen.rb CHANGED
@@ -11,6 +11,10 @@ module Kamifusen
11
11
  yield self
12
12
  end
13
13
 
14
+ def self.deprecator
15
+ @deprecator ||= ActiveSupport::Deprecation.new("2.0", "Kamifūsen")
16
+ end
17
+
14
18
  def self.process(variant, active_storage_direct_url = false)
15
19
  Processor.new(variant, active_storage_direct_url).url
16
20
  end
@@ -55,6 +59,9 @@ module Kamifusen
55
59
  @@quality = 70
56
60
 
57
61
  class Engine < ::Rails::Engine
62
+ initializer "kamifusen.deprecator", before: :load_environment_config do |app|
63
+ app.deprecators[:kamifusen] = Kamifusen.deprecator
64
+ end
58
65
  end
59
66
 
60
67
  class Error < StandardError
metadata CHANGED
@@ -1,15 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kamifusen
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.12.0
4
+ version: 1.13.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sébastien Moulène
8
8
  - Arnaud Levy
9
- autorequire:
10
9
  bindir: exe
11
10
  cert_chain: []
12
- date: 2024-07-10 00:00:00.000000000 Z
11
+ date: 1980-01-02 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rails
@@ -39,20 +38,6 @@ dependencies:
39
38
  - - ">="
40
39
  - !ruby/object:Gem::Version
41
40
  version: '0'
42
- - !ruby/object:Gem::Dependency
43
- name: listen
44
- requirement: !ruby/object:Gem::Requirement
45
- requirements:
46
- - - ">="
47
- - !ruby/object:Gem::Version
48
- version: '0'
49
- type: :development
50
- prerelease: false
51
- version_requirements: !ruby/object:Gem::Requirement
52
- requirements:
53
- - - ">="
54
- - !ruby/object:Gem::Version
55
- version: '0'
56
41
  - !ruby/object:Gem::Dependency
57
42
  name: sqlite3
58
43
  requirement: !ruby/object:Gem::Requirement
@@ -79,8 +64,6 @@ files:
79
64
  - ".rubocop.yml"
80
65
  - CHANGELOG.md
81
66
  - CODE_OF_CONDUCT.md
82
- - Gemfile
83
- - Gemfile.lock
84
67
  - LICENSE
85
68
  - README.md
86
69
  - Rakefile
@@ -102,7 +85,6 @@ licenses:
102
85
  metadata:
103
86
  homepage_uri: https://github.com/sebousan/kamifusen
104
87
  source_code_uri: https://github.com/sebousan/kamifusen
105
- post_install_message:
106
88
  rdoc_options: []
107
89
  require_paths:
108
90
  - lib
@@ -117,8 +99,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
99
  - !ruby/object:Gem::Version
118
100
  version: '0'
119
101
  requirements: []
120
- rubygems_version: 3.4.10
121
- signing_key:
102
+ rubygems_version: 3.6.9
122
103
  specification_version: 4
123
104
  summary: Images, light as balloons
124
105
  test_files: []
data/Gemfile DELETED
@@ -1,12 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- source "https://rubygems.org"
4
-
5
- # Specify your gem's dependencies in kamifusen.gemspec
6
- gemspec
7
-
8
- gem "rake", "~> 13.0"
9
-
10
- gem "rubocop", "~> 1.7"
11
-
12
- gem "byebug"
data/Gemfile.lock DELETED
@@ -1,244 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- kamifusen (1.12.0)
5
- image_processing
6
- rails
7
-
8
- GEM
9
- remote: https://rubygems.org/
10
- specs:
11
- actioncable (7.1.3.4)
12
- actionpack (= 7.1.3.4)
13
- activesupport (= 7.1.3.4)
14
- nio4r (~> 2.0)
15
- websocket-driver (>= 0.6.1)
16
- zeitwerk (~> 2.6)
17
- actionmailbox (7.1.3.4)
18
- actionpack (= 7.1.3.4)
19
- activejob (= 7.1.3.4)
20
- activerecord (= 7.1.3.4)
21
- activestorage (= 7.1.3.4)
22
- activesupport (= 7.1.3.4)
23
- mail (>= 2.7.1)
24
- net-imap
25
- net-pop
26
- net-smtp
27
- actionmailer (7.1.3.4)
28
- actionpack (= 7.1.3.4)
29
- actionview (= 7.1.3.4)
30
- activejob (= 7.1.3.4)
31
- activesupport (= 7.1.3.4)
32
- mail (~> 2.5, >= 2.5.4)
33
- net-imap
34
- net-pop
35
- net-smtp
36
- rails-dom-testing (~> 2.2)
37
- actionpack (7.1.3.4)
38
- actionview (= 7.1.3.4)
39
- activesupport (= 7.1.3.4)
40
- nokogiri (>= 1.8.5)
41
- racc
42
- rack (>= 2.2.4)
43
- rack-session (>= 1.0.1)
44
- rack-test (>= 0.6.3)
45
- rails-dom-testing (~> 2.2)
46
- rails-html-sanitizer (~> 1.6)
47
- actiontext (7.1.3.4)
48
- actionpack (= 7.1.3.4)
49
- activerecord (= 7.1.3.4)
50
- activestorage (= 7.1.3.4)
51
- activesupport (= 7.1.3.4)
52
- globalid (>= 0.6.0)
53
- nokogiri (>= 1.8.5)
54
- actionview (7.1.3.4)
55
- activesupport (= 7.1.3.4)
56
- builder (~> 3.1)
57
- erubi (~> 1.11)
58
- rails-dom-testing (~> 2.2)
59
- rails-html-sanitizer (~> 1.6)
60
- activejob (7.1.3.4)
61
- activesupport (= 7.1.3.4)
62
- globalid (>= 0.3.6)
63
- activemodel (7.1.3.4)
64
- activesupport (= 7.1.3.4)
65
- activerecord (7.1.3.4)
66
- activemodel (= 7.1.3.4)
67
- activesupport (= 7.1.3.4)
68
- timeout (>= 0.4.0)
69
- activestorage (7.1.3.4)
70
- actionpack (= 7.1.3.4)
71
- activejob (= 7.1.3.4)
72
- activerecord (= 7.1.3.4)
73
- activesupport (= 7.1.3.4)
74
- marcel (~> 1.0)
75
- activesupport (7.1.3.4)
76
- base64
77
- bigdecimal
78
- concurrent-ruby (~> 1.0, >= 1.0.2)
79
- connection_pool (>= 2.2.5)
80
- drb
81
- i18n (>= 1.6, < 2)
82
- minitest (>= 5.1)
83
- mutex_m
84
- tzinfo (~> 2.0)
85
- ast (2.4.2)
86
- base64 (0.2.0)
87
- bigdecimal (3.1.8)
88
- builder (3.3.0)
89
- byebug (11.1.3)
90
- concurrent-ruby (1.3.3)
91
- connection_pool (2.4.1)
92
- crass (1.0.6)
93
- date (3.3.4)
94
- drb (2.2.1)
95
- erubi (1.13.0)
96
- ffi (1.17.0)
97
- ffi (1.17.0-x86_64-darwin)
98
- globalid (1.2.1)
99
- activesupport (>= 6.1)
100
- i18n (1.14.5)
101
- concurrent-ruby (~> 1.0)
102
- image_processing (1.12.2)
103
- mini_magick (>= 4.9.5, < 5)
104
- ruby-vips (>= 2.0.17, < 3)
105
- io-console (0.7.2)
106
- irb (1.14.0)
107
- rdoc (>= 4.0.0)
108
- reline (>= 0.4.2)
109
- json (2.7.2)
110
- language_server-protocol (3.17.0.3)
111
- listen (3.9.0)
112
- rb-fsevent (~> 0.10, >= 0.10.3)
113
- rb-inotify (~> 0.9, >= 0.9.10)
114
- loofah (2.22.0)
115
- crass (~> 1.0.2)
116
- nokogiri (>= 1.12.0)
117
- mail (2.8.1)
118
- mini_mime (>= 0.1.1)
119
- net-imap
120
- net-pop
121
- net-smtp
122
- marcel (1.0.4)
123
- mini_magick (4.13.2)
124
- mini_mime (1.1.5)
125
- mini_portile2 (2.8.7)
126
- minitest (5.24.1)
127
- mutex_m (0.2.0)
128
- net-imap (0.4.14)
129
- date
130
- net-protocol
131
- net-pop (0.1.2)
132
- net-protocol
133
- net-protocol (0.2.2)
134
- timeout
135
- net-smtp (0.5.0)
136
- net-protocol
137
- nio4r (2.7.3)
138
- nokogiri (1.16.6)
139
- mini_portile2 (~> 2.8.2)
140
- racc (~> 1.4)
141
- nokogiri (1.16.6-x86_64-darwin)
142
- racc (~> 1.4)
143
- parallel (1.25.1)
144
- parser (3.3.4.0)
145
- ast (~> 2.4.1)
146
- racc
147
- psych (5.1.2)
148
- stringio
149
- racc (1.8.0)
150
- rack (3.1.6)
151
- rack-session (2.0.0)
152
- rack (>= 3.0.0)
153
- rack-test (2.1.0)
154
- rack (>= 1.3)
155
- rackup (2.1.0)
156
- rack (>= 3)
157
- webrick (~> 1.8)
158
- rails (7.1.3.4)
159
- actioncable (= 7.1.3.4)
160
- actionmailbox (= 7.1.3.4)
161
- actionmailer (= 7.1.3.4)
162
- actionpack (= 7.1.3.4)
163
- actiontext (= 7.1.3.4)
164
- actionview (= 7.1.3.4)
165
- activejob (= 7.1.3.4)
166
- activemodel (= 7.1.3.4)
167
- activerecord (= 7.1.3.4)
168
- activestorage (= 7.1.3.4)
169
- activesupport (= 7.1.3.4)
170
- bundler (>= 1.15.0)
171
- railties (= 7.1.3.4)
172
- rails-dom-testing (2.2.0)
173
- activesupport (>= 5.0.0)
174
- minitest
175
- nokogiri (>= 1.6)
176
- rails-html-sanitizer (1.6.0)
177
- loofah (~> 2.21)
178
- nokogiri (~> 1.14)
179
- railties (7.1.3.4)
180
- actionpack (= 7.1.3.4)
181
- activesupport (= 7.1.3.4)
182
- irb
183
- rackup (>= 1.0.0)
184
- rake (>= 12.2)
185
- thor (~> 1.0, >= 1.2.2)
186
- zeitwerk (~> 2.6)
187
- rainbow (3.1.1)
188
- rake (13.2.1)
189
- rb-fsevent (0.11.2)
190
- rb-inotify (0.11.1)
191
- ffi (~> 1.0)
192
- rdoc (6.7.0)
193
- psych (>= 4.0.0)
194
- regexp_parser (2.9.2)
195
- reline (0.5.9)
196
- io-console (~> 0.5)
197
- rexml (3.3.1)
198
- strscan
199
- rubocop (1.65.0)
200
- json (~> 2.3)
201
- language_server-protocol (>= 3.17.0)
202
- parallel (~> 1.10)
203
- parser (>= 3.3.0.2)
204
- rainbow (>= 2.2.2, < 4.0)
205
- regexp_parser (>= 2.4, < 3.0)
206
- rexml (>= 3.2.5, < 4.0)
207
- rubocop-ast (>= 1.31.1, < 2.0)
208
- ruby-progressbar (~> 1.7)
209
- unicode-display_width (>= 2.4.0, < 3.0)
210
- rubocop-ast (1.31.3)
211
- parser (>= 3.3.1.0)
212
- ruby-progressbar (1.13.0)
213
- ruby-vips (2.2.1)
214
- ffi (~> 1.12)
215
- sqlite3 (2.0.2)
216
- mini_portile2 (~> 2.8.0)
217
- sqlite3 (2.0.2-x86_64-darwin)
218
- stringio (3.1.1)
219
- strscan (3.1.0)
220
- thor (1.3.1)
221
- timeout (0.4.1)
222
- tzinfo (2.0.6)
223
- concurrent-ruby (~> 1.0)
224
- unicode-display_width (2.5.0)
225
- webrick (1.8.1)
226
- websocket-driver (0.7.6)
227
- websocket-extensions (>= 0.1.0)
228
- websocket-extensions (0.1.5)
229
- zeitwerk (2.6.16)
230
-
231
- PLATFORMS
232
- ruby
233
- x86_64-darwin-20
234
-
235
- DEPENDENCIES
236
- byebug
237
- kamifusen!
238
- listen
239
- rake (~> 13.0)
240
- rubocop (~> 1.7)
241
- sqlite3
242
-
243
- BUNDLED WITH
244
- 2.4.22