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