aboutsummaryrefslogtreecommitdiff
path: root/server/src/routes/ui/mod.rs
blob: 1cad72cc522f6a96abf162e332819f98b52fd01b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
use self::layout::Layout;
use markup::Render;
use rocket::{
    http::ContentType,
    response::{self, Responder},
    Request, Response,
};
use std::io::Cursor;

pub mod error;
pub mod home;
pub mod layout;
pub mod node;
pub mod style;
pub mod player;

pub struct HtmlTemplate<T>(pub String, pub T);

impl<'r, T: Render> Responder<'r, 'static> for HtmlTemplate<T> {
    fn respond_to(self, _: &'r Request<'_>) -> response::Result<'static> {
        let mut out = String::new();
        Layout {
            title: self.0,
            main: self.1,
        }
        .render(&mut out)
        .unwrap();
        Response::build()
            .header(ContentType::HTML)
            .streamed_body(Cursor::new(out))
            .ok()
    }
}