rumtk_web/utils/
matcher.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::components::app_shell::app_shell;
22use crate::rumtk_web_get_component;
23use crate::utils::defaults::DEFAULT_ROBOT_TXT;
24use crate::utils::types::SharedAppConf;
25use crate::utils::{HTMLResult, RUMString};
26use axum::response::Html;
27use std::collections::HashMap;
28
29pub async fn default_robots_matcher(
30    _path: Vec<RUMString>,
31    _params: HashMap<RUMString, RUMString>,
32    _state: SharedAppConf,
33) -> HTMLResult {
34    Ok(Html::<String>::from(String::from(DEFAULT_ROBOT_TXT)))
35}
36
37pub async fn default_page_matcher(
38    path: Vec<RUMString>,
39    params: HashMap<RUMString, RUMString>,
40    state: SharedAppConf,
41) -> HTMLResult {
42    let path_components = match path.first() {
43        Some(x) => x.split('/').collect::<Vec<&str>>(),
44        None => Vec::new(),
45    };
46
47    app_shell(&path_components, &params, state.clone())
48}
49
50pub async fn default_component_matcher(
51    path: Vec<RUMString>,
52    params: HashMap<RUMString, RUMString>,
53    state: SharedAppConf,
54) -> HTMLResult {
55    let path_components = match path.first() {
56        Some(x) => x.split('/').collect::<Vec<&str>>(),
57        None => Vec::new(),
58    };
59
60    let component = match path_components.first() {
61        Some(component) => component,
62        None => return Err(RUMString::from("Missing component name to fetch!")),
63    };
64
65    let component = rumtk_web_get_component!(component);
66
67    component(&path_components[1..], &params, state.clone())
68}