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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fd6722f0db882080e3c2d38e5e95f848384848f0
4
- data.tar.gz: a762d7ae9a0f53b14fbb36f886e69e17829173e5
3
+ metadata.gz: 475ee02bafe22805fe38b7f4900f84083ad8d0d8
4
+ data.tar.gz: 1122411192e47273a9116a31eb61a4fb6a39fd80
5
5
  SHA512:
6
- metadata.gz: b84a46915b0c5a3cd42ad447b1de5a240eb0ad545958273f80b6da373ed4a35d3d703e64cc835a2104df34d00861d99970515dc11c46cedd3b5d2e292b039584
7
- data.tar.gz: f8fad54f4877b61c05ea774ae52c3cec71eaab7b9c390b985cf3d602d6488a80eb69aaa7f7300c66f13401bd008f0497b93c865b6eb84bf330bba1044ffa5f3f
6
+ metadata.gz: e38e2f39d7cb8bbe76f942ff08ca6dcd801f86734c3095e654f031536f28324e9bd75ad5639d9acb1ca77a93a51de6be1ff0ff6142d3fa963d58cb38e160fc65
7
+ data.tar.gz: b815e3a0c0164a0e59832ddde441c5bb1b6830b3bcc3ee8007e4047c05a9cf1aa1cc1f4d009f902770ffe2dd4c8ba4e786c54d8b5bfcc12a65ad82e2c28386de
@@ -11,3 +11,10 @@ Lint/EndAlignment:
11
11
 
12
12
  Style/FileName:
13
13
  Enabled: false
14
+
15
+ Metrics/LineLength:
16
+ Exclude:
17
+ - spec/*/**
18
+
19
+ Style/DeprecatedHashMethods:
20
+ Enabled: false
@@ -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
- tag = '<img '
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
@@ -1,6 +1,6 @@
1
1
  module Liquid; class Tag; end; end
2
2
  module Jekyll
3
3
  class Avatar < Liquid::Tag
4
- VERSION = '0.2.3'.freeze
4
+ VERSION = '0.3.0'.freeze
5
5
  end
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-avatar
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Balter