kamifusen 0.9.1 → 0.9.6

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: fba4cc594fa4ab1ae8205a187f84b2815265127fed09c3cc3a46da87808068f1
4
- data.tar.gz: d82f0bf97ded7f442deb90c6647918ceb312a5197a2e313bee1adebb40b1e4d2
3
+ metadata.gz: a689acadb87e346abfda6e357a1de05daf496622275dacc35d4b1f4c3464f3f9
4
+ data.tar.gz: e21c4b4e6048ea0ba35709bfad5b364e2292ac9cbb7767c655b51d2913e63fd8
5
5
  SHA512:
6
- metadata.gz: dc71b4eba1b972abf61e8204e69940589e35828d8200b47aff400524402fd071890972988d0c7af978ae602e1b11ef64ecc4229a58ee705509f639de5daa772a
7
- data.tar.gz: 2d6bd8e27099ccfe668c1066fbd4b6e5a9456956a54d084e00bef16e3ffd3203c12210b985801d42d843fac6e290c3e263d94a4159f042a0e32839745d2742e0
6
+ metadata.gz: d44f3179b6a02b35c880d083a9b8a4232ee14e01564ef29017a45430f0acfcac328fac44b5d374dd32ecbb69de4ebd5e463d9351279404fabe5840126352c7a4
7
+ data.tar.gz: 46501974677fab6ae5749705991dded8bdfddd0b223e76b8eea9048eb67ee642f942ad99df046bd26e57f4728d38e7c7684faea09cfa75f1a0b7fdc19d48e6b4
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- Kamifusen (0.1.1)
4
+ kamifusen (0.9.6)
5
5
  image_processing
6
6
  rails
7
7
 
@@ -94,7 +94,7 @@ GEM
94
94
  mini_mime (1.0.3)
95
95
  minitest (5.14.4)
96
96
  nio4r (2.5.7)
97
- nokogiri (1.11.4-x86_64-darwin)
97
+ nokogiri (1.11.6-x86_64-darwin)
98
98
  racc (~> 1.4)
99
99
  parallel (1.20.1)
100
100
  parser (3.0.1.1)
@@ -162,7 +162,7 @@ GEM
162
162
  tzinfo (2.0.4)
163
163
  concurrent-ruby (~> 1.0)
164
164
  unicode-display_width (2.0.0)
165
- websocket-driver (0.7.3)
165
+ websocket-driver (0.7.4)
166
166
  websocket-extensions (>= 0.1.0)
167
167
  websocket-extensions (0.1.5)
168
168
  zeitwerk (2.4.2)
@@ -171,7 +171,7 @@ PLATFORMS
171
171
  x86_64-darwin-20
172
172
 
173
173
  DEPENDENCIES
174
- Kamifusen!
174
+ kamifusen!
175
175
  listen
176
176
  rake (~> 13.0)
177
177
  rubocop (~> 1.7)
data/README.md CHANGED
@@ -2,6 +2,34 @@
2
2
 
