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