blob: a36f63438c055d233104fef18d0f1f95dd34f9c3 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
#[macro_use]
extern crate askama;
use askama::Template;
#[derive(Template)]
#[template(path = "base.html")]
struct BaseTemplate<'a> {
title: &'a str,
}
#[derive(Template)]
#[template(path = "child.html")]
struct ChildTemplate<'a> {
_parent: BaseTemplate<'a>,
}
#[test]
fn test_use_base_directly() {
let t = BaseTemplate { title: "Foo" };
assert_eq!(t.render().unwrap(), "Foo\n\nFoo\nCopyright 2017");
}
#[test]
fn test_simple_extends() {
let t = ChildTemplate { _parent: BaseTemplate { title: "Bar" } };
assert_eq!(
t.render().unwrap(),
"Bar\n(Bar) Content goes here\nFoo\nCopyright 2017"
);
}
pub mod parent {
use askama::Template;
#[derive(Template)]
#[template(path = "base.html")]
pub struct BaseTemplate<'a> {
pub title: &'a str,
}
}
pub mod child {
use askama::Template;
use super::parent::*;
#[derive(Template)]
#[template(path = "child.html")]
pub struct ChildTemplate<'a> {
pub _parent: BaseTemplate<'a>,
}
}
#[test]
fn test_different_module() {
let t = child::ChildTemplate { _parent: parent::BaseTemplate { title: "a" } };
assert_eq!(
t.render().unwrap(),
"a\n(a) Content goes here\nFoo\nCopyright 2017"
);
}
|