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
pub use cratedo_replace;
pub use cratedo_html;
pub use cratedo_xml;
pub use cratedo_json;
/// ### do_forloop(vector, befor_items, befor_item, after_item, after_items)
///
/// Html Template Function
///
/// The `do_forloop` function takes a vector of items and formats them according to specified prefixes
/// and suffixes for the entire collection, as well as for each individual item. The output
/// is a concatenated string representation of the items, encapsulated within the provided
/// separator strings.
///
/// ### Parameters
/// - `vector`: A slice of items to format, where each item must implement the `Display` trait.
/// - `befor_items`: A string that will be prefixed before the whole collection of items.
/// - `befor_item`: A string that will be prefixed before each individual item.
/// - `after_item`: A string that will be suffixed after each individual item.
/// - `after_items`: A string that will be suffixed after the whole collection of items.
///
/// ### Examples
/// ```rust
/// use cans::content::do_forloop;
///
/// let items = vec!["Apples", "Bananas", "Cherries"];
/// let result = do_forloop(&items, "<ul>", "<li>", "</li>", "</ul>");
/// assert_eq!(result, "<ul><li>Apples</li><li>Bananas</li><li>Cherries</li></ul>");
///
/// let float_vector = vec![1.0, 2.0, 3.0];
/// let forloop_float = do_forloop(&float_vector, "", "", "", "");
/// assert_eq!(forloop_float, "123");
/// ```
/// <small>End Fun Doc</small>
/// ### do_text(t)
///
/// Text Conversion Function
///
/// The `do_text` function takes a string slice representing a text and converts it
/// into an owned `String`. This function is typically used for text elements,
/// including titles and other content that are incorporated into HTML templates,
/// ensuring proper ownership and allocation of string data.
///
/// ### Parameters
/// - `t`: A string slice (`&str`) representing the text to be used in
/// HTML templates.
///
/// ### Examples
/// ```rust
/// use cans::content::do_text;
///
/// let title = "Home";
/// let result = do_text(title);
/// assert_eq!(result, "Home");
///
/// let color = do_text("#000");
/// assert_eq!(color, "#000");
/// ```
///
/// ### Usage Context
/// This function is particularly useful in the context of generating dynamic HTML
/// pages where text elements, such as titles, may need to be included as part
/// of an HTML document or template. For instance, it is used in the `do_home_page`
/// function to set the title in the `HOME_TEMPLATE` HTML document:
/// ```rust
/// use cans::content::{do_html, do_text};
///
/// pub const HEAD: &str = r#"<head>
/// <meta charset="UTF-8">
/// <title>{{page_title}} Page</title>
/// </head>"#;
///
/// pub const HOME_TEMPLATE: &str = r#"<!DOCTYPE html>
/// <html>
/// {{HEAD}}
/// <body>
/// Home Page
/// </body>
/// </html>"#;
///
/// pub fn do_home_page() -> String {
/// do_html!(HOME_TEMPLATE, HEAD = HEAD, page_title = do_text("Home"))
/// }
///
/// pub const ABOUT_TEMPLATE: &str = r#"<!DOCTYPE html>
/// <html>
/// {{HEAD}}
/// <body>
/// About Page
/// </body>
/// </html>"#;
///
/// pub fn do_about_page() -> String {
/// do_html!(ABOUT_TEMPLATE, HEAD = HEAD, page_title = do_text("About"))
/// }
/// ```
///
/// This ensures that the text is properly formatted and owned, allowing for
/// efficient rendering and manipulation in templates.
///
/// <small>End Fun Doc</small>
/// ### alpine(version)
///
/// Alpine.js Script Tag Generator
///
/// The `alpine` function generates an HTML `<script>` tag string that loads the specified version
/// of the Alpine.js library from a CDN. You provide the version as a string slice, and the function
/// returns a formatted string containing the script tag with the correct version embedded.
///
/// ### Parameters
/// - `version`: A string slice (`&str`) representing the version of Alpine.js to include,
/// for example `"3.15.0"` or `"latest"` for the most recent version.
///
/// ### Examples
/// ```rust
/// use cans::content::alpine;
///
/// let script_tag = alpine("3.15.0");
/// assert_eq!(script_tag, r#"<script defer src="https://unpkg.com/alpinejs@3.15.0/dist/cdn.min.js"></script>"#);
///
/// let latest_script_tag = alpine("latest");
/// assert_eq!(latest_script_tag, r#"<script defer src="https://unpkg.com/alpinejs@latest/dist/cdn.min.js"></script>"#);
/// ```
///
/// ### Usage Context
/// This function is useful when dynamically generating HTML pages or templates that need to include
/// the Alpine.js library. By passing in the desired version, you can easily control which version
/// of Alpine is loaded, facilitating version management and updates in your web projects.
///
/// For example, in a server-side rendered HTML template:
/// ```rust
/// use cans::content::alpine;
/// let head_content = format!("<head>{}", alpine("3.15.0"));
/// ```
///
/// This ensures the correct script tag is embedded in the HTML, enabling Alpine.js functionalities.
///
/// <small>End Fun Doc</small>
/// ### chart_js (version)
///
/// Chart.js Script Tag Generator
///
/// The `chart_js` function generates an HTML `<script>` tag string that loads the specified version
/// of the Chart.js library from a CDN. You provide the version as a string slice, and the function
/// returns a formatted string containing the script tag with the correct version embedded.
///
/// ### Parameters
/// - `version`: A string slice (`&str`) representing the version of Chart.js to include,
/// for example `"4.2.1"` or `"latest"` for the most recent version.
///
/// ### Examples
/// ```rust
/// use cans::content::chart_js;
///
/// let script_tag = chart_js("4.2.1");
/// assert_eq!(script_tag, r#"<script src="https://cdn.jsdelivr.net/npm/chart.js@4.2.1/dist/chart.umd.min.js"></script>"#);
///
/// let latest_script_tag = chart_js("latest");
/// assert_eq!(latest_script_tag, r#"<script src="https://cdn.jsdelivr.net/npm/chart.js@latest/dist/chart.umd.min.js"></script>"#);
/// ```
///
/// ### Usage Context
/// This function is useful when dynamically generating HTML pages or templates that need to include
/// the Chart.js library. By passing in the desired version, you can easily control which version
/// of Chart.js is loaded, facilitating version management and updates in your web projects.
///
/// For example, in a server-side rendered HTML template:
/// ```rust
/// use cans::content::chart_js;
/// let head_content = format!("<head>{}</head>", chart_js("4.2.1"));
/// ```
///
/// This ensures the correct script tag is embedded in the HTML, enabling Chart.js functionalities.
///
/// <small>End Fun Doc</small>