Class: QR

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

Overview

Main tag definition for Jekyll Liquid

Constant Summary collapse

RQRCODE_OPTIONS =
{
  level: :l
}.freeze
RQRCODE_SVG_OPTIONS =
{
  viewbox: true,
  # offset is rqrcode's default module size of 11px multiplied by
  # the recommended 'quiet area' for a QR code of four modules
  offset: 44,
  use_path: true
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(tag_name, text, tokens) ⇒ QR

Returns a new instance of QR.



24
25
26
27
# File 'lib/jekyll-qr.rb', line 24

def initialize(tag_name, text, tokens)
  super
  @text = text
end

Instance Method Details

#render(_) ⇒ Object



29
30
31
32
33
# File 'lib/jekyll-qr.rb', line 29

def render(_)
  qr = RQRCode::QRCode.new(@text.strip, **RQRCODE_OPTIONS)
  qr_svg = ERB::Util.url_encode(qr.as_svg(**RQRCODE_SVG_OPTIONS).to_s)
  "<img class=\"qr-code\" src=\"data:image/svg+xml;utf8,#{qr_svg}\">"
end