kamifusen 1.5 → 1.9

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: 1b297bc21e758df40da735dee289c75adf846daf1fc4d11c88aa041b9985cf4e
4
- data.tar.gz: 62322fa18a71d6297fff797b91fcbc3ce06103bd20327b262b08be8d6d6f11a5
3
+ metadata.gz: a82b418d1a07d8b33f845d6ded2bdf3d1309943e41350f8e003bbdcbfe867f08
4
+ data.tar.gz: 0d20f1c01167036520f1451f1d295d8c7a32d40e315b8ac6fdee707fb3236c43
5
5
  SHA512:
6
- metadata.gz: 48dd1181ec937589ded1d25f5897f99e9ce2a52714f7239c6f8dca14db443cc9fa22ca11f8301a1de66d624e974a9e1d182aafe0b1b307757ecbe256c592c8fd
7
- data.tar.gz: 817ec1062b6b0b44f264182b2ba3af016f43fe77c7ac87dd640210d81798ee901c4e2895ef4d841b229ef8e2a78629fb58d0f6f2f1b1527251974790065fabdd
6
+ metadata.gz: 999758e2fece72df932546f261091b4ffc1584b85668fc9102852d703d4c45526a66ae980ae918f64a6884b99267d2c8c2d3c4646b78a7475ccfd5c01ccf64e0
7
+ data.tar.gz: be8d74901d1bb3f1859e01e6940c00aa2c9ee67aa086c34fb241de5e5adb510e14a93f39c040ba8dfa8708b1134d7637783775b3a7225cb400575d57643c316c
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- kamifusen (1.5)
4
+ kamifusen (1.8)
5
5
  image_processing
6
6
  rails
7
7
 
@@ -2,11 +2,18 @@
2
2
  # image_tag options
3
3
  options ||= {}
4
4
  alt = options[:alt]
5
- async = options[:sync] || true
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
6
9
  klass = options[:class]
7
10
  picture_class = options[:picture_class]
8
11
  width = options[:width]
9
12
  height = options[:height]
13
+
14
+ sizes = Kamifusen.sizes
15
+ quality = Kamifusen.quality
16
+
10
17
  if source&.metadata &&
11
18
  source.metadata['analyzed'] &&
12
19
  source.metadata.has_key?('width') &&
@@ -16,8 +23,8 @@ if source&.metadata &&
16
23
  image_ratio = 1.0 * image_width / image_height
17
24
  if width.nil? && height.nil?
18
25
  # Prendre width et height réelles de l'image
19
- width = image_width
20
- height = image_height
26
+ width = [image_width, sizes.last].min
27
+ height = width * image_ratio
21
28
  elsif width.nil?
22
29
  # Calculer la height sur ratio
23
30
  width = height * image_ratio
@@ -34,19 +41,31 @@ if source&.metadata &&
34
41
  width = width.round
35
42
  height = height.round
36
43
  end
37
- parameters = " "
38
- parameters = " loading=\"lazy\" decoding=\"async\"" if async
44
+ parameters = ""
45
+ parameters += " loading=\"lazy\" decoding=\"async\"" if async
39
46
  parameters += " alt=\"#{ alt }\"" if alt
40
47
  parameters += " width=\"#{ width }\"" if width
41
48
  parameters += " height=\"#{ height }\"" if height
42
49
  parameters += " class=\"#{ klass }\"" if klass
50
+
51
+ def kamifusen_process(variant, active_storage_direct_url)
52
+ if active_storage_direct_url
53
+ begin
54
+ # Pour générer la processed url, il faut savoir où sont stockées les images
55
+ # https://discuss.rubyonrails.org/t/define-host-so-absolute-urls-work-in-development-and-test/75085
56
+ # 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
+ url = variant.processed.url
59
+ rescue
60
+ end
61
+ end
62
+ url = url_for(variant) if url.nil?
63
+ url
64
+ end
43
65
  %>
44
66
  <% if source.variable? %>
45
67
  <%#= "#{image_width} x #{image_height}, #{image_ratio} ratio => #{width} x #{height}<br>".html_safe %>
46
68
  <%
47
- # kamifusen settings
48
- sizes = [320, 576, 640, 768, 992, 1152, 1200, 1400, 1536, 1984, 2400]
49
- quality = 80
50
69
  # Computing
51
70
  if width
52
71
  width_retina = width * 2
@@ -58,13 +77,16 @@ parameters += " class=\"#{ klass }\"" if klass
58
77
  default_width = width_retina if width_retina && width_retina > default_width
59
78
  if Kamifusen.with_webp
60
79
  srcset_webp = sizes.map { |size|
61
- "#{ url_for source.variant(resize: "#{size}>", format: :webp, quality: quality) } #{ size }w"
80
+ variant = source.variant(resize: "#{size}>", format: :webp, quality: quality)
81
+ "#{ kamifusen_process(variant, active_storage_direct_url) } #{ size }w"
62
82
  }.join(', ')
63
83
  end
64
84
  srcset_default = sizes.map { |size|
65
- "#{ url_for source.variant(resize: "#{size}>", quality: quality) } #{ size }w"
85
+ variant = source.variant(resize: "#{size}>", quality: quality)
86
+ "#{ kamifusen_process(variant, active_storage_direct_url) } #{ size }w"
66
87
  }.join(', ')
67
- default = url_for source.variant(resize: "#{default_width}>", quality: quality)
88
+ variant = source.variant(resize: "#{default_width}>", quality: quality)
89
+ default = kamifusen_process(variant, active_storage_direct_url)
68
90
  %>
69
91
  <picture<%= " class=\"#{picture_class}\"".html_safe unless picture_class.blank? %>>
70
92
  <% if Kamifusen.with_webp %>
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Kamifusen
4
- VERSION = "1.5"
4
+ VERSION = "1.9"
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
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.5'
4
+ version: '1.9'
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-16 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