diff options
author | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2020-01-28 22:06:11 +0100 |
---|---|---|
committer | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2020-01-29 09:25:59 +0100 |
commit | c6f9a053c7328e6c782508114bd96aa569b5de7d (patch) | |
tree | 362ef1f8ef421eb5913fa2834c10f6743e1ca7e1 /askama_rocket/src/lib.rs | |
parent | b56c11639f9ea5ef1354a1e91ca98541a16bca9b (diff) | |
download | askama-c6f9a053c7328e6c782508114bd96aa569b5de7d.tar.gz askama-c6f9a053c7328e6c782508114bd96aa569b5de7d.tar.bz2 askama-c6f9a053c7328e6c782508114bd96aa569b5de7d.zip |
Move Rocket integration into askama_rocket crate
Diffstat (limited to 'askama_rocket/src/lib.rs')
-rw-r--r-- | askama_rocket/src/lib.rs | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/askama_rocket/src/lib.rs b/askama_rocket/src/lib.rs new file mode 100644 index 0000000..6db3b7b --- /dev/null +++ b/askama_rocket/src/lib.rs @@ -0,0 +1,16 @@ +use std::io::Cursor; + +pub use askama::*; +use rocket::http::{ContentType, Status}; +pub use rocket::request::Request; +use rocket::response::Response; +pub use rocket::response::{Responder, Result}; + +pub fn respond<T: Template>(t: &T, ext: &str) -> Result<'static> { + let rsp = t.render().map_err(|_| Status::InternalServerError)?; + let ctype = ContentType::from_extension(ext).ok_or(Status::InternalServerError)?; + Response::build() + .header(ctype) + .sized_body(Cursor::new(rsp)) + .ok() +} |