From 91c2bbf80468c12d0663330cff185f1d7680c91e Mon Sep 17 00:00:00 2001 From: Bjørn Madsen Date: Wed, 29 Jan 2020 09:32:39 +0100 Subject: Add support for warp --- askama_derive/Cargo.toml | 1 + askama_derive/src/generator.rs | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) (limited to 'askama_derive') 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( -- cgit