Skip to main content

rumtk_web/components/
app_shell.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_body::app_body, app_head::app_head};
22use crate::utils::defaults::{DEFAULT_TEXT_ITEM, LANG_EN};
23use crate::utils::types::{HTMLResult, RUMString, SharedAppState, URLParams, URLPath};
24use crate::{
25    rumtk_web_get_text_item, rumtk_web_render_component, rumtk_web_render_html, rumtk_web_set_config,
26    RUMWebTemplate,
27};
28use rumtk_core::{rumtk_critical_section_read, rumtk_critical_section_write};
29
30#[derive(RUMWebTemplate)]
31#[template(
32    source = "
33        <!DOCTYPE html>
34        <html lang='{{lang}}'>
35            {{head|safe}}
36            {{body|safe}}
37        </html>
38    ",
39    ext = "html"
40)]
41pub struct AppShell {
42    head: RUMString,
43    lang: RUMString,
44    body: RUMString,
45}
46
47pub fn app_shell(path_components: URLPath, params: URLParams, state: SharedAppState) -> HTMLResult {
48    let lang = rumtk_web_get_text_item!(params, "lang", LANG_EN);
49    let theme = rumtk_web_get_text_item!(params, "theme", DEFAULT_TEXT_ITEM);
50    // TODO: We need to reevaluate how to validate the options that should be standardized to avoid parameter injection as an attack vector.
51    //owned_state.opts = *params.clone();
52
53    //Config App
54    rumtk_web_set_config!(state).lang = RUMString::from(lang);
55    rumtk_web_set_config!(state).theme = RUMString::from(theme);
56
57    //Let's render the head component
58    let head = rumtk_web_render_component!(|| -> HTMLResult {
59        app_head(path_components, params, state.clone())
60    });
61
62    //Let's render the head component
63    let body = rumtk_web_render_component!(|| -> HTMLResult {
64        app_body(path_components, params, state.clone())
65    });
66
67    rumtk_web_render_html!(AppShell {
68        lang: RUMString::from(lang),
69        head,
70        body
71    })
72}