diff options
author | Kellen Frodelius-Fujimoto <kellen@kellenfujimoto.com> | 2018-12-10 20:21:15 +0100 |
---|---|---|
committer | Juan Aguilar <mhpoin@gmail.com> | 2018-12-10 22:29:24 +0100 |
commit | 9b0001cdf3991e74c042a9661e306b13785ca223 (patch) | |
tree | d8ccfbdec0c5ad4d81150b92c2c74952abfc5da2 /askama_derive/src/generator.rs | |
parent | 5549f9a3cd94e3cd6700067b1c74194dadb58a0f (diff) | |
download | askama-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 'askama_derive/src/generator.rs')
-rw-r--r-- | askama_derive/src/generator.rs | 19 |
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( |