use super::{account::session::Session, Defer, HtmlTemplate};
use crate::{uri, CONF};
use async_std::task::block_on;
use markup::Render;
use rocket::{
http::ContentType,
request::{FromRequest, Outcome},
response::{self, Responder},
Request, Response,
};
use std::{convert::Infallible, io::Cursor};
use tokio::runtime::Handle;
markup::define! {
Layout(title: String, main: Main, session: Option) {
@markup::doctype()
html {
head {
title { @title " - " @CONF.brand }
link[rel="stylesheet", href="/assets/style.css"];
script[src="/assets/bundle.js"] {}
}
body {
nav {
h1 { a[href="/"] { @CONF.brand } }
a[href="/library"] { "My Library" }
div.account {
@if let Some(session) = session {
} else {
// a[href=uri!(r_account_register())] { "Register" }
// a[href=uri!(r_account_login())] { "Log in" }
}
}
}
#main { @main }
}
}
}
}
pub type DynLayoutPage<'a> = LayoutPage>;
pub struct LayoutPage {
pub title: String,
pub content: T,
}
impl<'r, Main: Render> Responder<'r, 'static> for LayoutPage {
fn respond_to(self, req: &'r Request<'_>) -> response::Result<'static> {
let session = block_on(req.guard::