From 59f3e54e4e6c47ebe29c64ca7ffb8c106651e06f Mon Sep 17 00:00:00 2001 From: Vincent Prouillet Date: Wed, 7 Nov 2018 20:48:39 +0100 Subject: [PATCH] Add test for nested page_template --- components/site/tests/site.rs | 15 ++++++++++++--- .../yet_another_section/_index.md | 4 ++++ .../yet_another_section/post.md | 4 ++++ test_site/templates/page_template_child.html | 8 ++++++++ 4 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 test_site/content/applying_page_template/yet_another_section/_index.md create mode 100644 test_site/content/applying_page_template/yet_another_section/post.md create mode 100644 test_site/templates/page_template_child.html diff --git a/components/site/tests/site.rs b/components/site/tests/site.rs index bd038689..717e83ee 100644 --- a/components/site/tests/site.rs +++ b/components/site/tests/site.rs @@ -18,7 +18,7 @@ fn can_parse_site() { site.load().unwrap(); // Correct number of pages (sections do not count as pages) - assert_eq!(site.library.pages().len(), 20); + assert_eq!(site.library.pages().len(), 21); let posts_path = path.join("content").join("posts"); // Make sure the page with a url doesn't have any sections @@ -31,7 +31,7 @@ fn can_parse_site() { assert_eq!(asset_folder_post.file.components, vec!["posts".to_string()]); // That we have the right number of sections - assert_eq!(site.library.sections().len(), 10); + assert_eq!(site.library.sections().len(), 11); // And that the sections are correct let index_section = site.library.get_section(&path.join("content").join("_index.md")).unwrap(); @@ -572,7 +572,7 @@ fn can_apply_page_templates() { let template_path = path.join("content").join("applying_page_template"); let template_section = site.library.get_section(&template_path.join("_index.md")).unwrap(); - assert_eq!(template_section.subsections.len(), 1); + assert_eq!(template_section.subsections.len(), 2); assert_eq!(template_section.pages.len(), 2); let from_section_config = site.library.get_page_by_key(template_section.pages[0]); @@ -591,4 +591,13 @@ fn can_apply_page_templates() { let changed_recursively = site.library.get_page_by_key(another_section.pages[0]); assert_eq!(changed_recursively.meta.template, Some("page_template.html".into())); assert_eq!(changed_recursively.meta.title, Some("Changed recursively".into())); + + // But it should not have override a children page_template + let yet_another_section = site.library.get_section(&template_path.join("yet_another_section").join("_index.md")).unwrap(); + assert_eq!(yet_another_section.subsections.len(), 0); + assert_eq!(yet_another_section.pages.len(), 1); + + let child = site.library.get_page_by_key(yet_another_section.pages[0]); + assert_eq!(child.meta.template, Some("page_template_child.html".into())); + assert_eq!(child.meta.title, Some("Local section override".into())); } diff --git a/test_site/content/applying_page_template/yet_another_section/_index.md b/test_site/content/applying_page_template/yet_another_section/_index.md new file mode 100644 index 00000000..6ead9c27 --- /dev/null +++ b/test_site/content/applying_page_template/yet_another_section/_index.md @@ -0,0 +1,4 @@ ++++ +page_template = "page_template_child.html" +sort_by = "weight" ++++ diff --git a/test_site/content/applying_page_template/yet_another_section/post.md b/test_site/content/applying_page_template/yet_another_section/post.md new file mode 100644 index 00000000..dcd943d1 --- /dev/null +++ b/test_site/content/applying_page_template/yet_another_section/post.md @@ -0,0 +1,4 @@ ++++ +title = "Local section override" +weight = 0 ++++ diff --git a/test_site/templates/page_template_child.html b/test_site/templates/page_template_child.html new file mode 100644 index 00000000..73d28620 --- /dev/null +++ b/test_site/templates/page_template_child.html @@ -0,0 +1,8 @@ +{% extends "index.html" %} +{% block content %} +

Another page template, specified with the "page_template" key in the front matter but from a child + of a section with also a "page_template" key

+ {{ page.content | safe }} + {% if page.earlier %}Previous article: {{ page.earlier.permalink }}{% endif %} + {% if page.later %}Next article: {{ page.later.permalink }}{% endif %} +{% endblock content %}