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, SharedAppConf, URLParams, URLPath};
25use crate::{
26 rumtk_web_get_param, rumtk_web_get_text_item,
27 rumtk_web_render_component, rumtk_web_render_html,
28};
29use askama::Template;
30
31#[derive(Template)]
32#[template(
33 source = "
34 <div>
35 {% for element in elements %}
36 {{ element|safe }}
37 {% endfor %}
38 </div>
39 ",
40 ext = "html"
41)]
42pub struct AppBodyContents<'a> {
43 elements: &'a [RUMString],
44}
45
46fn app_body_contents(elements: &[RUMString]) -> HTMLResult {
47 rumtk_web_render_html!(AppBodyContents { elements })
48}
49
50#[derive(Template)]
51#[template(
52 source = "
53 <body class='f12 theme-{{theme}}'>
54 <a href='#main-content'>Skip to main content</a>
55 {{header|safe}}
56 {{main|safe}}
57 {{footer|safe}}
58 </body>
59 ",
60 ext = "html"
61)]
62pub struct AppBody {
63 theme: RUMString,
64 header: RUMString,
65 main: RUMString,
66 footer: RUMString,
67}
68
69pub fn app_body(path_components: URLPath, params: URLParams, state: SharedAppConf) -> HTMLResult {
70 let page: RUMString =
71 rumtk_web_get_param!(path_components, 0, RUMString::from(DEFAULT_TEXT_ITEM));
72 let theme = rumtk_web_get_text_item!(params, "theme", DEFAULT_TEXT_ITEM);
73
74 //Let's render the header and footer
75 //<div class="" hx-get="/component/navbar" hx-target="#navbar" hx-trigger="load" id="navbar"></div>
76 let header = rumtk_web_render_component!("header", [("", "")], state);
77 let main = rumtk_web_render_component!("main", [("", "")], state);
78 //<div class="" hx-get="/component/footer?social_list=linkedin,github" hx-target="#footer" hx-trigger="load" id="footer"></div>
79 let footer = rumtk_web_render_component!(
80 "footer",
81 [(
82 "social_list",
83 state
84 .read()
85 .expect("Lock failure")
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}