-
Notifications
You must be signed in to change notification settings - Fork 49
Serialize to HTML #82
Comments
Yep! I've been intending to support this sometime in the future. The first step would be to add a impl<'a> Node<'a> {
fn to_html_string(&self) -> String { ... }
} And the second step would be a way to create an empty Happy to give some further pointers if you (or anyone else) is interested in contributing this. |
I'm want to try it ! It is possible ? |
@sepiropht sure thing! To expand a bit on what I wrote above: I think actually rather than making this a method on Here is a sketch: pub fn html_string<R>(component: &R) -> String
where
R: Render,
{
// Create an empty rendering context. You'll need to create this `empty`
// method.
let cx = &mut RenderContext::empty();
// Render the component in the new context.
let node = component.render(cx);
// Stringify the node into an HTML string.
let mut s = String::new();
html_string_recursive(cx, &mut s, self);
return s;
fn html_string_recursive(cx: &mut RenderContext, s: &mut String, node: &Node) {
match node.kind {
NodeKind::Text(ref t) => s.push_str(t.text),
NodeKind::Element(ref e) => {
// TODO: push the HTML-formatted element to `s`...
// Recursively stringify the children.
for c in &e.children {
html_string(cx, s, c);
}
// TODO: push the close tag to `s`...
}
NodeKind::Cached(ref c) => {
// TODO: use cx.cached_set.get to get the underlying cached node
// and then call `html_string_recursive` on it...
}
}
}
} |
Ok thanks! I will look at this as soon as possible! |
Would it be possible to serialize a tree as an html string or some mechanism to create a dodrio dom in server side and serve it via http?
The text was updated successfully, but these errors were encountered: