diff options
Diffstat (limited to 'askama_gotham/src')
-rw-r--r-- | askama_gotham/src/lib.rs | 22 |
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(), + } +} |