aboutsummaryrefslogtreecommitdiffstats
path: root/askama_shared/src/generator.rs
diff options
context:
space:
mode:
authorLibravatar Jacob Rothstein <hi@jbr.me>2020-07-09 21:06:03 -0700
committerLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2020-07-14 09:46:12 +0200
commit29cb90bceb59d9dbea94342dfdd8136e1ef494e6 (patch)
tree8d4d63527fbaa039ccf7f0982ff8849c238e68d3 /askama_shared/src/generator.rs
parent0a6284aa91e1eb8da81d7b317fb539653e519d0a (diff)
downloadaskama-29cb90bceb59d9dbea94342dfdd8136e1ef494e6.tar.gz
askama-29cb90bceb59d9dbea94342dfdd8136e1ef494e6.tar.bz2
askama-29cb90bceb59d9dbea94342dfdd8136e1ef494e6.zip
askama tide
Diffstat (limited to '')
-rw-r--r--askama_shared/src/generator.rs29
1 files changed, 29 insertions, 0 deletions
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(