From b0d77c36ba632b91d65047716ca0a3e4176eaf4c Mon Sep 17 00:00:00 2001 From: metamuffin Date: Tue, 16 May 2023 19:35:29 +0200 Subject: add class to layout --- server/src/routes/ui/layout.rs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'server/src/routes/ui/layout.rs') diff --git a/server/src/routes/ui/layout.rs b/server/src/routes/ui/layout.rs index bc01c2e..746b534 100644 --- a/server/src/routes/ui/layout.rs +++ b/server/src/routes/ui/layout.rs @@ -12,7 +12,7 @@ use crate::{ uri, CONF, }; use async_std::task::block_on; -use markup::Render; +use markup::{DynRender, Render}; use rocket::{ http::ContentType, response::{self, Responder}, @@ -21,7 +21,7 @@ use rocket::{ use std::io::Cursor; markup::define! { - Layout(title: String, main: Main, session: Option) { + Layout<'a, Main: Render>(title: String, main: Main, class: Option<&'a str>, session: Option) { @markup::doctype() html { head { @@ -29,7 +29,7 @@ markup::define! { link[rel="stylesheet", href="/assets/style.css"]; script[src="/assets/bundle.js"] {} } - body { + body[class=class.unwrap_or("")] { nav { h1 { a[href="/"] { @CONF.brand } } @if let Some(_) = session { @@ -63,9 +63,20 @@ pub type DynLayoutPage<'a> = LayoutPage>; pub struct LayoutPage { pub title: String, + pub class: Option<&'static str>, pub content: T, } +impl Default for LayoutPage> { + fn default() -> Self { + Self { + class: None, + content: markup::new!(), + title: String::new(), + } + } +} + impl<'r, Main: Render> Responder<'r, 'static> for LayoutPage
{ fn respond_to(self, req: &'r Request<'_>) -> response::Result<'static> { // TODO blocking the event loop here. it seems like there is no other way to @@ -76,6 +87,7 @@ impl<'r, Main: Render> Responder<'r, 'static> for LayoutPage
{ Layout { main: self.content, title: self.title, + class: self.class.as_deref(), session, } .render(&mut out) -- cgit v1.2.3-70-g09d2