diff --git a/lib/jekyll/excerpt.rb b/lib/jekyll/excerpt.rb index bac91ede..2dfbe958 100644 --- a/lib/jekyll/excerpt.rb +++ b/lib/jekyll/excerpt.rb @@ -8,7 +8,7 @@ module Jekyll attr_accessor :content, :ext attr_writer :output - def_delegators :@doc, :site, :name, :ext, :relative_path, :extname, + def_delegators :@doc, :site, :name, :ext, :extname, :render_with_liquid?, :collection, :related_posts, :url, :next_doc, :previous_doc @@ -41,6 +41,13 @@ module Jekyll File.join(doc.path, "#excerpt") end + # 'Relative Path' of the excerpt. + # + # Returns the relative_path for the doc this excerpt belongs to with #excerpt appended + def relative_path + File.join(doc.relative_path, "#excerpt") + end + # Check if excerpt includes a string # # Returns true if the string passed in diff --git a/test/test_excerpt.rb b/test/test_excerpt.rb index 96cd60cf..c4b4538d 100644 --- a/test/test_excerpt.rb +++ b/test/test_excerpt.rb @@ -78,6 +78,15 @@ class TestExcerpt < JekyllUnitTest end end + context "#relative_path" do + should "return its document's relative path with '/#excerpt' appended" do + assert_equal "#{@excerpt.doc.relative_path}/#excerpt", + @excerpt.relative_path + assert_equal "_posts/2013-07-22-post-excerpt-with-layout.markdown/#excerpt", + @excerpt.relative_path + end + end + context "#to_liquid" do should "contain the proper page data to mimic the post liquid" do assert_equal "Post Excerpt with Layout", @excerpt.to_liquid["title"] @@ -86,7 +95,7 @@ class TestExcerpt < JekyllUnitTest assert_equal Time.parse("2013-07-22"), @excerpt.to_liquid["date"] assert_equal %w(bar baz z_category MixedCase), @excerpt.to_liquid["categories"] assert_equal %w(first second third jekyllrb.com), @excerpt.to_liquid["tags"] - assert_equal "_posts/2013-07-22-post-excerpt-with-layout.markdown", + assert_equal "_posts/2013-07-22-post-excerpt-with-layout.markdown/#excerpt", @excerpt.to_liquid["path"] end end