3
3
  ![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
4
 
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'kamifusen'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle install
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install kamifusen
20
+
21
+ In the views, use (where object is an active record model, and image is an active storage attachment):
22
+
23
+ ```erb
24
+ <%= kamifusen_tag object.image, alt: 'A nice image' %>
25
+ ```
26
+
27
+ If you want to disable webp, in config/initializers/kamifusen.rb:
28
+
29
+ ```ruby
30
+ Kamifusen.with_webp = false
31
+ ```
32
+
5
33
  ## Usage
6
34
 
7
35
  Simply use `kamifusen_tag` instead of `image_tag` in your rails views.## What's the problem?
@@ -76,11 +104,13 @@ Webp and AVIF are more efficient formats than jpg and png. They allow better com
76
104
  https://sebousan.github.io/kamifusen/
77
105
 
78
106
  The new helper is:
107
+
79
108
  ```erb
80
109
  <%= kamifusen_tag object.image, alt: 'A nice image' %>
81
110
  ```
82
111
 
83
112
  It generates a code like:
113
+
84
114
  ```html
85
115
  <picture>
86
116
  <source srcset="image-800w.avif, image-1600w.avif 2x" type="image/avif" media="(min-width: 800px)">
@@ -93,22 +123,6 @@ It generates a code like:
93
123
  </picture>
94
124
  ```
95
125
 
96
- ## Installation
97
-
98
- Add this line to your application's Gemfile:
99
-
100
- ```ruby
101
- gem 'kamifusen'
102
- ```
103
-
104
- And then execute:
105
-
106
- $ bundle install
107
-
108
- Or install it yourself as:
109
-
110
- $ gem install kamifusen
111
-
112
126
  ## References
113
127
 
114
128
  - https://developer.mozilla.org/fr/docs/Learn/HTML/Multimedia_and_embedding/Responsive_images
@@ -1,18 +1,41 @@
1
1
  <%
2
2
  # image_tag options
3
+ options ||= {}
3
4
  alt = options[:alt]
4
5
  width = options[:width]
5
6
  height = options[:height]
6
- # kamifusen settings
7
- sizes = [320, 576, 640, 768, 992, 1152, 1200, 1400, 1536, 1984, 2400]
8
- quality = 80
9
- # Computing
10
- sizes.reject! { |size| size > width * 2 } if width
11
- webps = sizes.map { |size| "#{ url_for source.variant(resize: "#{size}>", format: :webp, quality: quality) } #{ size } vw" }.join(', ')
12
- jpgs = sizes.map { |size| "#{ url_for source.variant(resize: "#{size}>", format: :jpg, quality: quality) } #{ size } vw" }.join(', ')
13
- default = url_for source.variant(resize: "#{sizes.max}>", format: :jpg, quality: quality)
7
+ klass = options[:class]
8
+ parameters = " loading=\"lazy\" decoding=\"async\""
9
+ parameters += " alt=\"#{ options[:alt] }\"" if alt
10
+ parameters += " width=\"#{ options[:width] }\"" if width
11
+ parameters += " height=\"#{ options[:height]}\"" if height
12
+ parameters += " class=\"#{ options[:class] }\"" if klass
14
13
  %>
15
- <picture>
16
- <source srcset="<%= webps %>">
17
- <img src="<%= default %>" srcset="<%= jpgs %>" alt="<%= alt %>" loading="lazy" decoding="async"<%= raw " width=\"#{ width }\"" if width %><%= raw " height=\"#{ height}\"" if height %>>
18
- </picture>
14
+ <% if source.variable? %>
15
+ <%
16
+ # kamifusen settings
17
+ sizes = [320, 576, 640, 768, 992, 1152, 1200, 1400, 1536, 1984, 2400]
18
+ quality = 80
19
+ # Computing
20
+ sizes.reject! { |size| size > width * 2 } if width
21
+ if Kamifusen.with_webp
22
+ srcset_webp = sizes.map { |size|
23
+ "#{ url_for source.variant(resize: "#{size}>", format: :webp, quality: quality) } #{ size }w"
24
+ }.join(', ')
25
+ end
26
+ srcset_default = sizes.map { |size|
27
+ "#{ url_for source.variant(resize: "#{size}>", quality: quality) } #{ size }w"
28
+ }.join(', ')
29
+ default = url_for source.variant(resize: "#{sizes.max}>", quality: quality)
30
+ %>
31
+ <picture>
32
+ <% if Kamifusen.with_webp %>
33
+ <source srcset="<%= srcset_webp %>">
34
+ <% end %>
35
+ <img src="<%= default %>" srcset="<%= srcset_default %>"<%= raw parameters %>>
36
+ </picture>
37
+ <% else %>
38
+ <picture>
39
+ <img src="<%= url_for source %>"<%= raw parameters %>>
40
+ </picture>
41
+ <% end %>
data/lib/kamifusen.rb CHANGED
@@ -5,8 +5,13 @@ require "kamifusen/railtie"
5
5
  require "kamifusen/view_helper"
6
6
 
7
7
  module Kamifusen
8
+
9
+ mattr_accessor :with_webp
10
+ @@with_webp = true
11
+
8
12
  class Engine < ::Rails::Engine
9
13
  end
14
+
10
15
  class Error < StandardError
11
16
  end
12
17
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Kamifusen
4
- VERSION = "0.9.1"
4
+ VERSION = "0.9.6"
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: 0.9.1
4
+ version: 0.9.6
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-05-26 00:00:00.000000000 Z
12
+ date: 2021-06-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails