Skip to main content

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. <lsantos@medicalmasses.com>
5 * Copyright (C) 2025  Ethan Dixon
6 * Copyright (C) 2025  MedicalMasses L.L.C. <contact@medicalmasses.com>
7 *
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
20 */
21use crate::utils::defaults::{DEFAULT_EMPTY_PARAMS, DEFAULT_TEXT_ITEM};
22use crate::utils::types::{HTMLResult, RUMString, SharedAppState, URLParams, URLPath};
23use crate::{
24    rumtk_web_get_config, rumtk_web_get_text_item, rumtk_web_render_component, rumtk_web_render_html,
25    RUMWebTemplate,
26};
27use rumtk_core::rumtk_critical_section_read;
28
29#[derive(RUMWebTemplate)]
30#[template(
31    source = "
32        <body class='f12 theme-{{theme}}'>
33            <a href='#main-content'>Skip to main content</a>
34            {{header|safe}}
35            {{main|safe}}
36            {{footer|safe}}
37        </body>
38    ",
39    ext = "html"
40)]
41pub struct AppBody {
42    theme: RUMString,
43    header: RUMString,
44    main: RUMString,
45    footer: RUMString,
46}
47
48pub fn app_body(path_components: URLPath, params: URLParams, state: SharedAppState) -> HTMLResult {
49    let theme = rumtk_web_get_text_item!(params, "theme", DEFAULT_TEXT_ITEM);
50
51    //Let's render the header and footer
52    //<div class="" hx-get="/component/navbar" hx-target="#navbar" hx-trigger="load" id="navbar"></div>
53    let header = rumtk_web_render_component!("header", DEFAULT_EMPTY_PARAMS, state)?.to_rumstring();
54    let main = rumtk_web_render_component!("main", path_components, DEFAULT_EMPTY_PARAMS, state)?.to_rumstring();
55    //<div class="" hx-get="/component/footer?social_list=linkedin,github" hx-target="#footer" hx-trigger="load" id="footer"></div>
56    let footer = rumtk_web_render_component!(
57        "footer",
58        [(
59            "social_list",
60            rumtk_web_get_config!(state).footer_conf.socials_list.as_str()
61        )],
62        state
63    )?.to_rumstring();
64
65    rumtk_web_render_html!(AppBody {
66        theme: RUMString::from(theme),
67        header,
68        main,
69        footer
70    })
71}