Skip to main content

rumtk_web/components/html/
details.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::components::html::pre::{pre, Pre};
21use crate::components::html::summary::{summary, Summary};
22use crate::utils::defaults::{DEFAULT_TEXT_ITEM, PARAMS_CSS_CLASS};
23use crate::utils::types::{SharedAppState, URLParams, URLPath};
24use crate::{rumtk_web_get_config, rumtk_web_get_text_item, ComponentResult, RUMWebTemplate, RUMWebTemplateSafe};
25use rumtk_core::strings::RUMString;
26
27#[derive(RUMWebTemplate, Debug, Clone)]
28#[template(
29    source = "
30        {% if custom_css_enabled %}
31            <link href='/static/components/details.css' rel='stylesheet'>
32        {% endif %}
33        <details class='details-{{css_class}}'>
34            {{summary}}
35            {{contents}}
36        </details>
37    ",
38    ext = "html"
39)]
40pub struct Details {
41    summary: Summary,
42    contents: Pre,
43    css_class: RUMString,
44    custom_css_enabled: bool,
45}
46
47impl RUMWebTemplateSafe for Details {}
48
49pub fn details<'a>(_path_components: URLPath<'a, 'a>, params: URLParams<'a>, state: SharedAppState) -> ComponentResult<Details> {
50    let css_class = rumtk_web_get_text_item!(params, PARAMS_CSS_CLASS, DEFAULT_TEXT_ITEM).to_string();
51    let custom_css_enabled = rumtk_web_get_config!(state).flags.custom_css;
52
53    Ok(Details {
54        summary: summary(_path_components, params, state.clone())?,
55        contents: pre(_path_components, params, state)?,
56        css_class,
57        custom_css_enabled
58    })
59}