mirror of
https://github.com/jekyll/jekyll.git
synced 2026-04-28 03:01:03 -04:00
display single files from gist
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user