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
/// ### do_replace!($content, $key, and $val)
///
/// Macro Rules
///
/// The `do_replace` macro takes any content string or data (e.g., code, file content, templates)
/// along with key-value pairs and replaces placeholders in the content (formatted as `{{key}}`) with the corresponding values.
/// This macro is highly versatile and can manipulate any content of any programming language or file by substituting placeholders.
///
/// ### Parameters
/// - `$content`: The content string containing placeholders for substitution (e.g., `"<p>Hello, {{name}}!</p>"`).
/// - `$key`: The identifier for each placeholder in the content (e.g., `name`).
/// - `$val`: The value that replaces the corresponding placeholder in the content (e.g., `"Alice"`).
///
/// ### Examples
/// ```rust
/// // use cans::content::do_replace;
/// use cans::do_replace;
///
/// let template = "<p>Hello, {{name}}! Welcome to {{place}}.</p>";
/// let result = do_replace!(template, name = "Dear", place = "CANS Template");
/// assert_eq!(result, "<p>Hello, Dear! Welcome to CANS Template.</p>");
/// ```
///
/// This macro can be used to update any content dynamically by replacing placeholders with actual values.
///
/// #### Example: Creating a new macro using `do_replace!`
///
/// Macros for specific content types can be defined by wrapping `do_replace!`.
/// For example, to create a macro for CSS content:
/// ```rust
/// // use cans::content::do_replace;
/// use cans::do_replace;
///
/// #[macro_export]
/// macro_rules! do_html {
/// ($content:expr, $($key:ident = $val:expr),*) => {
/// $crate::do_replace!($content, $($key = $val),*)
/// };
/// }
/// ```
/// Now, `do_css!` can be used to easily replace placeholders in CSS templates.
///
/// <small>End Doc</small>
/// ### do_html!($content, $key, and $val)
///
/// Macro Rules
///
/// The `do_html` macro takes HTML string content along with key-value pairs and replaces placeholders in the HTML (formatted as `{{key}}`) with the corresponding values.
/// It returns the processed HTML string with the substitutions applied.
///
/// ### Parameters
/// - `$content`: The HTML string content containing placeholders for substitution (e.g., `"<p>Hello, {{name}}!</p>"`).
/// - `$key`: The identifier for each placeholder in the HTML (e.g., `name`).
/// - `$val`: The value that replaces the corresponding placeholder in the HTML (e.g., `"Alice"`).
///
/// ### Examples
/// ```rust
/// // use cans::content::do_html;
/// use cans::do_html;
///
/// let template = "<p>Hello, {{name}}! Welcome to {{place}}.</p>";
/// let result = do_html!(template, name = "Dear", place = "CANS Template");
/// assert_eq!(result, "<p>Hello, Dear! Welcome to CANS Template.</p>");
/// ```
/// <small>End Doc</small>
/// ### do_xml!($content, $key, and $val)
///
/// Macro Rules
///
/// The `do_xml` macro takes XML string content along with key-value pairs and replaces placeholders in the XML (formatted as `{{key}}`) with the corresponding values.
/// It returns the processed XML string with the substitutions applied.
///
/// ### Parameters
/// - `$content`: The XML string content containing placeholders for substitution (e.g., `"<p>Hello, {{name}}!</p>"`).
/// - `$key`: The identifier for each placeholder in the XML (e.g., `name`).
/// - `$val`: The value that replaces the corresponding placeholder in the XML (e.g., `"Alice"`).
///
/// ### Examples
/// ```rust
/// // use cans::content::do_xml;
/// use cans::do_xml;
///
/// let xml_content = "<note><to>{{recipient}}</to></note>";
/// let xml_result = do_xml!(xml_content, recipient = "Ahmed");
/// assert_eq!(xml_result, "<note><to>Ahmed</to></note>");
/// ```
/// <small>End Doc</small>
/// ### do_json!($content, $key1 = $val1, $key2 = $val2, ...)
///
/// Macro Rules
///
/// The `do_json` macro takes a JSON string with placeholders and replaces them with provided values.
/// It is an example of creating a specific macro wrapper for JSON content using `do_replace!`.
///
/// ### Parameters
/// - `$content`: The JSON string containing placeholders (e.g., `"{\"name\": \"{{name}}\"}"`).
/// - `$key`: The placeholder identifier (e.g., `name`).
/// - `$val`: The value to replace the placeholder (e.g., `"Ahmed"`).
///
//// ### Examples
///
/// ```rust
/// // use cans::content::do_json;
/// use cans::do_json;
///
/// let json_content = r##"{"greeting": "{{greeting}}", "name": "{{name}}"}"##;
/// let json_result = do_json!(json_content, greeting = "Hi", name = "Ahmed");
/// assert_eq!(json_result, r##"{"greeting": "Hi", "name": "Ahmed"}"##);
/// ```
///
/// <small>End Doc</small>