rumtk_web/components/
div.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  Nick Stephenson
6 * Copyright (C) 2025  Ethan Dixon
7 * Copyright (C) 2025  MedicalMasses L.L.C.
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
22 */
23use crate::utils::defaults::{DEFAULT_TEXT_ITEM, PARAMS_CONTENTS, PARAMS_CSS_CLASS};
24use crate::utils::types::{HTMLResult, RUMString, SharedAppState, URLParams, URLPath};
25use crate::{rumtk_web_get_text_item, rumtk_web_render_html, RUMWebTemplate};
26use askama::Template;
27
28#[derive(RUMWebTemplate, Debug)]
29#[template(
30    source = "
31        {% if custom_css_enabled %}
32            <link href='/static/components/div.css' rel='stylesheet'>
33        {% endif %}
34        <div class='div-{{css_class}}'>{{contents|safe}}</div>
35    ",
36    ext = "html"
37)]
38pub struct Div {
39    contents: RUMString,
40    css_class: RUMString,
41    custom_css_enabled: bool,
42}
43
44pub fn div(_path_components: URLPath, params: URLParams, state: SharedAppState) -> HTMLResult {
45    let contents = rumtk_web_get_text_item!(params, PARAMS_CONTENTS, DEFAULT_TEXT_ITEM);
46    let css_class = rumtk_web_get_text_item!(params, PARAMS_CSS_CLASS, DEFAULT_TEXT_ITEM);
47
48    let custom_css_enabled = state.read().expect("Lock failure").config.custom_css;
49
50    rumtk_web_render_html!(Div {
51        contents: RUMString::from(contents),
52        css_class: RUMString::from(css_class),
53        custom_css_enabled
54    })
55}