rumtk_web/components/
app_body.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  MedicalMasses L.L.C.
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
20 */
21use crate::utils::defaults::DEFAULT_TEXT_ITEM;
22use crate::utils::types::{HTMLResult, RUMString, SharedAppConf, URLParams, URLPath};
23use crate::{
24    rumtk_web_collect_page, rumtk_web_get_param, rumtk_web_get_text_item,
25    rumtk_web_render_component, rumtk_web_render_html,
26};
27use askama::Template;
28
29#[derive(Template)]
30#[template(
31    source = "
32    {% for element in elements %}
33        {{ element|safe }}
34    {% endfor %}
35    ",
36    ext = "html"
37)]
38pub struct AppBodyContents<'a> {
39    elements: &'a [RUMString],
40}
41
42fn app_body_contents(elements: &[RUMString]) -> HTMLResult {
43    rumtk_web_render_html!(AppBodyContents { elements })
44}
45
46#[derive(Template)]
47#[template(
48    source = "
49        <body class='f12 {{theme}}'>
50            {{header|safe}}
51            <div class='' id='content'>
52                <div class='gap20'>
53    
54                </div>
55                {{body|safe}}
56                <div class='gap5'>
57    
58                </div>
59            </div>
60            {{footer|safe}}
61        </body>
62    ",
63    ext = "html"
64)]
65pub struct AppBody {
66    theme: RUMString,
67    header: RUMString,
68    body: RUMString,
69    footer: RUMString,
70}
71
72pub fn app_body(path_components: URLPath, params: URLParams, state: SharedAppConf) -> HTMLResult {
73    let page: RUMString =
74        rumtk_web_get_param!(path_components, 0, RUMString::from(DEFAULT_TEXT_ITEM));
75    let theme = rumtk_web_get_text_item!(params, "theme", DEFAULT_TEXT_ITEM);
76
77    //Let's render the body to html
78    let body_components = rumtk_web_collect_page!(page, state);
79    let body =
80        rumtk_web_render_component!(|| -> HTMLResult { app_body_contents(&body_components) });
81
82    //Let's render the header and footer
83    //<div class="" hx-get="/component/navbar" hx-target="#navbar" hx-trigger="load" id="navbar"></div>
84    let header = rumtk_web_render_component!("navbar", [("", "")], state);
85    //<div class="" hx-get="/component/footer?social_list=linkedin,github" hx-target="#footer" hx-trigger="load" id="footer"></div>
86    let footer = rumtk_web_render_component!("footer", [("social_list", "linkedin,github")], state);
87
88    rumtk_web_render_html!(AppBody {
89        theme: RUMString::from(theme),
90        header,
91        body,
92        footer
93    })
94}