Documents should be able to render their date (#7404)

Merge pull request 7404
This commit is contained in:
Ashwin Maroli 2018-12-16 11:38:53 +05:30 committed by jekyllbot
parent e41c42720a
commit 1a7b55e6dd
3 changed files with 23 additions and 1 deletions

View File

@ -12,7 +12,7 @@ module Jekyll
mutable false
def_delegator :@obj, :relative_path, :path
def_delegators :@obj, :id, :output, :content, :to_s, :relative_path, :url
def_delegators :@obj, :id, :output, :content, :to_s, :relative_path, :url, :date
private def_delegator :@obj, :data, :fallback_data

View File

@ -7,6 +7,10 @@ module Jekyll
@obj.doc.data["layout"]
end
def date
@obj.doc.date
end
def excerpt
nil
end

View File

@ -67,6 +67,12 @@ class TestDocument < JekyllUnitTest
assert_equal "foo.bar", @document.data["whatever"]
end
should "know its date" do
assert_nil @document.data["date"]
assert_equal Time.now.strftime("%Y/%m/%d"), @document.date.strftime("%Y/%m/%d")
assert_equal Time.now.strftime("%Y/%m/%d"), @document.to_liquid["date"].strftime("%Y/%m/%d")
end
should "be jsonify-able" do
page_json = @document.to_liquid.to_json
parsed = JSON.parse(page_json)
@ -580,6 +586,10 @@ class TestDocument < JekyllUnitTest
should "have the expected date" do
assert_equal "2015/09/30", @document.data["date"].strftime("%Y/%m/%d")
end
should "return the expected date via Liquid" do
assert_equal "2015/09/30", @document.to_liquid["date"].strftime("%Y/%m/%d")
end
end
context "a document with a date with time but without timezone" do
@ -590,6 +600,10 @@ class TestDocument < JekyllUnitTest
should "have the expected date" do
assert_equal "2015/10/01", @document.data["date"].strftime("%Y/%m/%d")
end
should "return the expected date via Liquid" do
assert_equal "2015/10/01", @document.to_liquid["date"].strftime("%Y/%m/%d")
end
end
context "a document with a date without time" do
@ -600,5 +614,9 @@ class TestDocument < JekyllUnitTest
should "have the expected date" do
assert_equal "2015/10/01", @document.data["date"].strftime("%Y/%m/%d")
end
should "return the expected date via Liquid" do
assert_equal "2015/10/01", @document.to_liquid["date"].strftime("%Y/%m/%d")
end
end
end