rumtk_web/components/app_shell.rs
1use crate::components::{app_body::app_body, app_head::app_head};
2/*
3 * rumtk attempts to implement HL7 and medical protocols for interoperability in medicine.
4 * This toolkit aims to be reliable, simple, performant, and standards compliant.
5 * Copyright (C) 2025 Luis M. Santos, M.D.
6 * Copyright (C) 2025 MedicalMasses L.L.C.
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * This library 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 GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22use crate::utils::defaults::{DEFAULT_TEXT_ITEM, LANG_EN};
23use crate::utils::types::{HTMLResult, RUMString, SharedAppConf, URLParams, URLPath};
24use crate::{rumtk_web_get_text_item, rumtk_web_render_component, rumtk_web_render_html};
25use askama::Template;
26
27#[derive(Template)]
28#[template(
29 source = "
30 <!DOCTYPE html>
31 <html lang='{{lang}}'>
32 {{head|safe}}
33 {{body|safe}}
34 </html>
35 ",
36 ext = "html"
37)]
38pub struct AppShell {
39 head: RUMString,
40 lang: RUMString,
41 body: RUMString,
42}
43
44pub fn app_shell(path_components: URLPath, params: URLParams, state: SharedAppConf) -> HTMLResult {
45 let lang = rumtk_web_get_text_item!(params, "lang", LANG_EN);
46 let theme = rumtk_web_get_text_item!(params, "theme", DEFAULT_TEXT_ITEM);
47 // TODO: We need to reevaluate how to validate the options that should be standardized to avoid parameter injection as an attack vector.
48 //owned_state.opts = *params.clone();
49
50 //Config App
51 state.lock().expect("Lock failure").lang = RUMString::from(lang);
52 state.lock().expect("Lock failure").theme = RUMString::from(theme);
53
54 //Let's render the head component
55 let head = rumtk_web_render_component!(|| -> HTMLResult {
56 app_head(path_components, params, state.clone())
57 });
58
59 //Let's render the head component
60 let body = rumtk_web_render_component!(|| -> HTMLResult {
61 app_body(path_components, params, state.clone())
62 });
63
64 rumtk_web_render_html!(AppShell {
65 lang: RUMString::from(lang),
66 head,
67 body
68 })
69}