diff options
Diffstat (limited to '')
-rw-r--r-- | askama_shared/src/generator.rs | 51 | ||||
-rw-r--r-- | askama_shared/src/lib.rs | 1 |
2 files changed, 52 insertions, 0 deletions
diff --git a/askama_shared/src/generator.rs b/askama_shared/src/generator.rs index 99b8d85..655cdd9 100644 --- a/askama_shared/src/generator.rs +++ b/askama_shared/src/generator.rs @@ -104,6 +104,9 @@ impl<'a, S: std::hash::BuildHasher> Generator<'a, S> { if self.integrations.iron { self.impl_iron_modifier_response(&mut buf); } + if self.integrations.mendes { + self.impl_mendes_responder(&mut buf); + } if self.integrations.rocket { self.impl_rocket_responder(&mut buf); } @@ -264,6 +267,54 @@ impl<'a, S: std::hash::BuildHasher> Generator<'a, S> { buf.writeln("}"); } + // Implement mendes' `Responder`. + fn impl_mendes_responder(&mut self, buf: &mut Buffer) { + let param = syn::parse_str("A: ::mendes::Application").unwrap(); + + let mut generics = self.input.ast.generics.clone(); + generics.params.push(param); + let (_, orig_ty_generics, _) = self.input.ast.generics.split_for_impl(); + let (impl_generics, _, where_clause) = generics.split_for_impl(); + + let mut where_clause = match where_clause { + Some(clause) => clause.clone(), + None => syn::WhereClause { + where_token: syn::Token![where](Span::call_site()), + predicates: syn::punctuated::Punctuated::new(), + }, + }; + + where_clause + .predicates + .push(syn::parse_str("A::ResponseBody: From<String>").unwrap()); + where_clause + .predicates + .push(syn::parse_str("A::Error: From<::mendes::askama::Error>").unwrap()); + + buf.writeln( + format!( + "{} {} for {} {} {{", + quote!(impl#impl_generics), + "::mendes::application::Responder<A>", + self.input.ast.ident, + quote!(#orig_ty_generics #where_clause), + ) + .as_ref(), + ); + + buf.writeln( + "fn into_response(self, app: &A) \ + -> ::mendes::http::Response<A::ResponseBody> {", + ); + + buf.writeln(&format!( + "::mendes::askama::into_response(app, &self, {:?})", + self.input.path.extension() + )); + buf.writeln("}"); + buf.writeln("}"); + } + // Implement Rocket's `Responder`. fn impl_rocket_responder(&mut self, buf: &mut Buffer) { let lifetime = syn::Lifetime::new("'askama", Span::call_site()); diff --git a/askama_shared/src/lib.rs b/askama_shared/src/lib.rs index 2e3d502..9aa93c3 100644 --- a/askama_shared/src/lib.rs +++ b/askama_shared/src/lib.rs @@ -265,6 +265,7 @@ pub struct Integrations { pub actix: bool, pub gotham: bool, pub iron: bool, + pub mendes: bool, pub rocket: bool, pub tide: bool, pub warp: bool, |