From 75f32d3967e4d13b86b0d720ebc808c6fd9caa05 Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Tue, 28 Jan 2020 22:17:22 +0100 Subject: Move Gotham integration into separate askama_gotham crate --- askama_gotham/src/lib.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 askama_gotham/src/lib.rs (limited to 'askama_gotham/src/lib.rs') 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: &T, ext: &str) -> Response { + 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(), + } +} -- cgit