rumtk_web/components/
app_head.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::static_components::{css::css, fontawesome::fontawesome, htmx::htmx, meta::meta};
22use crate::utils::types::{HTMLResult, RUMString, SharedAppConf, URLParams, URLPath};
23use crate::{rumtk_web_render_component, rumtk_web_render_html};
24use askama::Template;
25
26#[derive(Template)]
27#[template(
28    source = "
29        <head>
30            {{meta|safe}}
31            {{css|safe}}
32            {{fontawesome|safe}}
33            {{htmx|safe}}
34        </head>
35    ",
36    ext = "html"
37)]
38pub struct AppShellHead {
39    meta: RUMString,
40    css: RUMString,
41    fontawesome: RUMString,
42    htmx: RUMString,
43}
44
45///
46///     !!!!!!!!!!!!!!!!!!!!!!!WARNING!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
47///
48///      The snippet below will add key static imports relying on CDN free bandwidth where possible.
49///      Keep in mind this can be dangerous security wise if the CDN or DNS services are manipulated
50///      because we will fallback on a local file version that may be of an older version.
51///
52///      It is not ideal but it will allow continuance of service for websites during CDN outages
53///      which do happen.
54///
55pub fn app_head(_path_components: URLPath, _params: URLParams, state: SharedAppConf) -> HTMLResult {
56    //Let's render the head component
57    let html_meta = rumtk_web_render_component!(meta, state);
58
59    //Let's render the head component
60    let html_css = rumtk_web_render_component!(css);
61
62    //Let's render the head component
63    let html_fontawesome = rumtk_web_render_component!(fontawesome);
64
65    //Let's render the head component
66    let html_htmx = rumtk_web_render_component!(htmx);
67
68    rumtk_web_render_html!(AppShellHead {
69        meta: html_meta,
70        css: html_css,
71        fontawesome: html_fontawesome,
72        htmx: html_htmx
73    })
74}