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