Skip to main content

rumtk_web/components/app/
fontawesome.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. <lsantos@medicalmasses.com>
5 * Copyright (C) 2025  Ethan Dixon
6 * Copyright (C) 2025  MedicalMasses L.L.C. <contact@medicalmasses.com>
7 *
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program 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
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
20 */
21use crate::{rumtk_web_get_config, ComponentResult, RUMWebTemplate, RUMWebTemplateSafe, SharedAppState};
22
23#[derive(Debug)]
24pub struct FontAwesomeCSSElement {
25    file: &'static str,
26    version: &'static str,
27    sha: &'static str,
28}
29
30#[derive(RUMWebTemplate, Debug)]
31#[template(
32    source = "
33        {% if enable %}
34            {% for e in elements %}
35                <link rel='preload' as='style' href='https://cdnjs.cloudflare.com/ajax/libs/font-awesome/{{e.version}}/css/{{e.file}}' integrity='{{e.sha}}' crossorigin='anonymous' referrerpolicy='no-referrer'  onload='this.rel=\"stylesheet\"' onerror='this.onerror=null;this.href=\"/static/fontawesome-free/css/{{e.file}}\";' />
36                <noscript><link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/font-awesome/{{e.version}}/css/{{e.file}}'></noscript>
37            {% endfor %}
38        {% endif %}
39    ",
40    ext = "html"
41)]
42pub struct FontAwesome {
43    elements: Vec<FontAwesomeCSSElement>,
44    enable: bool
45}
46
47impl RUMWebTemplateSafe for FontAwesome {}
48
49pub fn fontawesome(state: SharedAppState) -> ComponentResult<FontAwesome> {
50    let elements = vec![
51        FontAwesomeCSSElement {
52            file: "fontawesome.min.css",
53            version: "7.0.1",
54            sha: "sha512-M5Kq4YVQrjg5c2wsZSn27Dkfm/2ALfxmun0vUE3mPiJyK53hQBHYCVAtvMYEC7ZXmYLg8DVG4tF8gD27WmDbsg==",
55        },
56        FontAwesomeCSSElement {
57            file: "regular.min.css",
58            version: "7.0.1",
59            sha: "sha512-x3gns+l9p4mIK7vYLOCUoFS2P1gavFvnO9Its8sr0AkUk46bgf9R51D8xeRUwCSk+W93YbXWi19BYzXDNBH5SA==",
60        },
61        FontAwesomeCSSElement {
62            file: "brands.min.css",
63            version: "7.0.1",
64            sha: "sha512-WxpJXPm/Is1a/dzEdhdaoajpgizHQimaLGL/QqUIAjIihlQqlPQb1V9vkGs9+VzXD7rgI6O+UsSKl4u5K36Ydw==",
65        },
66    ];
67    let enable = rumtk_web_get_config!(state).flags.enable_icons;
68
69    Ok(FontAwesome { elements, enable })
70}