Skip to main content

rumtk_web/components/app/
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::app_body::AppBody;
22use crate::components::app::app_head::AppShellHead;
23use crate::components::{app::app_body::app_body, app::app_head::app_head};
24use crate::defaults::DEFAULT_THEME_ITEM;
25use crate::utils::defaults::LANG_EN;
26use crate::utils::types::{RUMString, SharedAppState, URLParams, URLPath};
27use crate::{rumtk_web_get_text_item, rumtk_web_set_config, ComponentResult, RUMWebTemplate, RUMWebTemplateSafe};
28
29#[derive(RUMWebTemplate)]
30#[template(
31    source = "
32        <!DOCTYPE html>
33        <html lang='{{lang}}'>
34            {{head}}
35            {{body}}
36        </html>
37    ",
38    ext = "html"
39)]
40pub struct AppShell {
41    head: AppShellHead,
42    lang: RUMString,
43    body: AppBody,
44}
45
46impl RUMWebTemplateSafe for AppShell {}
47
48pub fn app_shell<'a>(path_components: URLPath<'a, 'a>, params: URLParams<'a>, state: SharedAppState) -> ComponentResult<AppShell> {
49    let lang = rumtk_web_get_text_item!(params, "lang", LANG_EN).to_string();
50    let theme = rumtk_web_get_text_item!(params, "theme", DEFAULT_THEME_ITEM).to_string();
51    // TODO: We need to reevaluate how to validate the options that should be standardized to avoid parameter injection as an attack vector.
52    //owned_state.opts = *params.clone();
53
54    //Config App
55    rumtk_web_set_config!(state).lang = lang.clone();
56    rumtk_web_set_config!(state).theme = theme;
57
58    Ok(AppShell {
59        lang,
60        head: app_head(path_components, params, state.clone())?,
61        body: app_body(path_components, params, state.clone())?
62    })
63}