diff options
Diffstat (limited to 'askama_axum/src')
-rw-r--r-- | askama_axum/src/lib.rs | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/askama_axum/src/lib.rs b/askama_axum/src/lib.rs new file mode 100644 index 0000000..0c21464 --- /dev/null +++ b/askama_axum/src/lib.rs @@ -0,0 +1,25 @@ +#![deny(elided_lifetimes_in_paths)] + +pub use askama::*; +use axum::{ + self, + body::{Bytes, Full}, + http::{Response, StatusCode}, +}; + +pub fn into_response<T: Template>(t: &T, ext: &str) -> axum::http::Response<Full<Bytes>> { + match t.render() { + Ok(body) => Response::builder() + .status(StatusCode::OK) + .header( + "content-type", + askama::mime::extension_to_mime_type(ext).to_string(), + ) + .body(body.into()) + .unwrap(), + Err(_) => Response::builder() + .status(StatusCode::INTERNAL_SERVER_ERROR) + .body(vec![].into()) + .unwrap(), + } +} |