aboutsummaryrefslogtreecommitdiffstats
path: root/askama_shared/src
diff options
context:
space:
mode:
authorLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2020-07-28 11:54:47 +0200
committerLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2020-07-28 11:56:21 +0200
commit737858c5166e0d34d95084b349698971c019844f (patch)
tree488a04e8d238875b5d96c7ca07c20a6d41c9e619 /askama_shared/src
parent6642c4403f9469b7d97749b922bbab92d82b8c37 (diff)
downloadaskama-737858c5166e0d34d95084b349698971c019844f.tar.gz
askama-737858c5166e0d34d95084b349698971c019844f.tar.bz2
askama-737858c5166e0d34d95084b349698971c019844f.zip
Add mendes integration
Diffstat (limited to '')
-rw-r--r--askama_shared/src/generator.rs51
-rw-r--r--askama_shared/src/lib.rs1
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,