gazetta_render_ext/
date.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 gazetta_core::model::DateTime as DateModel;
17use gazetta_core::prelude::*;
18use horrorshow::html;
19use horrorshow::prelude::*;
20
21pub struct Date<'a>(pub &'a DateModel);
22
23impl<'a> RenderOnce for Date<'a> {
24    fn render_once(self, tmpl: &mut TemplateBuffer) {
25        self.render(tmpl)
26    }
27}
28
29impl<'a> RenderMut for Date<'a> {
30    fn render_mut(&mut self, tmpl: &mut TemplateBuffer) {
31        self.render(tmpl)
32    }
33}
34
35impl<'a> Render for Date<'a> {
36    fn render(&self, tmpl: &mut TemplateBuffer) {
37        tmpl << html! {
38            time(datetime = self.0.to_rfc3339(), title = format_args!("{}", self.0.format("%B %d, %Y"))) {
39                span(class="date-year") : format_args!("{:04}", self.0.year());
40                span(class="date-separator") : "-";
41                span(class="date-month") : format_args!("{:02}", self.0.month());
42                span(class="date-separator") : "-";
43                span(class="date-day") : format_args!("{:02}", self.0.day());
44            }
45        }
46    }
47}