Browse Source

Add test for nested page_template

index-subcmd
Vincent Prouillet 6 years ago
parent
commit
59f3e54e4e
4 changed files with 28 additions and 3 deletions
  1. +12
    -3
      components/site/tests/site.rs
  2. +4
    -0
      test_site/content/applying_page_template/yet_another_section/_index.md
  3. +4
    -0
      test_site/content/applying_page_template/yet_another_section/post.md
  4. +8
    -0
      test_site/templates/page_template_child.html

+ 12
- 3
components/site/tests/site.rs View File

@@ -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()));
}

+ 4
- 0
test_site/content/applying_page_template/yet_another_section/_index.md View File

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

+ 4
- 0
test_site/content/applying_page_template/yet_another_section/post.md View File

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

+ 8
- 0
test_site/templates/page_template_child.html 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 %}

Loading…
Cancel
Save