Skip to main content

rumtk_web/components/app/
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::components::app::app_footer::app_footer;
22use crate::components::app::app_nav::app_nav;
23use crate::components::html::main;
24use crate::utils::defaults::DEFAULT_EMPTY_PARAMS;
25use crate::utils::types::{SharedAppState, URLParams, URLPath};
26use crate::{rumtk_web_get_config, sanitize_html, ComponentResult, RUMWebTemplate, RUMWebTemplateSafe};
27use rumtk_core::strings::RUMString;
28
29#[derive(RUMWebTemplate)]
30#[template(
31    source = "
32        <body class='f12 fw300 theme-{{theme}}'>
33            <a href='#main-content header' hidden>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
48impl RUMWebTemplateSafe for AppBody {}
49
50pub fn app_body<'a>(path_components: URLPath<'a, 'a>, params: URLParams<'a>, state: SharedAppState) -> ComponentResult<AppBody> {
51    let theme = rumtk_web_get_config!(state).theme.clone();
52
53    //Let's render the header and footer
54    //<div class="" hx-get="/component/navbar" hx-target="#navbar" hx-trigger="load" id="navbar"></div>
55    let header = app_nav(path_components, DEFAULT_EMPTY_PARAMS.get_inner(), state.clone())?;
56    let main = main(path_components, DEFAULT_EMPTY_PARAMS.get_inner(), state.clone())?;
57    //<div class="" hx-get="/component/footer?social_list=linkedin,github" hx-target="#footer" hx-trigger="load" id="footer"></div>
58    let footer = app_footer(
59        path_components,
60        params,
61        state
62    )?;
63
64    //Prerender the body so we can do an html sanitization pass
65    let rendered_header = sanitize_html(&header.to_string(), true);
66    let rendered_main = sanitize_html(&main.to_string(), true);
67    let rendered_footer = sanitize_html(&footer.to_string(), true);
68
69    Ok(AppBody {
70        theme,
71        header: rendered_header,
72        main: rendered_main,
73        footer: rendered_footer,
74    })
75}