aboutsummaryrefslogtreecommitdiffstats
path: root/testing
diff options
context:
space:
mode:
authorLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2017-08-10 12:37:01 +0200
committerLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2017-08-10 12:37:01 +0200
commite8c47b7135a1ecf3414c6495b1cb592ae3e2d8a3 (patch)
tree1a8a08968d7f169e145a4767726177f7322b5ed8 /testing
parentadfc52a26d3da8f62fad81eb1b12ffc7202583e7 (diff)
downloadaskama-e8c47b7135a1ecf3414c6495b1cb592ae3e2d8a3.tar.gz
askama-e8c47b7135a1ecf3414c6495b1cb592ae3e2d8a3.tar.bz2
askama-e8c47b7135a1ecf3414c6495b1cb592ae3e2d8a3.zip
Add README example as a test case
Diffstat (limited to 'testing')
-rw-r--r--testing/templates/hello.html1
-rw-r--r--testing/tests/hello.rs18
2 files changed, 19 insertions, 0 deletions
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.
+}