diff options
author | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2020-01-28 22:17:22 +0100 |
---|---|---|
committer | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2020-01-29 09:25:59 +0100 |
commit | 75f32d3967e4d13b86b0d720ebc808c6fd9caa05 (patch) | |
tree | b919cd2796220c74b1d6fd69b363c53505681f3a /askama_gotham | |
parent | c6f9a053c7328e6c782508114bd96aa569b5de7d (diff) | |
download | askama-75f32d3967e4d13b86b0d720ebc808c6fd9caa05.tar.gz askama-75f32d3967e4d13b86b0d720ebc808c6fd9caa05.tar.bz2 askama-75f32d3967e4d13b86b0d720ebc808c6fd9caa05.zip |
Move Gotham integration into separate askama_gotham crate
Diffstat (limited to '')
-rw-r--r-- | askama_gotham/Cargo.toml | 21 | ||||
-rw-r--r-- | askama_gotham/src/lib.rs | 22 | ||||
-rw-r--r-- | askama_gotham/templates/hello.html | 1 | ||||
-rw-r--r-- | askama_gotham/tests/basic.rs (renamed from testing/tests/gotham.rs) | 2 |
4 files changed, 44 insertions, 2 deletions
diff --git a/askama_gotham/Cargo.toml b/askama_gotham/Cargo.toml new file mode 100644 index 0000000..efd872d --- /dev/null +++ b/askama_gotham/Cargo.toml @@ -0,0 +1,21 @@ +[package] +name = "askama_gotham" +version = "0.9.0" +authors = ["Dirkjan Ochtman <dirkjan@ochtman.nl>"] +description = "Gotham 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-gotham", "mime", "mime_guess"] } +gotham = { version = "0.3", default-features = false } +hyper = "0.12" + +[dev-dependencies] +mime = "0.3" diff --git a/askama_gotham/src/lib.rs b/askama_gotham/src/lib.rs new file mode 100644 index 0000000..c929a40 --- /dev/null +++ b/askama_gotham/src/lib.rs @@ -0,0 +1,22 @@ +pub use askama::*; + +pub use gotham::handler::IntoResponse; +pub use gotham::state::State; +pub use hyper::{Body, Response, StatusCode}; + +pub fn respond<T: Template>(t: &T, ext: &str) -> Response<Body> { + match t.render() { + Ok(body) => Response::builder() + .status(StatusCode::OK) + .header( + "content-type", + mime::extension_to_mime_type(ext).to_string(), + ) + .body(body.into()) + .unwrap(), + Err(_) => Response::builder() + .status(StatusCode::INTERNAL_SERVER_ERROR) + .body(vec![].into()) + .unwrap(), + } +} diff --git a/askama_gotham/templates/hello.html b/askama_gotham/templates/hello.html new file mode 100644 index 0000000..8149be7 --- /dev/null +++ b/askama_gotham/templates/hello.html @@ -0,0 +1 @@ +Hello, {{ name }}! diff --git a/testing/tests/gotham.rs b/askama_gotham/tests/basic.rs index 225a0ef..fbb61a0 100644 --- a/testing/tests/gotham.rs +++ b/askama_gotham/tests/basic.rs @@ -1,5 +1,3 @@ -#![cfg(feature = "with-gotham")] - use askama::Template; use gotham::state::State; use gotham::test::TestServer; |