aboutsummaryrefslogtreecommitdiffstats
path: root/askama_derive
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--askama_derive/Cargo.toml1
-rw-r--r--askama_derive/src/generator.rs23
2 files changed, 24 insertions, 0 deletions
diff --git a/askama_derive/Cargo.toml b/askama_derive/Cargo.toml
index 1834852..774fb51 100644
--- a/askama_derive/Cargo.toml
+++ b/askama_derive/Cargo.toml
@@ -15,6 +15,7 @@ proc-macro = true
default = []
iron = ["askama_shared/iron"]
rocket = ["askama_shared/rocket"]
+actix-web = ["askama_shared/actix-web"]
[dependencies]
askama_shared = { version = "0.7.0", path = "../askama_shared" }
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>>) {