diff options
author | Bjørn Madsen <bm@aeons.dk> | 2020-01-29 09:32:39 +0100 |
---|---|---|
committer | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2020-01-29 11:22:47 +0100 |
commit | 91c2bbf80468c12d0663330cff185f1d7680c91e (patch) | |
tree | 9cadabbc819ffeffb5ff02b1605cb5d614425b47 /askama_derive | |
parent | e507c6faf61488cbce23a16eb823816f45130019 (diff) | |
download | askama-91c2bbf80468c12d0663330cff185f1d7680c91e.tar.gz askama-91c2bbf80468c12d0663330cff185f1d7680c91e.tar.bz2 askama-91c2bbf80468c12d0663330cff185f1d7680c91e.zip |
Add support for warp
Diffstat (limited to 'askama_derive')
-rw-r--r-- | askama_derive/Cargo.toml | 1 | ||||
-rw-r--r-- | askama_derive/src/generator.rs | 17 |
2 files changed, 18 insertions, 0 deletions
diff --git a/askama_derive/Cargo.toml b/askama_derive/Cargo.toml index 93755f5..799f989 100644 --- a/askama_derive/Cargo.toml +++ b/askama_derive/Cargo.toml @@ -17,6 +17,7 @@ iron = [] rocket = [] actix-web = [] gotham = [] +warp = [] [dependencies] askama_shared = { version = "0.9", path = "../askama_shared" } diff --git a/askama_derive/src/generator.rs b/askama_derive/src/generator.rs index 9532057..ab1a012 100644 --- a/askama_derive/src/generator.rs +++ b/askama_derive/src/generator.rs @@ -97,6 +97,9 @@ impl<'a> Generator<'a> { if cfg!(feature = "gotham") { self.impl_gotham_into_response(&mut buf); } + if cfg!(feature = "warp") { + self.impl_warp_reply(&mut buf); + } buf.buf } @@ -272,6 +275,20 @@ impl<'a> Generator<'a> { buf.writeln("}"); } + fn impl_warp_reply(&mut self, buf: &mut Buffer) { + self.write_header(buf, "::askama_warp::warp::reply::Reply", None); + buf.writeln("fn into_response(self) -> ::askama_warp::warp::reply::Response {"); + let ext = self + .input + .path + .extension() + .and_then(|s| s.to_str()) + .unwrap_or("txt"); + buf.writeln(&format!("::askama_warp::reply(&self, {:?})", ext)); + buf.writeln("}"); + buf.writeln("}"); + } + // Writes header for the `impl` for `TraitFromPathName` or `Template` // for the given context struct. fn write_header( |