class Jekyll::JekyllGithubChart::JekyllGithubChartTag

Public Class Methods

new(tag_name, text, tokens) click to toggle source
Calls superclass method
# File lib/jekyll-github-chart.rb, line 8
def initialize(tag_name, text, tokens)
  super
  opts    = text.split(' ').map(&:strip)
  @user   = opts[0]
  @scheme = opts[1] || 'default' # old, halloween
  @format = opts[2] || 'image'   # raw
end

Public Instance Methods

render(context) click to toggle source
# File lib/jekyll-github-chart.rb, line 16
def render(context)
  raw_svg = GithubChart.new({ user: @user, colors: @scheme.to_sym }).render(:svg)

  return raw_svg if @format == 'raw'

  content_type = 'image/svg+xml'
  encoding = 'charset=utf-8'
  data = CGI::escape(raw_svg).gsub('+', '%20')

  "<img src='data:#{content_type};#{encoding},#{data}' class='github-contributions' alt='#{@user} Github contributions' />"
end