diff --git a/lib/jekyll/tags/gist.rb b/lib/jekyll/tags/gist.rb
index 0d981af1..d69499af 100644
--- a/lib/jekyll/tags/gist.rb
+++ b/lib/jekyll/tags/gist.rb
@@ -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?
""
else
diff --git a/test/test_tags.rb b/test/test_tags.rb
index da5a62f3..fd2df409 100644
--- a/test/test_tags.rb
+++ b/test/test_tags.rb
@@ -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 = < 'pretty', 'source' => source_dir, 'destination' => dest_dir, 'read_posts' => true})
+ end
+
+ should "write script tag with specific file in gist" do
+ assert_match "", @result
+ end
+ end
+
+ context "when invalid" do
+ setup do
+ @gist = "mattr-24081a1d93d2898ecf0f"
+ @filename = "myfile.ext"
+ content = < '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