Add PageDrop to provide Liquid templates with data (#7992)

Merge pull request 7992
This commit is contained in:
Ashwin Maroli
2020-03-26 19:09:47 +05:30
committed by GitHub
parent a011579fe4
commit b84ba5accc
5 changed files with 123 additions and 0 deletions

View File

@@ -50,6 +50,42 @@ class TestPage < JekyllUnitTest
assert_equal "/+/%25%23%20+.html", @page.url
end
should "be exposed to Liquid as a Liquid::Drop subclass" do
page = setup_page("properties.html")
liquid_rep = page.to_liquid
refute_equal Hash, liquid_rep.class
assert_equal true, liquid_rep.is_a?(Liquid::Drop)
assert_equal Jekyll::Drops::PageDrop, liquid_rep.class
end
should "make attributes accessible for use in Liquid templates" do
page = setup_page("/contacts", "index.html")
template = Liquid::Template.parse(<<~TEXT)
Name: {{ page.name }}
Path: {{ page.path }}
URL: {{ page.url }}
TEXT
expected = <<~TEXT
Name: index.html
Path: contacts/index.html
URL: /contacts/
TEXT
assert_equal(expected, template.render!("page" => page.to_liquid))
end
should "make front matter data accessible for use in Liquid templates" do
page = setup_page("properties.html")
template = Liquid::Template.parse(<<~TEXT)
TITLE: {{ page.title }}
FOO: {{ page.foo }}
TEXT
expected = <<~TEXT
TITLE: Properties Page
FOO: bar
TEXT
assert_equal expected, template.render!("page" => page.to_liquid)
end
context "in a directory hierarchy" do
should "create URL based on filename" do
@page = setup_page("/contacts", "bar.html")

View File

@@ -76,6 +76,12 @@ class TestPageWithoutAFile < JekyllUnitTest
end
end
end
should "be exposed to Liquid as a Hash" do
liquid_rep = @page.to_liquid
refute_equal Jekyll::Drops::PageDrop, liquid_rep.class
assert_equal Hash, liquid_rep.class
end
end
context "with site-wide permalink configuration" do