rustolio_web/renderer/server.rs
1//
2// SPDX-License-Identifier: MPL-2.0
3//
4// Copyright (c) 2026 Tobias Binnewies. All rights reserved.
5//
6// This Source Code Form is subject to the terms of the Mozilla Public
7// License, v. 2.0. If a copy of the MPL was not distributed with this
8// file, You can obtain one at http://mozilla.org/MPL/2.0/.
9//
10
11use crate::prelude::*;
12
13#[derive(Clone)]
14pub struct ServerRenderer;
15
16#[derive(Debug, Clone, Default)]
17pub struct Body {
18 pub root: String,
19 pub overlay: String,
20}
21
22impl ServerRenderer {
23 pub fn render(element: Elements) -> Body {
24 let mut body = Body::default();
25 let root = Self::render_rec(element, &mut body);
26 body.root = root;
27 body
28 }
29
30 fn render_rec(_elements: Elements, _body: &mut Body) -> String {
31 todo!()
32 // match elements.inner {
33 // InnerElements::Element(Element {
34 // inner: InnerElement::Raw { .. },
35 // attributes,
36 // }) => unimplemented!("Raw not support in ServerRenderer yet"),
37 // InnerElements::Element(Element {
38 // inner: InnerElement::HtmlTag { tag, children, .. },
39 // attributes,
40 // }) => {
41 // let html::Attributes {
42 // attributes,
43 // class,
44 // style,
45 // value,
46 // selected,
47 // checked,
48 // ..
49 // } = attributes;
50
51 // let class = super::build_multi_attrs(&class);
52 // let style = super::build_multi_attrs(&style);
53 // let attributes: String = attributes
54 // .into_iter()
55 // .map(|a| {
56 // let name = a.name;
57 // let value = match a.value {
58 // html::AttributeValue::None => unreachable!(
59 // "AttributeValue::None should is not used in general attributes"
60 // ),
61 // html::AttributeValue::Static(v) => v,
62 // html::AttributeValue::Dynamic(f) => f().to_string(),
63 // };
64 // match value.as_str() {
65 // "true" => format!(" {name}"),
66 // "false" => String::new(),
67 // _ => format!(" {name}=\"{value}\""),
68 // }
69 // })
70 // .collect();
71
72 // let attributes = if !class.is_empty() {
73 // format!("{attributes} class=\"{class}\"")
74 // } else {
75 // attributes
76 // };
77 // let attributes = if !style.is_empty() {
78 // format!("{attributes} style=\"{style}\"")
79 // } else {
80 // attributes
81 // };
82 // let attributes = match value {
83 // Some(html::AttributeValue::None) | None => attributes,
84 // Some(html::AttributeValue::Static(value)) => {
85 // format!("{attributes} value=\"{value}\"")
86 // }
87 // Some(html::AttributeValue::Dynamic(f)) => {
88 // let value = f();
89 // format!("{attributes} value=\"{value}\"")
90 // }
91 // };
92 // let attributes = match selected {
93 // Some(html::AttributeValue::Static(value)) if value == "true" => {
94 // format!("{attributes} selected")
95 // }
96 // Some(html::AttributeValue::Dynamic(f)) if f() == "true" => {
97 // format!("{attributes} selected")
98 // }
99 // _ => attributes,
100 // };
101 // let attributes = match checked {
102 // Some(html::AttributeValue::Static(value)) if value == "true" => {
103 // format!("{attributes} checked")
104 // }
105 // Some(html::AttributeValue::Dynamic(f)) if f() == "true" => {
106 // format!("{attributes} checked")
107 // }
108 // _ => attributes,
109 // };
110
111 // let children: String = children
112 // .into_iter()
113 // .map(|c| Self::render_rec(c, body))
114 // .collect();
115 // format!("<{tag}{attributes}>{children}</{tag}>")
116 // }
117 // InnerElements::Element(Element {
118 // inner: InnerElement::Text(t),
119 // ..
120 // }) => t,
121 // InnerElements::Element(Element {
122 // inner: InnerElement::None,
123 // ..
124 // }) => String::new(),
125 // InnerElements::Dynamic(d) => Self::render_rec(d(), body),
126 // InnerElements::Iter(i) => i.map(|c| Self::render_rec(c, body)).collect(),
127 // InnerElements::Overlay(f) => {
128 // let overlay = Self::render_rec(f(), body);
129 // body.overlay.push_str(&overlay);
130 // String::new()
131 // }
132 // }
133 }
134}