gazetta_render_ext/content.rs
1// Copyright (C) 2015 Steven Allen
2//
3// This file is part of gazetta.
4//
5// This program is free software: you can redistribute it and/or modify it under the terms of the
6// GNU General Public License as published by the Free Software Foundation version 3 of the
7// License.
8//
9// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
10// without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
11// the GNU General Public License for more details.
12//
13// You should have received a copy of the GNU General Public License along with this program. If
14// not, see <http://www.gnu.org/licenses/>.
15//
16use horrorshow::prelude::*;
17
18/// Renders a page's content
19pub struct Content<'a> {
20 pub content: &'a gazetta_core::view::Content<'a>,
21 pub base: &'a str,
22 pub syntax_highlight: bool,
23}
24
25impl RenderOnce for Content<'_> {
26 fn render_once(self, tmpl: &mut TemplateBuffer) {
27 self.render(tmpl);
28 }
29}
30
31impl RenderMut for Content<'_> {
32 fn render_mut(&mut self, tmpl: &mut TemplateBuffer) {
33 self.render(tmpl);
34 }
35}
36
37impl Render for Content<'_> {
38 fn render(&self, tmpl: &mut TemplateBuffer) {
39 match self.content.format {
40 "mkd" | "md" | "markdown" => {
41 tmpl << crate::Markdown::new(self.content.data, self.base, self.syntax_highlight)
42 }
43 // TODO: error if heading-level is non-zero.
44 "html" => tmpl << Raw(self.content.data),
45 "" | "text" | "txt" => tmpl << self.content.data,
46 format => tmpl.record_error(format!("unknown format '{}'", format)),
47 }
48 }
49}