Class: Jekyll::ShieldsIO::ShieldsIOTag

Inherits:
Liquid::Tag
  • Object
show all
Defined in:
lib/jekyll-shields_io.rb

Overview

Jekyll Liquid Tag for Shields.io

Usage: shields_io <query param + special param as json> %

Instance Method Summary collapse

Constructor Details

#initialize(tag_name, input, parse_context) ⇒ ShieldsIOTag



189
190
191
192
193
194
195
196
# File 'lib/jekyll-shields_io.rb', line 189

def initialize(tag_name, input, parse_context)
  super
  # @type [Hash]
  @payload = JSON.parse(input.strip, {symbolize_names: true})
  # This only appears if there is an error trying to fetch the shield.
  # @type [String]
  @last_ditch_alt = "<p>#{@payload[:label]} #{@payload[:message]}</p>"
end

Instance Method Details

#render(context) ⇒ Object



198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
# File 'lib/jekyll-shields_io.rb', line 198

def render(context)
  fct = ShieldFactory.new context
  shield = fct.get_shield @payload
  fct.queue_shield shield

  shield_tag = "<img src=\"/\#{fct.target_dir}/\#{shield.basename}\" width=\"\#{shield.width}\" height=\"\#{shield.height}\"\n"
  shield_tag += if !shield.alt.nil?
    " alt=\"#{shield.alt}\" class=\"#{shield.cls}\"/>"
  else
    " class=\"#{shield.cls}\"/>"
  end
  if !shield.href.nil?
    "      <a href=\"\#{shield.href}\" class=\"\#{shield.cls}\">\n      \#{shield_tag}\n      </a>\n    HTML\n  else\n    shield_tag\n  end\nrescue ShieldFetchError\n  warn \"[Shields.IO Plugin] Failed to fetch shields! (input: \#{JSON.dump @payload})\"\n  @last_ditch_alt\nrescue ShieldFileError\n  warn \"[Shields.IO Plugin] Failed to access cached shields!\"\n  @last_ditch_alt\nend\n"