jekyll-avatar 0.2.3 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +7 -0
- data/lib/jekyll-avatar.rb +26 -15
- data/lib/jekyll-avatar/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 475ee02bafe22805fe38b7f4900f84083ad8d0d8
|
4
|
+
data.tar.gz: 1122411192e47273a9116a31eb61a4fb6a39fd80
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e38e2f39d7cb8bbe76f942ff08ca6dcd801f86734c3095e654f031536f28324e9bd75ad5639d9acb1ca77a93a51de6be1ff0ff6142d3fa963d58cb38e160fc65
|
7
|
+
data.tar.gz: b815e3a0c0164a0e59832ddde441c5bb1b6830b3bcc3ee8007e4047c05a9cf1aa1cc1f4d009f902770ffe2dd4c8ba4e786c54d8b5bfcc12a65ad82e2c28386de
|
data/.rubocop.yml
CHANGED
data/lib/jekyll-avatar.rb
CHANGED
@@ -12,21 +12,23 @@ module Jekyll
|
|
12
12
|
def render(context)
|
13
13
|
@context = context
|
14
14
|
@text = Liquid::Template.parse(@text).render(@context)
|
15
|
-
|
16
|
-
|
17
|
-
# See http://primercss.io/avatars/#small-avatars
|
18
|
-
tag << if size < 48
|
19
|
-
'class="avatar avatar-small" '
|
20
|
-
else
|
21
|
-
'class="avatar" '
|
22
|
-
end
|
23
|
-
|
24
|
-
tag << "src=\"#{url}\" alt=\"#{username}\" "
|
25
|
-
tag << "width=\"#{size}\" height=\"#{size}\" />"
|
15
|
+
attrs = attributes.map { |k, v| "#{k}=\"#{v}\"" }.join(' ')
|
16
|
+
"<img #{attrs} />"
|
26
17
|
end
|
27
18
|
|
28
19
|
private
|
29
20
|
|
21
|
+
def attributes
|
22
|
+
{
|
23
|
+
class: classes,
|
24
|
+
src: url,
|
25
|
+
alt: username,
|
26
|
+
srcset: srcset,
|
27
|
+
width: size,
|
28
|
+
height: size
|
29
|
+
}
|
30
|
+
end
|
31
|
+
|
30
32
|
def username
|
31
33
|
matches = @text.match(/\buser=(\w+)\b/)
|
32
34
|
if matches && @context.has_key?(matches[1])
|
@@ -41,8 +43,8 @@ module Jekyll
|
|
41
43
|
matches ? matches[1].to_i : DEFAULT_SIZE
|
42
44
|
end
|
43
45
|
|
44
|
-
def path
|
45
|
-
"#{username}?v=#{VERSION}&s=#{size}"
|
46
|
+
def path(scale = 1)
|
47
|
+
"#{username}?v=#{VERSION}&s=#{size * scale}"
|
46
48
|
end
|
47
49
|
|
48
50
|
def server_number
|
@@ -53,8 +55,17 @@ module Jekyll
|
|
53
55
|
"avatars#{server_number}.githubusercontent.com"
|
54
56
|
end
|
55
57
|
|
56
|
-
def url
|
57
|
-
"https://#{host}/#{path}"
|
58
|
+
def url(scale = 1)
|
59
|
+
"https://#{host}/#{path(scale)}"
|
60
|
+
end
|
61
|
+
|
62
|
+
def srcset
|
63
|
+
(1..4).map { |scale| "#{url(scale)} #{scale}x" }.join(', ')
|
64
|
+
end
|
65
|
+
|
66
|
+
# See http://primercss.io/avatars/#small-avatars
|
67
|
+
def classes
|
68
|
+
size < 48 ? 'avatar avatar-small' : 'avatar'
|
58
69
|
end
|
59
70
|
end
|
60
71
|
end
|