aboutsummaryrefslogtreecommitdiffstats
path: root/askama_derive/src/generator.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_derive/src/generator.rs
parente507c6faf61488cbce23a16eb823816f45130019 (diff)
downloadaskama-91c2bbf80468c12d0663330cff185f1d7680c91e.tar.gz
askama-91c2bbf80468c12d0663330cff185f1d7680c91e.tar.bz2
askama-91c2bbf80468c12d0663330cff185f1d7680c91e.zip
Add support for warp
Diffstat (limited to 'askama_derive/src/generator.rs')
-rw-r--r--askama_derive/src/generator.rs17
1 files changed, 17 insertions, 0 deletions
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(