aboutsummaryrefslogtreecommitdiffstats
path: root/askama_derive/src
diff options
context:
space:
mode:
authorLibravatar Kellen Frodelius-Fujimoto <kellen@kellenfujimoto.com>2018-12-10 20:21:15 +0100
committerLibravatar Juan Aguilar <mhpoin@gmail.com>2018-12-10 22:29:24 +0100
commit9b0001cdf3991e74c042a9661e306b13785ca223 (patch)
treed8ccfbdec0c5ad4d81150b92c2c74952abfc5da2 /askama_derive/src
parent5549f9a3cd94e3cd6700067b1c74194dadb58a0f (diff)
downloadaskama-9b0001cdf3991e74c042a9661e306b13785ca223.tar.gz
askama-9b0001cdf3991e74c042a9661e306b13785ca223.tar.bz2
askama-9b0001cdf3991e74c042a9661e306b13785ca223.zip
Implement `IntoResponse` for `Template`, allowing them to be used in `gotham` handlers.
Diffstat (limited to '')
-rw-r--r--askama_derive/src/generator.rs19
1 files changed, 19 insertions, 0 deletions
diff --git a/askama_derive/src/generator.rs b/askama_derive/src/generator.rs
index 61a82bd..b30b040 100644
--- a/askama_derive/src/generator.rs
+++ b/askama_derive/src/generator.rs
@@ -92,6 +92,9 @@ impl<'a> Generator<'a> {
if cfg!(feature = "actix-web") {
self.impl_actix_web_responder(&mut buf);
}
+ if cfg!(feature = "gotham") {
+ self.impl_gotham_into_response(&mut buf);
+ }
buf.buf
}
@@ -217,6 +220,22 @@ impl<'a> Generator<'a> {
buf.writeln("}");
}
+ // Implement gotham's `IntoResponse`.
+ fn impl_gotham_into_response(&mut self, buf: &mut Buffer) {
+ self.write_header(buf, "::askama::gotham::IntoResponse", None);
+ buf.writeln(
+ "fn into_response(self, _state: &::askama::gotham::State)\
+ -> ::askama::gotham::Response<::askama::gotham::Body> {",
+ );
+ let ext = match self.input.path.extension() {
+ Some(s) => s.to_str().unwrap(),
+ None => "txt",
+ };
+ buf.writeln(&format!("::askama::gotham::respond(&self, {:?})", ext));
+ buf.writeln("}");
+ buf.writeln("}");
+ }
+
// Writes header for the `impl` for `TraitFromPathName` or `Template`
// for the given context struct.
fn write_header(