diff --git a/lib/jekyll/tags/gist.rb b/lib/jekyll/tags/gist.rb
index d3eb0b37cfd..0d981af11a3 100644
--- a/lib/jekyll/tags/gist.rb
+++ b/lib/jekyll/tags/gist.rb
@@ -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.strip.match(/\A(\d+) ?(\S*)\Z/)
+ 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)
- ""
+ private
+
+ def gist_script_tag(gist_id, filename=nil)
+ if filename.empty?
+ ""
+ else
+ ""
+ end
end
end
end
diff --git a/test/test_tags.rb b/test/test_tags.rb
index caefb9ac823..f7916fc5111 100644
--- a/test/test_tags.rb
+++ b/test/test_tags.rb
@@ -170,7 +170,7 @@ def fill_post(code, override = {})
assert_match %r{FINISH HIM}, @result
end
end
-
+
context "using Redcarpet" do
setup do
create_post(@content, 'markdown' => 'redcarpet')
@@ -203,22 +203,78 @@ def fill_post(code, override = {})
assert_match %r{/2008/11/21/complex/}, @result
end
end
-
- context "simple gist inclusion" do
- setup do
- @gist = 358471
- content = < 'pretty', 'source' => source_dir, 'destination' => dest_dir, 'read_posts' => true})
+ create_post(content, {'permalink' => 'pretty', 'source' => source_dir, 'destination' => dest_dir, 'read_posts' => true})
+ end
+
+ should "write script tag" do
+ assert_match "", @result
+ end
end
-
- should "write script tag" do
- assert_match %r{}, @result
+
+ context "with specific file" do
+ setup do
+ @gist = 358471
+ @filename = 'somefile.rb'
+ 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 "with blank gist id" do
+ setup do
+ content = < 'pretty', 'source' => source_dir, 'destination' => dest_dir, 'read_posts' => true})
+ end
+
+ should "output error message" do
+ assert_match "Error parsing gist id", @result
+ end
+ end
+
+ context "with invalid gist id" do
+ setup do
+ invalid_gist = 'invalid'
+ content = < 'pretty', 'source' => source_dir, 'destination' => dest_dir, 'read_posts' => true})
+ end
+
+ should "output error message" do
+ assert_match "Error parsing gist id", @result
+ end
end
end
end