rumtk_web/utils/
matcher.rs1use 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, ¶ms, 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 match component {
68 Some(cf) => cf(&path_components[1..], ¶ms, state.clone()),
69 _ => Ok(Html("<div></div>".to_string())),
70 }
71}