aboutsummaryrefslogtreecommitdiffstats
path: root/askama_axum/src
diff options
context:
space:
mode:
authorLibravatar Michael Alyn Miller <malyn@strangeGizmo.com>2021-11-27 20:59:51 -0800
committerLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2021-11-27 22:03:18 -0800
commit4940b5dd5e792811491f1c3c3b1c70c8177c7e02 (patch)
tree4d28ad21a66ecf9496c265c0844b4c4d036763bc /askama_axum/src
parent3ef2869f48556a0aae4ca861889f9fd8bea02d66 (diff)
downloadaskama-4940b5dd5e792811491f1c3c3b1c70c8177c7e02.tar.gz
askama-4940b5dd5e792811491f1c3c3b1c70c8177c7e02.tar.bz2
askama-4940b5dd5e792811491f1c3c3b1c70c8177c7e02.zip
Add Axum integration
Diffstat (limited to 'askama_axum/src')
-rw-r--r--askama_axum/src/lib.rs25
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(),
+ }
+}