1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
/*
* rumtk attempts to implement HL7 and medical protocols for interoperability in medicine.
* This toolkit aims to be reliable, simple, performant, and standards compliant.
* Copyright (C) 2025 Luis M. Santos, M.D. <lsantos@medicalmasses.com>
* Copyright (C) 2025 Ethan Dixon
* Copyright (C) 2025 MedicalMasses L.L.C. <contact@medicalmasses.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
use crateHTMLResult;
use crate::;
use ;
use ;
use OnceLock;
pub static MARKDOWN_OPTIONS: = new;
pub static MARKDOWN_OPTIONS_INIT: fn = ;
const TEMPLATE_NEWLINE_COMPONENT_PATTERN: = ;
const TEMPLATE_NEWLINE_COMPONENT_INNER_PATTERN: =
;
///
/// This function trims excess newlines and whitespacing outside tag block (e.g. `<div></div>`). The
/// idea is to cleanup the rendered template which picks up extra characters due to the way string
/// literals work in proc macros.
///
/// This is not meant to be used as a sanitization function!
///
/// This function consumes the input string!!!!!
///
/// ## Example
/// ```
/// use rumtk_web::rumtk_web_trim_rendered_html;
/// use rumtk_web::testdata::{TRIMMED_HTML_RENDER, UNTRIMMED_HTML_RENDER};
///
/// let expected = String::from(TRIMMED_HTML_RENDER);
/// let input = String::from(UNTRIMMED_HTML_RENDER);
/// let filtered = rumtk_web_trim_rendered_html(input);
///
/// assert_eq!(filtered, expected, "Template render trim failed!");
/// ```
///
///
/// Render the given component template into an `HTML Body response` or a `URL Redirect response`.
/// If you provide the [RUMWebRedirect] in the `url` parameter configured for redirection, then we
/// return the redirection as the response. Otherwise, we render the HTML and save it in the response.
///
/// ## Example
/// ```
/// use rumtk_web::{HTMLBody, RUMString, RUMWebRedirect, RUMWebResponse};
/// use rumtk_web::RUMWebTemplate;
/// use rumtk_web::rumtk_web_render_html;
///
/// #[derive(RUMWebTemplate)]
/// #[template(
/// source = "<div></div>",
/// ext = "html"
/// )]
/// struct Div { }
///
/// let result = rumtk_web_render_html(Div{}, RUMWebRedirect::None).unwrap();
/// let expected = RUMWebResponse::into_get_response("<div></div>");
///
/// assert_eq!(result, expected, "Test Div template rendered improperly!");
/// ```
///
///
/// Render component into an HTML Response Body of type [HTMLResult]. This macro is a bit more complex.
/// Depending on the arguments passed to it, it can
///
/// 1. Call a component function that receives exactly 0 parameters.
/// 2. Call a component function that only receives the [SharedAppState](crate::utils::SharedAppState) handle as its only parameter.
/// 3. Call a component function that can accept the standard set of parameters (`path`, `params`, and `app_state`). However, the Path is set to empty.
/// 4. Call a component function that can accept the standard set of parameters (`path`, `params`, and `app_state`). All of these parameters are passed through to the function.
///
/// The reason for this set of behaviors is that we have standard component functions which are found in [components](crate::components) modules.
/// These functions are of type [ComponentFunction](crate::utils::ComponentFunction) and the expected parameters are as follows:
///
/// 1. `path` => [URLPath](crate::utils::URLPath)
/// 2. `params` => [URLParams](crate::utils::URLParams)
/// 3. `app_state` => [SharedAppState](crate::utils::SharedAppState)
///
/// The component functions are the bread and butter of the framework and are what are expected from consumers of
/// this library. They get registered to an internal `Map` that we use as a sort of `vTable` to dispatch the correct user function.
/// **In this case, the component function parameter for this macro is a stringview type since we perform the lookup automatically!**
///
/// The reason for the other usages is that we also have static components whose only purpose are to define
/// pre-selected items to help make web apps come together in an easy to use package. These include the
/// `htmx` and `fontawesome` imports. Perhaps, we will open up this facility to the user in later iterations of the framework
/// to make it easy to override and include other static assets and maybe for prefetch and optimization purposes.
///
/// ## Examples
///
/// ### Simple Component Render
/// ```
/// use rumtk_web::static_components::css::css;
/// use rumtk_web::rumtk_web_render_component;
///
/// let rendered = rumtk_web_render_component!(css);
/// let expected = "<link rel='stylesheet' href='/static/css/bundle.min.css' onerror='this.onerror=null;this.href='/static/css/bundle.css';' />";
///
/// assert_eq!(rendered, expected, "Commponent rendered improperly!");
/// ```
///
/// ### Component Render with Shared State
/// ```
/// use rumtk_web::SharedAppState;
/// use rumtk_web::static_components::meta::meta;
/// use rumtk_web::utils::testdata::TRIMMED_HTML_RENDER_META;
/// use rumtk_web::rumtk_web_render_component;
///
/// let state = SharedAppState::default();
/// let rendered = rumtk_web_render_component!(meta, state);
///
/// assert_eq!(rendered, TRIMMED_HTML_RENDER_META, "Commponent rendered improperly!");
/// ```
///
/// ### Component Render with Standard Parameters
/// ```
/// use rumtk_web::SharedAppState;
/// use rumtk_web::defaults::PARAMS_TITLE;
/// use rumtk_web::utils::testdata::TRIMMED_HTML_TITLE_RENDER;
/// use rumtk_web::{rumtk_web_render_component, rumtk_web_init_components};
///
/// rumtk_web_init_components!(None);
/// let params = [
/// (PARAMS_TITLE, "Hello World!")
/// ];
/// let state = SharedAppState::default();
/// let rendered = rumtk_web_render_component!("title", params, state).unwrap().to_rumstring();
///
/// assert_eq!(rendered, TRIMMED_HTML_TITLE_RENDER, "Commponent rendered improperly!");
/// ```
///
///
/// Generates the HTML page as prescribed by the input `page` function of type [HTMLResult].
///
/// ## Example
/// ```
/// use rumtk_core::strings::RUMString;
/// use rumtk_web::pages::index::index;
/// use rumtk_web::{rumtk_web_render_component, rumtk_web_render_page_contents, SharedAppState};
///
/// let app_state = SharedAppState::default();
/// let mydiv = rumtk_web_render_component!("div", [("type", "story")], app_state).unwrap().to_rumstring();
///
/// let expected_page = RUMString::new("<div class='div-default'>default</div>");
/// let page_response = rumtk_web_render_page_contents!(
/// &vec![
/// mydiv
/// ]
/// ).expect("Page rendered!");
/// let rendered_page = page_response.to_rumstring();
///
/// assert_eq!(rendered_page, expected_page, "Page was not rendered properly!")
/// ```
///
///
/// Generate redirect response automatically instead of actually rendering an HTML page.
///
/// ## Examples
///
/// ### Temporary Redirect
/// ```
/// use rumtk_web::RUMStringConversions;
/// use rumtk_web::utils::response::RUMWebRedirect;
/// use rumtk_web::rumtk_web_render_redirect;
///
/// let url = "http://localhost/redirected";
/// let redirect = rumtk_web_render_redirect!(RUMWebRedirect::RedirectTemporary(url.to_rumstring()));
///
/// let result = redirect.expect("Failed to create the redirect response!").get_url();
///
/// assert_eq!(result, url, "Url in Response object does not match the expected!");
///
/// ```
///
///
///
/// If using raw strings, do not leave an extra line. The first input must have characters, or you
/// will get <pre><code> blocks regardless of what you do.
///
/// ## Example
/// ```
/// use rumtk_web::rumtk_web_render_markdown;
///
/// let md = r###"
///**Hello World**
/// "###;
/// let expected_html = "<p><strong>Hello World</strong></p>\n";
///
/// let result = rumtk_web_render_markdown!(md);
///
/// assert_eq!(result, expected_html, "The rendered markdown does not match the expected HTML!");
/// ```
///