aboutsummaryrefslogtreecommitdiffstats
path: root/askama_derive/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--askama_derive/src/generator.rs23
1 files changed, 23 insertions, 0 deletions
diff --git a/askama_derive/src/generator.rs b/askama_derive/src/generator.rs
index f586e1c..5af38c0 100644
--- a/askama_derive/src/generator.rs
+++ b/askama_derive/src/generator.rs
@@ -94,6 +94,9 @@ impl<'a> Generator<'a> {
if cfg!(feature = "rocket") {
self.impl_rocket_responder();
}
+ if cfg!(feature = "actix-web") {
+ self.impl_actix_web_responder();
+ }
self.buf
}
@@ -235,6 +238,26 @@ impl<'a> Generator<'a> {
self.writeln("}");
}
+ // Implement Actix-web's `Responder`.
+ fn impl_actix_web_responder(&mut self) {
+ self.write_header("::askama::actix_web::Responder", None);
+ self.writeln("type Item = ::askama::actix_web::HttpResponse;");
+ self.writeln("type Error = ::askama::actix_web::Error;");
+ self.writeln(
+ "fn respond_to<S>(self, _req: &::askama::actix_web::HttpRequest<S>) \
+ -> Result<Self::Item, Self::Error> {",
+ );
+
+ let ext = match self.input.path.extension() {
+ Some(s) => s.to_str().unwrap(),
+ None => "txt",
+ };
+ self.writeln(&format!("::askama::actix_web::respond(&self, {:?})", ext));
+
+ self.writeln("}");
+ self.writeln("}");
+ }
+
// Writes header for the `impl` for `TraitFromPathName` or `Template`
// for the given context struct.
fn write_header(&mut self, target: &str, params: Option<Vec<syn::GenericParam>>) {