windjammer_ui/components/generated/
html_elements.rs

1#![allow(clippy::all)]
2#![allow(noop_method_call)]
3use super::traits::Renderable;
4
5#[derive(Debug, Clone, PartialEq, Eq, Default)]
6pub struct Div {
7    pub children: Vec<String>,
8    pub class: String,
9    pub style: String,
10    pub id: String,
11}
12
13impl Div {
14    #[inline]
15    pub fn new() -> Div {
16        Div {
17            children: Vec::new(),
18            class: String::new(),
19            style: String::new(),
20            id: String::new(),
21        }
22    }
23    #[inline]
24    pub fn child<T: Renderable>(mut self, component: T) -> Div {
25        self.children.push(component.render());
26        self
27    }
28    #[inline]
29    pub fn text(mut self, text: String) -> Div {
30        self.children.push(text);
31        self
32    }
33    #[inline]
34    pub fn class(mut self, class: String) -> Div {
35        self.class = class;
36        self
37    }
38    #[inline]
39    pub fn style(mut self, style: String) -> Div {
40        self.style = style;
41        self
42    }
43    #[inline]
44    pub fn id(mut self, id: String) -> Div {
45        self.id = id;
46        self
47    }
48    #[inline]
49    pub fn render(&self) -> String {
50        let mut html = String::new();
51        html.push_str("<div");
52        if !self.id.is_empty() {
53            html.push_str(" id=\"");
54            html.push_str(&self.id.as_str());
55            html.push('"')
56        }
57        if !self.class.is_empty() {
58            html.push_str(" class=\"");
59            html.push_str(&self.class.as_str());
60            html.push('"')
61        }
62        if !self.style.is_empty() {
63            html.push_str(" style=\"");
64            html.push_str(&self.style.as_str());
65            html.push('"')
66        }
67        html.push('>');
68        for child in &self.children {
69            html.push_str(&child.as_str());
70        }
71        html.push_str("</div>");
72        html
73    }
74}
75
76#[derive(Debug, Clone, PartialEq, Eq, Default)]
77pub struct Span {
78    pub children: Vec<String>,
79    pub class: String,
80    pub style: String,
81}
82
83impl Span {
84    #[inline]
85    pub fn new() -> Span {
86        Span {
87            children: Vec::new(),
88            class: String::new(),
89            style: String::new(),
90        }
91    }
92    #[inline]
93    pub fn child<T: Renderable>(mut self, component: T) -> Span {
94        self.children.push(component.render());
95        self
96    }
97    #[inline]
98    pub fn text(mut self, text: String) -> Span {
99        self.children.push(text);
100        self
101    }
102    #[inline]
103    pub fn class(mut self, class: String) -> Span {
104        self.class = class;
105        self
106    }
107    #[inline]
108    pub fn style(mut self, style: String) -> Span {
109        self.style = style;
110        self
111    }
112}
113
114impl Renderable for Span {
115    #[inline]
116    fn render(self) -> String {
117        let mut html = String::new();
118        html.push_str("<span");
119        if !self.class.is_empty() {
120            html.push_str(" class=\"");
121            html.push_str(&self.class.as_str());
122            html.push('"')
123        }
124        if !self.style.is_empty() {
125            html.push_str(" style=\"");
126            html.push_str(&self.style.as_str());
127            html.push('"')
128        }
129        html.push('>');
130        for child in &self.children {
131            html.push_str(&child.as_str());
132        }
133        html.push_str("</span>");
134        html
135    }
136}
137
138#[derive(Debug, Clone, PartialEq, Eq, Default)]
139pub struct P {
140    pub children: Vec<String>,
141    pub class: String,
142    pub style: String,
143}
144
145impl P {
146    #[inline]
147    pub fn new() -> P {
148        P {
149            children: Vec::new(),
150            class: String::new(),
151            style: String::new(),
152        }
153    }
154    #[inline]
155    pub fn child<T: Renderable>(mut self, component: T) -> P {
156        self.children.push(component.render());
157        self
158    }
159    #[inline]
160    pub fn text(mut self, text: String) -> P {
161        self.children.push(text);
162        self
163    }
164    #[inline]
165    pub fn class(mut self, class: String) -> P {
166        self.class = class;
167        self
168    }
169    #[inline]
170    pub fn style(mut self, style: String) -> P {
171        self.style = style;
172        self
173    }
174}
175
176impl Renderable for P {
177    #[inline]
178    fn render(self) -> String {
179        let mut html = String::new();
180        html.push_str("<p");
181        if !self.class.is_empty() {
182            html.push_str(" class=\"");
183            html.push_str(&self.class.as_str());
184            html.push('"')
185        }
186        if !self.style.is_empty() {
187            html.push_str(" style=\"");
188            html.push_str(&self.style.as_str());
189            html.push('"')
190        }
191        html.push('>');
192        for child in &self.children {
193            html.push_str(&child.as_str());
194        }
195        html.push_str("</p>");
196        html
197    }
198}
199
200#[derive(Debug, Clone, PartialEq, Eq, Hash, Default)]
201pub struct H1 {
202    pub text: String,
203    pub class: String,
204    pub style: String,
205}
206
207impl H1 {
208    #[inline]
209    pub fn new(text: String) -> H1 {
210        H1 {
211            text,
212            class: String::new(),
213            style: String::new(),
214        }
215    }
216    #[inline]
217    pub fn class(mut self, class: String) -> H1 {
218        self.class = class;
219        self
220    }
221    #[inline]
222    pub fn style(mut self, style: String) -> H1 {
223        self.style = style;
224        self
225    }
226}
227
228impl Renderable for H1 {
229    #[inline]
230    fn render(self) -> String {
231        let mut html = String::new();
232        html.push_str("<h1");
233        if !self.class.is_empty() {
234            html.push_str(" class=\"");
235            html.push_str(&self.class.as_str());
236            html.push('"')
237        }
238        if !self.style.is_empty() {
239            html.push_str(" style=\"");
240            html.push_str(&self.style.as_str());
241            html.push('"')
242        }
243        html.push('>');
244        html.push_str(&self.text.as_str());
245        html.push_str("</h1>");
246        html
247    }
248}
249
250#[derive(Debug, Clone, PartialEq, Eq, Hash, Default)]
251pub struct H2 {
252    pub text: String,
253    pub class: String,
254    pub style: String,
255}
256
257impl H2 {
258    #[inline]
259    pub fn new(text: String) -> H2 {
260        H2 {
261            text,
262            class: String::new(),
263            style: String::new(),
264        }
265    }
266    #[inline]
267    pub fn class(mut self, class: String) -> H2 {
268        self.class = class;
269        self
270    }
271    #[inline]
272    pub fn style(mut self, style: String) -> H2 {
273        self.style = style;
274        self
275    }
276}
277
278impl Renderable for H2 {
279    #[inline]
280    fn render(self) -> String {
281        let mut html = String::new();
282        html.push_str("<h2");
283        if !self.class.is_empty() {
284            html.push_str(" class=\"");
285            html.push_str(&self.class.as_str());
286            html.push('"')
287        }
288        if !self.style.is_empty() {
289            html.push_str(" style=\"");
290            html.push_str(&self.style.as_str());
291            html.push('"')
292        }
293        html.push('>');
294        html.push_str(&self.text.as_str());
295        html.push_str("</h2>");
296        html
297    }
298}
299
300#[derive(Debug, Clone, PartialEq, Eq, Hash, Default)]
301pub struct H3 {
302    pub text: String,
303    pub class: String,
304    pub style: String,
305}
306
307impl H3 {
308    #[inline]
309    pub fn new(text: String) -> H3 {
310        H3 {
311            text,
312            class: String::new(),
313            style: String::new(),
314        }
315    }
316    #[inline]
317    pub fn class(mut self, class: String) -> H3 {
318        self.class = class;
319        self
320    }
321    #[inline]
322    pub fn style(mut self, style: String) -> H3 {
323        self.style = style;
324        self
325    }
326}
327
328impl Renderable for H3 {
329    #[inline]
330    fn render(self) -> String {
331        let mut html = String::new();
332        html.push_str("<h3");
333        if !self.class.is_empty() {
334            html.push_str(" class=\"");
335            html.push_str(&self.class.as_str());
336            html.push('"')
337        }
338        if !self.style.is_empty() {
339            html.push_str(" style=\"");
340            html.push_str(&self.style.as_str());
341            html.push('"')
342        }
343        html.push('>');
344        html.push_str(&self.text.as_str());
345        html.push_str("</h3>");
346        html
347    }
348}