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