acts_as_hoc_avatarable 0.1.11 → 0.1.12
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
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d8a72a0640879c1d94563f6d787d7b7a3f564b60
|
4
|
+
data.tar.gz: 879bc30177e1d76fc0fce45dd592e3c75204074c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f3a3ed70d5128736bfed89075d00495de6488f2092d341f3cbd4d29d47a04e9681667d96147e6ffa0fa0bd8ba8132fb7015bce1a4050d55e46f8ef414df61172
|
7
|
+
data.tar.gz: fd50a10b0df2274fe50d708b69dd68b3effdec87b3f933b34a086cc6b6632123a4cbc520d4483f44dd59d58d9ff787f7d690861ff5410566e09d605502fa6529
|
data/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# ActsAsHocAvatarable
|
2
2
|
|
3
|
-
Ease the use of
|
3
|
+
Ease the use of ActiveStorage as an avatar for eg. user model.
|
4
|
+
This is specially made for API usage, where data is delivered as a base64 string.
|
5
|
+
Images can be resized on saving.
|
4
6
|
This uses ActiveStorage, thus minimum rails version is 5.2
|
5
7
|
|
6
8
|
## Installation
|
@@ -15,28 +15,28 @@ module ActsAsHocAvatarable
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def avatar_url
|
18
|
-
return Rails.application.routes.url_helpers.rails_blob_url(avatar, host:
|
19
|
-
return "https://www.gravatar.com/avatar/#{Digest::MD5.hexdigest(email)}" if
|
18
|
+
return Rails.application.routes.url_helpers.rails_blob_url(avatar, host: ActsAsHocAvatarable.configuration.default_host) if avatar.attached?
|
19
|
+
return "https://www.gravatar.com/avatar/#{Digest::MD5.hexdigest(email)}" if ActsAsHocAvatarable.configuration.fallback_to_gravatar
|
20
20
|
return nil
|
21
21
|
end
|
22
22
|
|
23
23
|
def clear_avatar
|
24
24
|
if remove_avatar == '1'
|
25
|
-
avatar_contents = nil
|
25
|
+
@avatar_contents = nil
|
26
26
|
avatar.purge_later
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
30
|
def parse_avatar
|
31
31
|
# If directly uploaded
|
32
|
-
unless avatar_contents.nil? || avatar_contents[/(image\/[a-z]{3,4})
|
33
|
-
content_type = avatar_contents[/(image\/[a-z]{3,4})
|
32
|
+
unless avatar_contents.nil? || avatar_contents[/(image\/[a-z]{3,4})/] == ''
|
33
|
+
content_type = avatar_contents[/(image\/[a-z]{3,4})/]
|
34
34
|
content_type = content_type[/\b(?!.*\/).*/]
|
35
|
-
contents = avatar_contents.sub /data:((image
|
35
|
+
contents = avatar_contents.sub /data:((image)\/.{3,}),/, ''
|
36
36
|
decoded_data = Base64.decode64(contents)
|
37
37
|
mini_magick = MiniMagick::Image.read(decoded_data)
|
38
|
-
if
|
39
|
-
mini_magick.resize (ActsAsHocAvatarable.configuration.resize_size
|
38
|
+
if ActsAsHocAvatarable.configuration.resize_on_create
|
39
|
+
mini_magick.resize (ActsAsHocAvatarable.configuration.resize_size)
|
40
40
|
end
|
41
41
|
decoded_data = mini_magick.to_blob
|
42
42
|
filename = avatar_name || "avatar_#{Time.zone.now.to_i}.#{content_type}"
|