Support new private gist syntax.
This commit is contained in:
parent
5e9b8d64c6
commit
066912556e
|
@ -6,9 +6,10 @@
|
|||
|
||||
module Jekyll
|
||||
class GistTag < Liquid::Tag
|
||||
|
||||
def render(context)
|
||||
if tag_contents = @markup.strip.match(/\A(\d+) ?(\S*)\Z/)
|
||||
gist_id, filename = tag_contents[1].strip, tag_contents[2].strip
|
||||
if tag_contents = determine_arguments(@markup.strip)
|
||||
gist_id, filename = tag_contents[0], tag_contents[1]
|
||||
gist_script_tag(gist_id, filename)
|
||||
else
|
||||
"Error parsing gist id"
|
||||
|
@ -17,7 +18,16 @@ module Jekyll
|
|||
|
||||
private
|
||||
|
||||
def gist_script_tag(gist_id, filename=nil)
|
||||
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
|
||||
|
||||
def gist_script_tag(gist_id, filename = nil)
|
||||
if filename.empty?
|
||||
"<script src=\"https://gist.github.com/#{gist_id}.js\"> </script>"
|
||||
else
|
||||
|
|
|
@ -253,6 +253,46 @@ CONTENT
|
|||
end
|
||||
end
|
||||
|
||||
context "for private gist" do
|
||||
context "when valid" do
|
||||
setup do
|
||||
@gist = "mattr-/24081a1d93d2898ecf0f"
|
||||
@filename = "myfile.ext"
|
||||
content = <<CONTENT
|
||||
---
|
||||
title: My Cool Gist
|
||||
---
|
||||
|
||||
{% gist #{@gist} #{@filename} %}
|
||||
CONTENT
|
||||
create_post(content, {'permalink' => 'pretty', 'source' => source_dir, 'destination' => dest_dir, 'read_posts' => true})
|
||||
end
|
||||
|
||||
should "write script tag with specific file in gist" do
|
||||
assert_match "<script src='https://gist.github.com/#{@gist}.js?file=#{@filename}'>\s</script>", @result
|
||||
end
|
||||
end
|
||||
|
||||
context "when invalid" do
|
||||
setup do
|
||||
@gist = "mattr-24081a1d93d2898ecf0f"
|
||||
@filename = "myfile.ext"
|
||||
content = <<CONTENT
|
||||
---
|
||||
title: My Cool Gist
|
||||
---
|
||||
|
||||
{% gist #{@gist} #{@filename} %}
|
||||
CONTENT
|
||||
create_post(content, {'permalink' => 'pretty', 'source' => source_dir, 'destination' => dest_dir, 'read_posts' => true})
|
||||
end
|
||||
|
||||
should "write script tag with specific file in gist" do
|
||||
assert_match "Error parsing gist id", @result
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "with specific file" do
|
||||
setup do
|
||||
@gist = 358471
|
||||
|
|
Loading…
Reference in New Issue