aboutsummaryrefslogtreecommitdiffstats
path: root/askama_warp/src/lib.rs
diff options
context:
space:
mode:
authorLibravatar Bjørn Madsen <bm@aeons.dk>2020-01-29 09:32:39 +0100
committerLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2020-01-29 11:22:47 +0100
commit91c2bbf80468c12d0663330cff185f1d7680c91e (patch)
tree9cadabbc819ffeffb5ff02b1605cb5d614425b47 /askama_warp/src/lib.rs
parente507c6faf61488cbce23a16eb823816f45130019 (diff)
downloadaskama-91c2bbf80468c12d0663330cff185f1d7680c91e.tar.gz
askama-91c2bbf80468c12d0663330cff185f1d7680c91e.tar.bz2
askama-91c2bbf80468c12d0663330cff185f1d7680c91e.zip
Add support for warp
Diffstat (limited to '')
-rw-r--r--askama_warp/src/lib.rs22
1 files changed, 22 insertions, 0 deletions
diff --git a/askama_warp/src/lib.rs b/askama_warp/src/lib.rs
new file mode 100644
index 0000000..e721ab4
--- /dev/null
+++ b/askama_warp/src/lib.rs
@@ -0,0 +1,22 @@
+pub use askama::*;
+pub use warp;
+
+use warp::http::{self, header, StatusCode};
+use warp::hyper::Body;
+use warp::reply::Response;
+
+pub fn reply<T: askama::Template>(t: &T, ext: &str) -> Response {
+ match t.render() {
+ Ok(body) => http::Response::builder()
+ .status(StatusCode::OK)
+ .header(
+ header::CONTENT_TYPE,
+ mime::extension_to_mime_type(ext).to_string(),
+ )
+ .body(body.into()),
+ Err(_) => http::Response::builder()
+ .status(StatusCode::INTERNAL_SERVER_ERROR)
+ .body(Body::empty()),
+ }
+ .unwrap()
+}