rumtk-web 0.9.2

Web framework part of the RUMTK framework that attempts to simplify and expedite dashboard development in Healthcare.
Documentation
/*
 * rumtk attempts to implement HL7 and medical protocols for interoperability in medicine.
 * This toolkit aims to be reliable, simple, performant, and standards compliant.
 * Copyright (C) 2025  Luis M. Santos, M.D. <lsantos@medicalmasses.com>
 * Copyright (C) 2025  Ethan Dixon
 * Copyright (C) 2025  MedicalMasses L.L.C. <contact@medicalmasses.com>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */
use crate::{rumtk_web_get_config, ComponentResult, RUMWebTemplate, RUMWebTemplateSafe, SharedAppState};

#[derive(Debug)]
pub struct FontAwesomeCSSElement {
    file: &'static str,
    version: &'static str,
    sha: &'static str,
}

#[derive(RUMWebTemplate, Debug)]
#[template(
    source = "
        {% if enable %}
            {% for e in elements %}
                <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}}\";' />
                <noscript><link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/font-awesome/{{e.version}}/css/{{e.file}}'></noscript>
            {% endfor %}
        {% endif %}
    ",
    ext = "html"
)]
pub struct FontAwesome {
    elements: Vec<FontAwesomeCSSElement>,
    enable: bool
}

impl RUMWebTemplateSafe for FontAwesome {}

pub fn fontawesome(state: SharedAppState) -> ComponentResult<FontAwesome> {
    let elements = vec![
        FontAwesomeCSSElement {
            file: "fontawesome.min.css",
            version: "7.0.1",
            sha: "sha512-M5Kq4YVQrjg5c2wsZSn27Dkfm/2ALfxmun0vUE3mPiJyK53hQBHYCVAtvMYEC7ZXmYLg8DVG4tF8gD27WmDbsg==",
        },
        FontAwesomeCSSElement {
            file: "regular.min.css",
            version: "7.0.1",
            sha: "sha512-x3gns+l9p4mIK7vYLOCUoFS2P1gavFvnO9Its8sr0AkUk46bgf9R51D8xeRUwCSk+W93YbXWi19BYzXDNBH5SA==",
        },
        FontAwesomeCSSElement {
            file: "brands.min.css",
            version: "7.0.1",
            sha: "sha512-WxpJXPm/Is1a/dzEdhdaoajpgizHQimaLGL/QqUIAjIihlQqlPQb1V9vkGs9+VzXD7rgI6O+UsSKl4u5K36Ydw==",
        },
    ];
    let enable = rumtk_web_get_config!(state).flags.enable_icons;

    Ok(FontAwesome { elements, enable })
}