rumtk_web/components/
mod.rs1use crate::utils::ComponentFunction;
22use rumtk_core::cache::{new_cache, LazyRUMCache};
23use rumtk_core::strings::RUMString;
24use rumtk_core::{rumtk_cache_get, rumtk_cache_push};
25
26pub mod app_body;
28pub mod app_head;
29pub mod app_shell;
30
31mod Form;
33mod contact_button;
34mod contact_card;
35pub mod div;
36mod footer;
37mod formatted_label;
38mod info_card;
39mod item_card;
40mod label;
41mod logo;
42mod navbar;
43mod navlink;
44mod portrait_card;
45mod socials;
46mod spacer;
47mod text_card;
48mod title;
49
50pub use Form::form_utils::*;
51
52pub type ComponentCache = LazyRUMCache<RUMString, ComponentFunction>;
53pub type UserComponentCacheItem = (RUMString, ComponentFunction);
54pub type UserComponents = Vec<UserComponentCacheItem>;
55
56static mut component_cache: ComponentCache = new_cache();
57
58pub fn register_component(name: &str, component_fxn: ComponentFunction) {
59 let key = RUMString::from(name);
60 rumtk_cache_push!(&mut component_cache, &key, &component_fxn);
61}
62
63pub fn get_component(name: &str) -> Option<&ComponentFunction> {
64 rumtk_cache_get!(&mut component_cache, &RUMString::from(name))
65}
66
67pub fn init_components(user_components: &UserComponents) {
68 register_component("logo", logo::logo);
70 register_component("info_card", info_card::info_card);
71 register_component("portrait_card", portrait_card::portrait_card);
72 register_component("title", title::title);
73 register_component("footer", footer::footer);
74 register_component("navbar", navbar::navbar);
75 register_component("contact_card", contact_card::contact_card);
76 register_component("contact_button", contact_button::contact_button);
77 register_component("socials", socials::socials);
78 register_component("item_card", item_card::item_card);
79 register_component("navlink", navlink::navlink);
80 register_component("label", label::label);
81 register_component("formatted_label", formatted_label::formatted_label);
82 register_component("text_card", text_card::text_card);
83 register_component("form", Form::form::form);
84 register_component("spacer", spacer::spacer);
85 register_component("div", div::div);
86
87 for itm in user_components {
89 let (name, value) = itm;
90 register_component(name, *value);
91 }
92}
93
94#[macro_export]
95macro_rules! rumtk_web_register_component {
96 ( $key:expr, $fxn:expr ) => {{
97 use $crate::components::register_component;
98 register_component($key, $fxn)
99 }};
100}
101
102#[macro_export]
103macro_rules! rumtk_web_get_component {
104 ( $key:expr ) => {{
105 use $crate::components::get_component;
106 get_component($key)
107 }};
108}
109
110#[macro_export]
111macro_rules! rumtk_web_init_components {
112 ( $components:expr ) => {{
113 use $crate::components::init_components;
114 init_components($components)
115 }};
116}