diff options
Diffstat (limited to '')
-rw-r--r-- | askama_derive/Cargo.toml | 1 | ||||
-rw-r--r-- | askama_derive/src/generator.rs | 19 |
2 files changed, 20 insertions, 0 deletions
diff --git a/askama_derive/Cargo.toml b/askama_derive/Cargo.toml index 7096597..461a1f8 100644 --- a/askama_derive/Cargo.toml +++ b/askama_derive/Cargo.toml @@ -16,6 +16,7 @@ proc-macro = true iron = [] rocket = [] actix-web = [] +gotham = [] [dependencies] askama_shared = { version = "0.7.2", path = "../askama_shared" } 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( |