about summary refs log tree commit diff
path: root/src/render.rs
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@gmail.com>2018-04-15T19·18+0200
committerVincent Ambo <tazjin@gmail.com>2018-04-15T19·18+0200
commitd9d1a3313f5cbceb5cb4878752fe0dc117bed3b0 (patch)
treea96452c752f73ac4aa78d74f06f68b79daed7c98 /src/render.rs
parentec712cc4c0e12329f51d10d9bd626d1859a011b8 (diff)
refactor(render): Pass serializable structs to Tera directly
No need to go the intermediate step via `Context::new()`
Diffstat (limited to 'src/render.rs')
-rw-r--r--src/render.rs12
1 files changed, 3 insertions, 9 deletions
diff --git a/src/render.rs b/src/render.rs
index d95fb693478b..0c1e69d3c4c9 100644
--- a/src/render.rs
+++ b/src/render.rs
@@ -151,11 +151,7 @@ impl Handler<ThreadPage> for Renderer {
 
     fn handle(&mut self, msg: ThreadPage, _: &mut Self::Context) -> Self::Result {
         let renderable = prepare_thread(&self.comrak, msg);
-        let mut ctx = Context::new();
-        ctx.add("title", &renderable.title);
-        ctx.add("posts", &renderable.posts);
-        ctx.add("id", &renderable.id);
-        Ok(self.tera.render("thread.html", &ctx)?)
+        Ok(self.tera.render("thread.html", &renderable)?)
     }
 }
 
@@ -224,6 +220,7 @@ impl Handler<NewThreadPage> for Renderer {
 }
 
 /// Message used to render search results
+#[derive(Serialize)]
 pub struct SearchResultPage {
     pub query: String,
     pub results: Vec<SearchResult>,
@@ -237,9 +234,6 @@ impl Handler<SearchResultPage> for Renderer {
     type Result = Result<String>;
 
     fn handle(&mut self, msg: SearchResultPage, _: &mut Self::Context) -> Self::Result {
-        let mut ctx = Context::new();
-        ctx.add("query", &msg.query);
-        ctx.add("results", &msg.results);
-        Ok(self.tera.render("search.html", &ctx)?)
+        Ok(self.tera.render("search.html", &msg)?)
     }
 }