From 29cb90bceb59d9dbea94342dfdd8136e1ef494e6 Mon Sep 17 00:00:00 2001 From: Jacob Rothstein Date: Thu, 9 Jul 2020 21:06:03 -0700 Subject: askama tide --- askama_shared/src/generator.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'askama_shared/src/generator.rs') diff --git a/askama_shared/src/generator.rs b/askama_shared/src/generator.rs index 180a356..fda56e2 100644 --- a/askama_shared/src/generator.rs +++ b/askama_shared/src/generator.rs @@ -109,6 +109,9 @@ impl<'a, S: std::hash::BuildHasher> Generator<'a, S> { if self.integrations.warp { self.impl_warp_reply(&mut buf); } + if self.integrations.tide { + self.impl_tide_integrations(&mut buf); + } buf.buf } @@ -298,6 +301,32 @@ impl<'a, S: std::hash::BuildHasher> Generator<'a, S> { buf.writeln("}"); } + fn impl_tide_integrations(&mut self, buf: &mut Buffer) { + let ext = self + .input + .path + .extension() + .and_then(|s| s.to_str()) + .unwrap_or("txt"); + + self.write_header( + buf, + "std::convert::TryInto<::askama_tide::tide::Body>", + None, + ); + buf.writeln( + "type Error = ::askama_tide::askama::Error;\n\ + fn try_into(self) -> ::askama_tide::askama::Result<::askama_tide::tide::Body> {", + ); + buf.writeln(&format!("::askama_tide::try_into_body(&self, {:?})", &ext)); + buf.writeln("}"); + buf.writeln("}"); + self.write_header(buf, "Into<::askama_tide::tide::Response>", None); + buf.writeln("fn into(self) -> ::askama_tide::tide::Response {"); + buf.writeln(&format!("::askama_tide::into_response(&self, {:?})", ext)); + buf.writeln("}\n}"); + } + // Writes header for the `impl` for `TraitFromPathName` or `Template` // for the given context struct. fn write_header( -- cgit