shimmer 0.0.16 → 0.0.17
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/shimmer/utils/file_helper.rb +21 -3
- data/lib/shimmer/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ef9968ad0ba48627fb9adb95ae2702575de2f9fa1b1e56ba3f30c9872d9cde38
|
4
|
+
data.tar.gz: c8bef4d12c776820c96e810a1e3ae1cb7c6717f029d5ac532b7fc05e595005d2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2c2dfb753bd6ac9afc4a4ba726c99a53a1dce6e1843c6b5bcdc320671ffcb2da0a8575ff357fd1294b3c25beed7a2026e144dffc0873a1a6ded6b78318ac737a
|
7
|
+
data.tar.gz: 9c00815fe851db16bd4ebf925d2ba2beb8b84c729351982f430721d6c7a395d21fd162add118a82a80df13ed8b97c67f76ac8177dadac29573c9e9604d8f9687
|
@@ -2,6 +2,16 @@
|
|
2
2
|
|
3
3
|
module Shimmer
|
4
4
|
module FileHelper
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
included do
|
8
|
+
ActiveSupport.on_load(:action_view) do
|
9
|
+
include Shimmer::FileAdditions
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
module FileAdditions
|
5
15
|
def image_tag(source, **options)
|
6
16
|
return nil if source.blank?
|
7
17
|
|
@@ -9,19 +19,27 @@ module Shimmer
|
|
9
19
|
attachment = source
|
10
20
|
width = options[:width]
|
11
21
|
height = options[:height]
|
12
|
-
source =
|
22
|
+
source = image_file_path(source, width: width, height: height)
|
13
23
|
options[:loading] = :lazy
|
14
|
-
options[:srcset] = "#{source} 1x, #{
|
24
|
+
options[:srcset] = "#{source} 1x, #{image_file_path(attachment, width: width.to_i * 2, height: height ? height.to_i * 2 : nil)} 2x" if options[:width].present?
|
15
25
|
end
|
16
26
|
super source, options
|
17
27
|
end
|
18
28
|
|
29
|
+
def image_file_path(source, width: nil, height: nil)
|
30
|
+
image_file_proxy(source, width: width, height: height).path
|
31
|
+
end
|
32
|
+
|
19
33
|
def image_file_url(source, width: nil, height: nil)
|
34
|
+
image_file_proxy(source, width: width, height: height).url
|
35
|
+
end
|
36
|
+
|
37
|
+
def image_file_proxy(source, width: nil, height: nil)
|
20
38
|
return if source.blank?
|
21
39
|
return source if source.is_a?(String)
|
22
40
|
|
23
41
|
blob = source.try(:blob) || source
|
24
|
-
Shimmer::FileProxy.new(blob_id: blob.id, width: width, height: height)
|
42
|
+
Shimmer::FileProxy.new(blob_id: blob.id, width: width, height: height)
|
25
43
|
end
|
26
44
|
end
|
27
45
|
end
|
data/lib/shimmer/version.rb
CHANGED