From 9b0001cdf3991e74c042a9661e306b13785ca223 Mon Sep 17 00:00:00 2001 From: Kellen Frodelius-Fujimoto Date: Mon, 10 Dec 2018 20:21:15 +0100 Subject: Implement `IntoResponse` for `Template`, allowing them to be used in `gotham` handlers. --- askama_derive/src/generator.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'askama_derive/src/generator.rs') 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( -- cgit