aboutsummaryrefslogtreecommitdiffstats
path: root/askama_gotham/src/lib.rs
diff options
context:
space:
mode:
authorLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2020-01-28 22:17:22 +0100
committerLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2020-01-29 09:25:59 +0100
commit75f32d3967e4d13b86b0d720ebc808c6fd9caa05 (patch)
treeb919cd2796220c74b1d6fd69b363c53505681f3a /askama_gotham/src/lib.rs
parentc6f9a053c7328e6c782508114bd96aa569b5de7d (diff)
downloadaskama-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/src/lib.rs22
1 files changed, 22 insertions, 0 deletions
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(),
+ }
+}