Class: Bunto::Gist::GistTag

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

Instance Method Summary collapse

Instance Method Details

#render(context) ⇒ Object



12
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
# File 'lib/bunto-gist/gist_tag.rb', line 12

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, filename = tag_contents[0], tag_contents[1]
    if context.has_key?(gist_id)
      gist_id = context[gist_id]
    end
    if context.has_key?(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.new "  Syntax error in tag 'gist' while parsing the following markup:\n\n    \#{@markup}\n\n  Valid syntax:\n    {% gist user/1234567 %}\n    {% gist user/1234567 foo.js %}\n    {% gist 28949e1d5ee2273f9fd3 %}\n    {% gist 28949e1d5ee2273f9fd3 best.md %}\n  eos\n  end\nend\n"