From e8c47b7135a1ecf3414c6495b1cb592ae3e2d8a3 Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Thu, 10 Aug 2017 12:37:01 +0200 Subject: Add README example as a test case --- testing/templates/hello.html | 1 + testing/tests/hello.rs | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 testing/templates/hello.html create mode 100644 testing/tests/hello.rs diff --git a/testing/templates/hello.html b/testing/templates/hello.html new file mode 100644 index 0000000..8149be7 --- /dev/null +++ b/testing/templates/hello.html @@ -0,0 +1 @@ +Hello, {{ name }}! diff --git a/testing/tests/hello.rs b/testing/tests/hello.rs new file mode 100644 index 0000000..12ffde6 --- /dev/null +++ b/testing/tests/hello.rs @@ -0,0 +1,18 @@ +#[macro_use] +extern crate askama; + +use askama::Template; + +#[derive(Template)] // this will generate the code... +#[template(path = "hello.html", print = "all")] // using the template in this path, relative + // to the templates dir in the crate root +struct HelloTemplate<'a> { // the name of the struct can be anything + name: &'a str, // the field name should match the variable name + // in your template +} + +#[test] +fn main() { + let hello = HelloTemplate { name: "world" }; // instantiate your struct + assert_eq!("Hello, world!", hello.render().unwrap()); // then render it. +} -- cgit