diff options
Diffstat (limited to 'askama_iron')
-rw-r--r-- | askama_iron/Cargo.toml | 17 | ||||
-rw-r--r-- | askama_iron/src/lib.rs | 3 | ||||
-rw-r--r-- | askama_iron/templates/hello.html | 1 | ||||
-rw-r--r-- | askama_iron/templates/hello.txt | 1 | ||||
-rw-r--r-- | askama_iron/tests/basic.rs | 36 |
5 files changed, 58 insertions, 0 deletions
diff --git a/askama_iron/Cargo.toml b/askama_iron/Cargo.toml new file mode 100644 index 0000000..35c585d --- /dev/null +++ b/askama_iron/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "askama_iron" +version = "0.9.0" +authors = ["Dirkjan Ochtman <dirkjan@ochtman.nl>"] +description = "Iron integration for Askama templates" +documentation = "https://docs.rs/askama" +keywords = ["markup", "template", "jinja2", "html"] +categories = ["template-engine"] +homepage = "https://github.com/djc/askama" +repository = "https://github.com/djc/askama" +license = "MIT OR Apache-2.0" +workspace = ".." +edition = "2018" + +[dependencies] +askama = { version = "0.9.0", path = "../askama", features = ["with-iron"] } +iron = { version = ">= 0.5, < 0.7" } diff --git a/askama_iron/src/lib.rs b/askama_iron/src/lib.rs new file mode 100644 index 0000000..37e79cc --- /dev/null +++ b/askama_iron/src/lib.rs @@ -0,0 +1,3 @@ +pub use askama::*; + +pub use iron::{headers::ContentType, modifier::Modifier, Response}; diff --git a/askama_iron/templates/hello.html b/askama_iron/templates/hello.html new file mode 100644 index 0000000..8149be7 --- /dev/null +++ b/askama_iron/templates/hello.html @@ -0,0 +1 @@ +Hello, {{ name }}! diff --git a/askama_iron/templates/hello.txt b/askama_iron/templates/hello.txt new file mode 100644 index 0000000..8149be7 --- /dev/null +++ b/askama_iron/templates/hello.txt @@ -0,0 +1 @@ +Hello, {{ name }}! diff --git a/askama_iron/tests/basic.rs b/askama_iron/tests/basic.rs new file mode 100644 index 0000000..32ca839 --- /dev/null +++ b/askama_iron/tests/basic.rs @@ -0,0 +1,36 @@ +use askama::Template; +use iron::{status, Response}; + +#[derive(Template)] +#[template(path = "hello.html")] +struct HelloTemplate<'a> { + name: &'a str, +} + +#[derive(Template)] +#[template(path = "hello.txt")] +struct HelloTextTemplate<'a> { + name: &'a str, +} + +#[test] +fn test_iron() { + let rsp = Response::with((status::Ok, HelloTemplate { name: "world" })); + let mut buf = Vec::new(); + let _ = rsp.body.unwrap().write_body(&mut buf); + assert_eq!(buf, b"Hello, world!"); + + let content_type = rsp.headers.get::<iron::headers::ContentType>().unwrap(); + assert_eq!(format!("{}", content_type), "text/html; charset=utf-8"); +} + +#[test] +fn test_iron_non_html() { + let rsp = Response::with((status::Ok, HelloTextTemplate { name: "world" })); + let mut buf = Vec::new(); + let _ = rsp.body.unwrap().write_body(&mut buf); + assert_eq!(buf, b"Hello, world!"); + + let content_type = rsp.headers.get::<iron::headers::ContentType>(); + assert_eq!(content_type, None); +} |