display single files from gist

This commit is contained in:
Daniel Grieve
2013-03-15 22:37:14 +00:00
parent f8a90d711f
commit 92d9c4301b
3 changed files with 83 additions and 16 deletions

View File

@@ -2,16 +2,27 @@
#
# Example:
# {% gist 1234567 %}
# {% gist 1234567 file.rb %}
module Jekyll
class GistTag < Liquid::Tag
def initialize(tag_name, gist, tokens)
super
@gist = gist.strip
def render(context)
if tag_contents = @markup.match(/(\d+) (.*)/)
gist_id, filename = tag_contents[1].strip, tag_contents[2].strip
gist_script_tag(gist_id, filename)
else
"Error parsing gist id"
end
end
def render(context)
"<script src=\"https://gist.github.com/#{@gist}.js\"> </script>"
private
def gist_script_tag(gist_id, filename=nil)
if filename.empty?
"<script src=\"https://gist.github.com/#{gist_id}.js\">\s</script>"
else
"<script src=\"https://gist.github.com/#{gist_id}.js?file=#{filename}\">\s</script>"
end
end
end
end