class Jekyll::Crypticons

Constants

Syntax

Syntax for the crypticon symbol

TagAttributes

Copied from Liquid::TagAttributes to allow dashes in tag names:

{% crypticon alert area-label:"Hello World!" %}
VERSION
Variable

For interpoaltion, look for liquid variables

Public Class Methods

new(tag_name, markup, options) click to toggle source
Calls superclass method
# File lib/jekyll-crypticons.rb, line 23
def initialize(tag_name, markup, options)
  super
  @markup = markup

  # If there's interpoaltion going on, we need to do this in render
  prepare(markup) unless match = markup.match(Variable)
end

Public Instance Methods

render(context) click to toggle source
# File lib/jekyll-crypticons.rb, line 31
def render(context)
  prepare(interpolate(@markup, context)) if match = @markup.match(Variable)

  return nil if @symbol.nil?
  ::Crypticons::Crypticon.new(@symbol, @options).to_svg
end

Private Instance Methods

interpolate(markup, context) click to toggle source
# File lib/jekyll-crypticons.rb, line 40
def interpolate(markup, context)
  markup.scan Variable do |variable|
    markup = markup.gsub(Variable, lookup_variable(context, variable.first))
  end
  markup
end
prepare(markup) click to toggle source
# File lib/jekyll-crypticons.rb, line 47
def prepare(markup)
  @symbol = symbol(markup)
  @options = string_to_hash(markup)
end
string_to_hash(markup) click to toggle source

Create a ruby hash from a string passed by the jekyll tag

# File lib/jekyll-crypticons.rb, line 59
def string_to_hash(markup)
  options = {}

  if match = markup.match(Syntax)
    markup.scan(TagAttributes) do |key, value|
      options[key.to_sym] = value.gsub(/\A"|"\z/, "")
    end
  end

  options
end
symbol(markup) click to toggle source
# File lib/jekyll-crypticons.rb, line 52
def symbol(markup)
  if match = markup.match(Syntax)
    match[1]
  end
end