rumtk_web/components/app_body.rs
1/*
2 * rumtk attempts to implement HL7 and medical protocols for interoperability in medicine.
3 * This toolkit aims to be reliable, simple, performant, and standards compliant.
4 * Copyright (C) 2025 Luis M. Santos, M.D.
5 * Copyright (C) 2025 Nick Stephenson
6 * Copyright (C) 2025 Ethan Dixon
7 * Copyright (C) 2025 MedicalMasses L.L.C.
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23use crate::utils::defaults::DEFAULT_TEXT_ITEM;
24use crate::utils::types::{HTMLResult, RUMString, SharedAppState, URLParams, URLPath};
25use crate::{
26 rumtk_web_get_param, rumtk_web_get_text_item, rumtk_web_render_component, rumtk_web_render_html,
27};
28use askama::Template;
29
30#[derive(Template)]
31#[template(
32 source = "
33 <div>
34 {% for element in elements %}
35 {{ element|safe }}
36 {% endfor %}
37 </div>
38 ",
39 ext = "html"
40)]
41pub struct AppBodyContents<'a> {
42 elements: &'a [RUMString],
43}
44
45fn app_body_contents(elements: &[RUMString]) -> HTMLResult {
46 rumtk_web_render_html!(AppBodyContents { elements })
47}
48
49#[derive(Template)]
50#[template(
51 source = "
52 <body class='f12 theme-{{theme}}'>
53 <a href='#main-content'>Skip to main content</a>
54 {{header|safe}}
55 {{main|safe}}
56 {{footer|safe}}
57 </body>
58 ",
59 ext = "html"
60)]
61pub struct AppBody {
62 theme: RUMString,
63 header: RUMString,
64 main: RUMString,
65 footer: RUMString,
66}
67
68pub fn app_body(path_components: URLPath, params: URLParams, state: SharedAppState) -> HTMLResult {
69 let page: RUMString =
70 rumtk_web_get_param!(path_components, 0, RUMString::from(DEFAULT_TEXT_ITEM));
71 let theme = rumtk_web_get_text_item!(params, "theme", DEFAULT_TEXT_ITEM);
72
73 //Let's render the header and footer
74 //<div class="" hx-get="/component/navbar" hx-target="#navbar" hx-trigger="load" id="navbar"></div>
75 let header = rumtk_web_render_component!("header", [("", "")], state);
76 let main = rumtk_web_render_component!("main", [("", "")], state);
77 //<div class="" hx-get="/component/footer?social_list=linkedin,github" hx-target="#footer" hx-trigger="load" id="footer"></div>
78 let footer = rumtk_web_render_component!(
79 "footer",
80 [(
81 "social_list",
82 state
83 .read()
84 .expect("Lock failure")
85 .config
86 .footer_conf
87 .socials_list
88 .clone()
89 )],
90 state
91 );
92
93 rumtk_web_render_html!(AppBody {
94 theme: RUMString::from(theme),
95 header,
96 main,
97 footer
98 })
99}