diff options
author | Vincent Ambo <mail@tazj.in> | 2018-05-22T16·56+0200 |
---|---|---|
committer | Vincent Ambo <github@tazj.in> | 2018-05-22T18·44+0200 |
commit | 69583b1236fd329cdc223f2d2a52ff313269d1d1 (patch) | |
tree | f7613e7f5b8ab41b76bd16f243bddf478003fbb6 /src | |
parent | 94d5e02bb3672db49e4fa2590eab8b7e58440f61 (diff) |
refactor(templates): Move thread page template to Askama
Diffstat (limited to 'src')
-rw-r--r-- | src/main.rs | 1 | ||||
-rw-r--r-- | src/render.rs | 11 |
2 files changed, 6 insertions, 6 deletions
diff --git a/src/main.rs b/src/main.rs index c68b75229f41..3c533515bfb0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -142,7 +142,6 @@ fn start_renderer() -> Addr<Syn, Renderer> { tera.add_raw_templates(vec![ ("post.html", include_str!("../templates/post.html")), ("search.html", include_str!("../templates/search.html")), - ("thread.html", include_str!("../templates/thread.html")), ]).expect("Could not compile templates"); let comrak = comrak::ComrakOptions{ diff --git a/src/render.rs b/src/render.rs index ff8bd3ab8ee6..cfae2ad817ea 100644 --- a/src/render.rs +++ b/src/render.rs @@ -108,7 +108,7 @@ message!(ThreadPage, Result<String>); struct RenderablePost { id: i32, body: String, - posted: String, // FormattedDate, + posted: FormattedDate, author_name: String, author_gravatar: String, editable: bool, @@ -116,7 +116,8 @@ struct RenderablePost { /// This structure represents the transformed thread data with /// Markdown rendering and other changes applied. -#[derive(Debug, Serialize)] +#[derive(Template)] +#[template(path = "thread.html")] struct RenderableThreadPage { id: i32, title: String, @@ -137,7 +138,7 @@ fn prepare_thread(comrak: &ComrakOptions, page: ThreadPage) -> RenderableThreadP RenderablePost { id: post.id, body: markdown_to_html(&post.body, comrak), - posted: format!("{}", FormattedDate(post.posted)), // post.posted.into(), + posted: FormattedDate(post.posted), author_name: post.author_name.clone(), author_gravatar: md5_hex(post.author_email.as_bytes()), editable, @@ -147,7 +148,7 @@ fn prepare_thread(comrak: &ComrakOptions, page: ThreadPage) -> RenderableThreadP RenderableThreadPage { posts, id: page.thread.id, - title: escape_html(&page.thread.title), + title: page.thread.title, } } @@ -156,7 +157,7 @@ impl Handler<ThreadPage> for Renderer { fn handle(&mut self, msg: ThreadPage, _: &mut Self::Context) -> Self::Result { let renderable = prepare_thread(&self.comrak, msg); - Ok(self.tera.render("thread.html", &renderable)?) + renderable.render().map_err(|e| e.into()) } } |