diff options
author | Jacob Rothstein <hi@jbr.me> | 2020-07-09 21:06:03 -0700 |
---|---|---|
committer | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2020-07-14 09:46:12 +0200 |
commit | 29cb90bceb59d9dbea94342dfdd8136e1ef494e6 (patch) | |
tree | 8d4d63527fbaa039ccf7f0982ff8849c238e68d3 /askama_shared | |
parent | 0a6284aa91e1eb8da81d7b317fb539653e519d0a (diff) | |
download | askama-29cb90bceb59d9dbea94342dfdd8136e1ef494e6.tar.gz askama-29cb90bceb59d9dbea94342dfdd8136e1ef494e6.tar.bz2 askama-29cb90bceb59d9dbea94342dfdd8136e1ef494e6.zip |
askama tide
Diffstat (limited to 'askama_shared')
-rw-r--r-- | askama_shared/src/generator.rs | 29 | ||||
-rw-r--r-- | askama_shared/src/lib.rs | 1 |
2 files changed, 30 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( diff --git a/askama_shared/src/lib.rs b/askama_shared/src/lib.rs index e405439..f11b129 100644 --- a/askama_shared/src/lib.rs +++ b/askama_shared/src/lib.rs @@ -267,6 +267,7 @@ pub struct Integrations { pub iron: bool, pub rocket: bool, pub warp: bool, + pub tide: bool, } static CONFIG_FILE_NAME: &str = "askama.toml"; |