Sha256: 568732a581160e0f7f127557332233014b2b054d11898a97f3b8348d3ed287cc
Contents?: true
Size: 1.17 KB
Versions: 1
Compression:
Stored size: 1.17 KB
Contents
require 'jekyll/avatar/version' module Jekyll class Avatar < Liquid::Tag SERVERS = 4 DEFAULT_SIZE = 40 VERSION = 3 def initialize(tag_name, text, tokens) super @text = text end def render(_context) tag = '<img ' # See http://primercss.io/avatars/#small-avatars if size < 48 tag << 'class="avatar avatar-small" ' else tag << 'class="avatar" ' end tag << "src=\"#{url}\" alt=\"#{username}\" " tag << "width=\"#{size}\" height=\"#{size}\" " tag << '/>' tag end private def username @username ||= @text.split(' ').first.sub('@', '') end def size @size ||= begin matches = @text.match(/\bsize=(\d+)\b/i) matches ? matches[1].to_i : DEFAULT_SIZE end end def path @path ||= "#{username}?v=#{VERSION}&s=#{size}" end def server_number @server_number ||= Zlib.crc32(path) % SERVERS end def host @host ||= "avatars#{server_number}.githubusercontent.com" end def url @url ||= "https://#{host}/#{path}" end end end Liquid::Template.register_tag('avatar', Jekyll::Avatar)
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
jekyll-avatar-0.1.0 | lib/jekyll/avatar.rb |