class Jekyll::GistTag

Public Instance Methods

render(context) click to toggle source
# File lib/jekyll/tags/gist.rb, line 10
    def render(context)
      if tag_contents = determine_arguments(@markup.strip)
        gist_id, filename = tag_contents[0], tag_contents[1]
        gist_script_tag(gist_id, filename)
      else
        raise ArgumentError.new <<-eos
Syntax error in tag 'gist' while parsing the following markup:

  #{@markup}

Valid syntax:
  for public gists:  {% gist 1234567 %}
  for private gists: {% gist user/1234567 %}
eos
      end
    end

Private Instance Methods

determine_arguments(input) click to toggle source
# File lib/jekyll/tags/gist.rb, line 29
def determine_arguments(input)
  matched = if input.include?("/")
    input.match(/\A([a-zA-Z0-9\/\-_]+) ?(\S*)\Z/)
  else
    input.match(/\A(\d+) ?(\S*)\Z/)
  end
  [matched[1].strip, matched[2].strip] if matched && matched.length >= 3
end
gist_script_tag(gist_id, filename = nil) click to toggle source
# File lib/jekyll/tags/gist.rb, line 38
def gist_script_tag(gist_id, filename = nil)
  if filename.empty?
    "<script src=\"https://gist.github.com/#{gist_id}.js\"> </script>"
  else
    "<script src=\"https://gist.github.com/#{gist_id}.js?file=#{filename}\"> </script>"
  end
end