Module: Jekyll::GeoPatterns

Defined in:
lib/jekyll-geo-pattern.rb

Defined Under Namespace

Classes: Base64GeoPattern, SVGGeoPattern, UriImageGeoPattern

Constant Summary collapse

VALID_KEYS =
%w(:base_color :color :generator :text)
VALID_SYNTAX =
/([\w-]+)\s*=\s*(?:"([^"\\]*(?:\\.[^"\\]*)*)"|'([^'\\]*(?:\\.[^'\\]*)*)'|([\w\.-]+))/

Class Method Summary collapse

Class Method Details

.extract_options(input, context) ⇒ Object

from a string of options, construct a hash, without using ‘eval`



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/jekyll-geo-pattern.rb', line 9

def self.extract_options( input, context )
  opts = {}
  markup = input

  while match = VALID_SYNTAX.match(markup) do
    markup = markup[match.end(0)..-1]

    value = if match[2]
      match[2].gsub(/\\"/, '"')
    elsif match[3]
      match[3].gsub(/\\'/, "'")
    elsif match[4]
      context[match[4]]
    end

    opts[match[1].to_sym] = value
  end
  GeoPatterns.scrub_options(opts, context)
end

.look_up(context, name) ⇒ Object

set it up such that variables, like ‘post.title`, are still processed



44
45
46
47
48
49
50
51
52
# File 'lib/jekyll-geo-pattern.rb', line 44

def self.look_up(context, name)
  lookup = context

  name.split(".").each do |value|
    lookup = lookup[value]
  end

  lookup
end

.scrub_options(opts, context) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/jekyll-geo-pattern.rb', line 29

def self.scrub_options(opts, context)
  opts.each do |opt, value|
    next if value.nil? # ignore properties that have no corresponding value

    value.gsub! /"|'/, ""

    if value =~ /^(\w+?(\.[\w]+)*)/i
      context_val = GeoPatterns.look_up(context, $1)
      opts[opt] = context_val unless context_val.nil?
    end
  end
  opts
end