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}
23
24impl RenderOnce for Content<'_> {
25 fn render_once(self, tmpl: &mut TemplateBuffer) {
26 self.render(tmpl);
27 }
28}
29
30impl RenderMut for Content<'_> {
31 fn render_mut(&mut self, tmpl: &mut TemplateBuffer) {
32 self.render(tmpl);
33 }
34}
35
36impl Render for Content<'_> {
37 fn render(&self, tmpl: &mut TemplateBuffer) {
38 match self.content.format {
39 "mkd" | "md" | "markdown" => tmpl << crate::Markdown::new(self.content.data, self.base),
40 // TODO: error if heading-level is non-zero.
41 "html" => tmpl << Raw(self.content.data),
42 "" | "text" | "txt" => tmpl << self.content.data,
43 format => tmpl.record_error(format!("unknown format '{}'", format)),
44 }
45 }
46}