diff options
author | metamuffin <metamuffin@disroot.org> | 2023-05-16 19:35:29 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2023-05-16 19:35:29 +0200 |
commit | b0d77c36ba632b91d65047716ca0a3e4176eaf4c (patch) | |
tree | 881d5448b5f28dabe4f6eeb7ace1bb4f50af5fc6 /server/src/routes/ui/layout.rs | |
parent | 3eda83a00f1c3e065a3e36675b40cc240cdb6ed6 (diff) | |
download | jellything-b0d77c36ba632b91d65047716ca0a3e4176eaf4c.tar jellything-b0d77c36ba632b91d65047716ca0a3e4176eaf4c.tar.bz2 jellything-b0d77c36ba632b91d65047716ca0a3e4176eaf4c.tar.zst |
add class to layout
Diffstat (limited to 'server/src/routes/ui/layout.rs')
-rw-r--r-- | server/src/routes/ui/layout.rs | 18 |
1 files changed, 15 insertions, 3 deletions
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<Main: Render>(title: String, main: Main, session: Option<Session>) { + Layout<'a, Main: Render>(title: String, main: Main, class: Option<&'a str>, session: Option<Session>) { @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<markup::DynRender<'a>>; pub struct LayoutPage<T> { pub title: String, + pub class: Option<&'static str>, pub content: T, } +impl Default for LayoutPage<DynRender<'_>> { + fn default() -> Self { + Self { + class: None, + content: markup::new!(), + title: String::new(), + } + } +} + impl<'r, Main: Render> Responder<'r, 'static> for LayoutPage<Main> { 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<Main> { Layout { main: self.content, title: self.title, + class: self.class.as_deref(), session, } .render(&mut out) |