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.
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, LANG_EN};
24use crate::utils::types::{HTMLResult, RUMString, SharedAppState, URLParams, URLPath};
25use crate::{rumtk_web_get_text_item, rumtk_web_render_component, rumtk_web_render_html};
26use askama::Template;
27
28use crate::components::{app_body::app_body, app_head::app_head};
29
30#[derive(Template)]
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    state.write().expect("Lock failure").config.lang = RUMString::from(lang);
55    state.write().expect("Lock failure").config.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}