mirror of
https://github.com/askama-rs/askama.git
synced 2025-10-02 15:25:19 +00:00
Add test for deep inheritance
This commit is contained in:
parent
21edd48917
commit
3d75bcfe78
14
testing/templates/deep-base.html
Normal file
14
testing/templates/deep-base.html
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
{% import "macro.html" as libb %}
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
{% block head %}
|
||||||
|
<style></style>
|
||||||
|
{% endblock %}
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
{% block body %}
|
||||||
|
{% call libb::thrice("nav") %}
|
||||||
|
Copyright {{ year }}
|
||||||
|
{% endblock %}
|
||||||
|
</body>
|
||||||
|
</html>
|
10
testing/templates/deep-kid.html
Normal file
10
testing/templates/deep-kid.html
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
{% extends "deep-mid.html" %}
|
||||||
|
{% import "macro.html" as libk %}
|
||||||
|
|
||||||
|
{% block head %}
|
||||||
|
<script></script>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
{% call libk::thrice(item) %}
|
||||||
|
{% endblock %}
|
19
testing/templates/deep-mid.html
Normal file
19
testing/templates/deep-mid.html
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
{% extends "deep-base.html" %}
|
||||||
|
{% import "macro.html" as libm %}
|
||||||
|
|
||||||
|
{% block head %}
|
||||||
|
{{ title }}
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block body %}
|
||||||
|
<div id="wrap">
|
||||||
|
<section id="content">
|
||||||
|
{% block content %}
|
||||||
|
No content found
|
||||||
|
{% endblock %}
|
||||||
|
</section>
|
||||||
|
<section id="nav">
|
||||||
|
{% call libm::thrice("nav") %}
|
||||||
|
</section>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
@ -79,3 +79,95 @@ fn test_nested_blocks() {
|
|||||||
};
|
};
|
||||||
assert_eq!(t.render().unwrap(), "\ndurpy\n");
|
assert_eq!(t.render().unwrap(), "\ndurpy\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Template)]
|
||||||
|
#[template(path = "deep-base.html")]
|
||||||
|
struct DeepBaseTemplate {
|
||||||
|
year: u16,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Template)]
|
||||||
|
#[template(path = "deep-mid.html")]
|
||||||
|
struct DeepMidTemplate {
|
||||||
|
_parent: DeepBaseTemplate,
|
||||||
|
title: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Template)]
|
||||||
|
#[template(path = "deep-kid.html")]
|
||||||
|
struct DeepKidTemplate {
|
||||||
|
_parent: DeepMidTemplate,
|
||||||
|
item: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_deep() {
|
||||||
|
let t = DeepKidTemplate {
|
||||||
|
_parent: DeepMidTemplate {
|
||||||
|
_parent: DeepBaseTemplate {
|
||||||
|
year: 2018,
|
||||||
|
},
|
||||||
|
title: "Test".into(),
|
||||||
|
},
|
||||||
|
item: "Foo".into(),
|
||||||
|
};
|
||||||
|
|
||||||
|
assert_eq!(t.render().unwrap(), "
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
|
||||||
|
<script></script>
|
||||||
|
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<div id=\"wrap\">
|
||||||
|
<section id=\"content\">
|
||||||
|
|
||||||
|
Foo Foo Foo
|
||||||
|
|
||||||
|
</section>
|
||||||
|
<section id=\"nav\">
|
||||||
|
nav nav nav
|
||||||
|
</section>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>");
|
||||||
|
assert_eq!(t._parent.render().unwrap(), "
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
|
||||||
|
Test
|
||||||
|
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<div id=\"wrap\">
|
||||||
|
<section id=\"content\">
|
||||||
|
|
||||||
|
No content found
|
||||||
|
|
||||||
|
</section>
|
||||||
|
<section id=\"nav\">
|
||||||
|
nav nav nav
|
||||||
|
</section>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>");
|
||||||
|
assert_eq!(t._parent._parent.render().unwrap(), "
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
|
||||||
|
<style></style>
|
||||||
|
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
nav nav nav
|
||||||
|
Copyright 2018
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>");
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user