aboutsummaryrefslogtreecommitdiffstats
path: root/askama_derive/src/generator.rs
diff options
context:
space:
mode:
Diffstat (limited to 'askama_derive/src/generator.rs')
-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(