Add test for nested page_template

This commit is contained in:
Vincent Prouillet 2018-11-07 20:48:39 +01:00
parent 2d324b3cee
commit 59f3e54e4e
4 changed files with 28 additions and 3 deletions

View file

@ -18,7 +18,7 @@ fn can_parse_site() {
site.load().unwrap(); site.load().unwrap();
// Correct number of pages (sections do not count as pages) // 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"); let posts_path = path.join("content").join("posts");
// Make sure the page with a url doesn't have any sections // 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()]); assert_eq!(asset_folder_post.file.components, vec!["posts".to_string()]);
// That we have the right number of sections // 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 // And that the sections are correct
let index_section = site.library.get_section(&path.join("content").join("_index.md")).unwrap(); 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_path = path.join("content").join("applying_page_template");
let template_section = site.library.get_section(&template_path.join("_index.md")).unwrap(); 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); assert_eq!(template_section.pages.len(), 2);
let from_section_config = site.library.get_page_by_key(template_section.pages[0]); 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]); 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.template, Some("page_template.html".into()));
assert_eq!(changed_recursively.meta.title, Some("Changed recursively".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()));
} }

View file

@ -0,0 +1,4 @@
+++
page_template = "page_template_child.html"
sort_by = "weight"
+++

View file

@ -0,0 +1,4 @@
+++
title = "Local section override"
weight = 0
+++

View file

@ -0,0 +1,8 @@
{% extends "index.html" %}
{% block content %}
<h1>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</h1>
{{ page.content | safe }}
{% if page.earlier %}Previous article: {{ page.earlier.permalink }}{% endif %}
{% if page.later %}Next article: {{ page.later.permalink }}{% endif %}
{% endblock content %}