aboutsummaryrefslogtreecommitdiffstats
path: root/askama_shared
diff options
context:
space:
mode:
Diffstat (limited to 'askama_shared')
-rw-r--r--askama_shared/src/generator.rs29
-rw-r--r--askama_shared/src/lib.rs1
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";