1pub mod app;
22pub mod conf;
23pub mod defaults;
24pub mod matcher;
25pub mod render;
26pub mod types;
27
28pub use render::*;
29pub use types::*;
30
31#[macro_export]
32macro_rules! rumtk_web_get_text_item {
33 ( $store:expr, $item:expr, $default:expr) => {{
34 match $store.get($item) {
35 Some(x) => x,
36 None => $default,
37 }
38 }};
39}
40
41#[macro_export]
42macro_rules! rumtk_web_get_param_eq {
43 ( $params:expr, $indx:expr, $comparison:expr, $default:expr ) => {{
44 match $params.get($indx) {
45 Some(x) => *x == $comparison,
46 None => $default,
47 }
48 }};
49}
50
51#[macro_export]
52macro_rules! rumtk_web_get_param {
53 ( $params:expr, $indx:expr, $default:expr ) => {{
54 match $params.get($indx) {
55 Some(x) => x.parse().unwrap_or($default),
56 None => $default,
57 }
58 }};
59}
60
61#[macro_export]
62macro_rules! rumtk_web_params_map {
63 ( $params:expr ) => {{
64 use std::collections::HashMap;
65 let mut params = HashMap::<RUMString, RUMString>::with_capacity($params.len());
66
67 for (k, v) in $params.iter() {
68 params.insert(
69 RUMString::from(k.to_string()),
70 RUMString::from(v.to_string()),
71 );
72 }
73 params
74 }};
75}
76
77#[macro_export]
78macro_rules! rumtk_web_collect_page {
79 ( $page:expr, $app_state:expr ) => {{
80 use $crate::rumtk_web_get_page;
81 use $crate::utils::types::{PageFunction, RenderedPageComponents};
82
83 let page = match rumtk_web_get_page!(&$page) {
84 Some(x) => x,
85 None => &(|_| -> RenderedPageComponents { vec![] } as PageFunction),
86 };
87
88 page($app_state.clone())
89 }};
90}
91
92#[macro_export]
93macro_rules! rumtk_web_fetch {
94 ( $matcher:expr ) => {{
95 use axum::extract::{Path, Query, State};
96 use axum::response::Html;
97 use $crate::utils::types::{RouterAppConf, RouterComponents, RouterParams};
98
99 async |Path(path_params): RouterComponents,
100 Query(params): RouterParams,
101 State(state): RouterAppConf|
102 -> Html<String> {
103 match $matcher(path_params, params, state).await {
104 Ok(res) => res,
105 Err(e) => {
106 error!("{}", e);
107 return Html(String::default());
108 }
109 }
110 }
111 }};
112}