Skip to main content

rumtk_web/components/html/
anchor.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) 2026  Luis M. Santos, M.D. <lsantos@medicalmasses.com>
5 *     Copyright (C) 2026  MedicalMasses L.L.C. <contact@medicalmasses.com>
6 *
7 *     This program is free software: you can redistribute it and/or modify
8 *     it under the terms of the GNU General Public License as published by
9 *     the Free Software Foundation, either version 3 of the License, or
10 *     (at your option) any later version.
11 *
12 *     This program 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
15 *     GNU General Public License for more details.
16 *
17 *     You should have received a copy of the GNU General Public License
18 *     along with this program.  If not, see <https://www.gnu.org/licenses/>.
19 */
20use crate::defaults::PARAMS_ID;
21use crate::utils::defaults::{DEFAULT_TEXT_ITEM, PARAMS_CSS_CLASS};
22use crate::utils::types::{SharedAppState, URLParams, URLPath};
23use crate::{rumtk_web_get_config, rumtk_web_get_text_item, ComponentResult, RUMWebTemplate, RUMWebTemplateSafe};
24use rumtk_core::strings::RUMString;
25
26#[derive(RUMWebTemplate, Debug)]
27#[template(
28    source = "
29        {% if custom_css_enabled %}
30            <link href='/static/components/anchor.css' rel='preload' as='style' >
31            <link href='/static/components/a.css' rel='stylesheet'>
32        {% endif %}
33        <a class='anchor-{{css_class}}' href='#{{id}}'></div>
34    ",
35    ext = "html"
36)]
37pub struct Anchor {
38    id: RUMString,
39    css_class: RUMString,
40    custom_css_enabled: bool,
41}
42
43impl RUMWebTemplateSafe for Anchor {}
44
45pub fn anchor<'a>(_path_components: URLPath<'a, 'a>, params: URLParams<'a>, state: SharedAppState) -> ComponentResult<Anchor> {
46    let id = rumtk_web_get_text_item!(params, PARAMS_ID, DEFAULT_TEXT_ITEM).to_string();
47    let css_class = rumtk_web_get_text_item!(params, PARAMS_CSS_CLASS, DEFAULT_TEXT_ITEM).to_string();
48
49    let custom_css_enabled = rumtk_web_get_config!(state).flags.custom_css;
50
51    Ok(Anchor {
52        id,
53        css_class,
54        custom_css_enabled
55    })
56}
57
58pub fn a<'a>(_path_components: URLPath<'a, 'a>, params: URLParams<'a>, state: SharedAppState) -> ComponentResult<Anchor> {
59    anchor(_path_components, params, state)
60}