aboutsummaryrefslogtreecommitdiffstats
path: root/askama_derive
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--askama_derive/Cargo.toml1
-rw-r--r--askama_derive/src/generator.rs17
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(