blob: f33441da9b3c866df13b5fba195d915f6141ae1e (
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
|
#[macro_use]
extern crate askama;
use askama::Template;
#[derive(Template)]
#[template(source = "{{ self.get_s() }}", ext = "txt")]
struct MethodTemplate<'a> {
s: &'a str,
}
impl<'a> MethodTemplate<'a> {
fn get_s(&self) -> &str {
self.s
}
}
#[derive(Template)]
#[template(source = "{{ self.get_s() }} {{ t.get_s() }}", ext = "txt")]
struct NestedMethodTemplate<'a> {
t: MethodTemplate<'a>,
}
impl<'a> NestedMethodTemplate<'a> {
fn get_s(&self) -> &str {
"bar"
}
}
#[test]
fn test_method() {
let t = MethodTemplate { s: "foo" };
assert_eq!(t.render().unwrap(), "foo");
}
#[test]
fn test_nested() {
let t = NestedMethodTemplate {
t: MethodTemplate { s: "foo" },
};
assert_eq!(t.render().unwrap(), "bar foo");
}
|