diff options
Diffstat (limited to 'askama_shared/src/generator.rs')
-rw-r--r-- | askama_shared/src/generator.rs | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/askama_shared/src/generator.rs b/askama_shared/src/generator.rs index 78ada4b..cb395d4 100644 --- a/askama_shared/src/generator.rs +++ b/askama_shared/src/generator.rs @@ -96,6 +96,9 @@ impl<'a, S: std::hash::BuildHasher> Generator<'a, S> { if self.integrations.actix { self.impl_actix_web_responder(&mut buf)?; } + if self.integrations.axum { + self.impl_axum_into_response(&mut buf)?; + } if self.integrations.gotham { self.impl_gotham_into_response(&mut buf)?; } @@ -222,6 +225,21 @@ impl<'a, S: std::hash::BuildHasher> Generator<'a, S> { buf.writeln("}") } + // Implement Axum's `IntoResponse`. + fn impl_axum_into_response(&mut self, buf: &mut Buffer) -> Result<(), CompileError> { + self.write_header(buf, "::axum::response::IntoResponse", None)?; + buf.writeln( + "type Body = ::axum::body::Full<::axum::body::Bytes>;\n\ + type BodyError = std::convert::Infallible;\n\ + fn into_response(self)\ + -> ::axum::http::Response<Self::Body> {", + )?; + let ext = self.input.extension().unwrap_or("txt"); + buf.writeln(&format!("::askama_axum::into_response(&self, {:?})", ext))?; + buf.writeln("}")?; + buf.writeln("}") + } + // Implement gotham's `IntoResponse`. fn impl_gotham_into_response(&mut self, buf: &mut Buffer) -> Result<(), CompileError> { self.write_header(buf, "::askama_gotham::IntoResponse", None)?; @@ -439,9 +457,9 @@ impl<'a, S: std::hash::BuildHasher> Generator<'a, S> { self.flush_ws(m.ws1); self.prepare_ws(m.ws2); } - Node::Raw(ws1, contents, ws2) => { + Node::Raw(ws1, lws, val, rws, ws2) => { self.handle_ws(ws1); - self.buf_writable.push(Writable::Lit(contents)); + self.visit_lit(lws, val, rws); self.handle_ws(ws2); } Node::Import(ws, _, _) => { |