Class: Jekyll::Gist::GistTag

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

Instance Method Summary collapse

Instance Method Details

#render(context) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/jekyll-gist/gist_tag.rb', line 13

def render(context)
  @encoding = context.registers[:site].config["encoding"] || "utf-8"
  @settings = context.registers[:site].config["gist"]
  if (tag_contents = determine_arguments(@markup.strip))
    gist_id = tag_contents[0]
    filename = tag_contents[1]
    if context_contains_key?(context, gist_id)
      gist_id = context[gist_id]
    end
    if context_contains_key?(context, filename)
      filename = context[filename]
    end
    noscript_tag = gist_noscript_tag(gist_id, filename)
    script_tag = gist_script_tag(gist_id, filename)
    "#{noscript_tag}#{script_tag}"
  else
    raise ArgumentError, <<-EOS
  Syntax error in tag 'gist' while parsing the following markup:

    #{@markup}

  Valid syntax:
    {% gist user/1234567 %}
    {% gist user/1234567 foo.js %}
    {% gist 28949e1d5ee2273f9fd3 %}
    {% gist 28949e1d5ee2273f9fd3 best.md %}
  EOS
  end
end