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, SharedAppConf, URLParams, URLPath};
25use crate::{rumtk_web_get_text_item, rumtk_web_render_html};
26use askama::Template;
27
28#[derive(Template, Debug)]
29#[template(
30 source = "
31 <style>
32
33 </style>
34 {% if custom_css_enabled %}
35 <link href='/static/components/div.css' rel='stylesheet'>
36 {% endif %}
37 <div class='div-{{css_class}}'>{{contents|safe}}</div>
38 ",
39 ext = "html"
40)]
41pub struct Div {
42 contents: RUMString,
43 css_class: RUMString,
44 custom_css_enabled: bool,
45}
46
47pub fn div(_path_components: URLPath, params: URLParams, state: SharedAppConf) -> HTMLResult {
48 let contents = rumtk_web_get_text_item!(params, PARAMS_CONTENTS, DEFAULT_TEXT_ITEM);
49 let css_class = rumtk_web_get_text_item!(params, PARAMS_CSS_CLASS, DEFAULT_TEXT_ITEM);
50
51 let custom_css_enabled = state.read().expect("Lock failure").custom_css;
52
53 rumtk_web_render_html!(Div {
54 contents: RUMString::from(contents),
55 css_class: RUMString::from(css_class),
56 custom_css_enabled
57 })
58}