diff options
Diffstat (limited to 'askama_derive/src')
-rw-r--r-- | askama_derive/src/generator.rs | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/askama_derive/src/generator.rs b/askama_derive/src/generator.rs index 6eb16e8..57d54b1 100644 --- a/askama_derive/src/generator.rs +++ b/askama_derive/src/generator.rs @@ -53,6 +53,9 @@ pub fn generate(ast: &syn::DeriveInput, path: &Path, mut nodes: Vec<Node>) -> St gen.impl_template(ast, &content); } gen.impl_display(ast); + if cfg!(feature = "iron") { + gen.impl_modifier_response(ast); + } gen.result() } @@ -618,6 +621,15 @@ impl<'a> Generator<'a> { self.writeln("}"); } + // Implement iron's Modifier<Response> if enabled + fn impl_modifier_response(&mut self, ast: &syn::DeriveInput) { + self.write_header(ast, "::askama::iron::Modifier<::askama::iron::Response>"); + self.writeln("fn modify(self, res: &mut ::askama::iron::Response) {"); + self.writeln("res.body = Some(Box::new(self.render().unwrap().into_bytes()));"); + self.writeln("}"); + self.writeln("}"); + } + fn result(self) -> String { self.buf } |