Crates.io | bloom-rsx |
lib.rs | bloom-rsx |
version | |
source | src |
created_at | 2024-07-15 20:12:54.471793 |
updated_at | 2024-07-15 20:14:45.236748 |
description | A JSX-like syntax for bloom |
homepage | |
repository | https://github.com/mismosmi/bloom/tree/main/bloom-rsx |
max_upload_size | |
id | 1304274 |
size | 0 |
Essentially, bloom-rsx implements rsx in a way that it just calls a builder-pattern based on the builder-pattern crate.
Lower-case tags will be transformed to calls to a tag
function that must be in scope (bloom-html provides one for HtmlNode
s):
rsx!(<div id="foo" on_click=|| {} />)
will be transformed into (the equivalent of)
tag("div")
.attr("id", "foo")
.on("click", || {})
.build()
.into()
Children are passed after building the tag itself:
rsx!(<div><span /></div>)
is transformed to
tag("div")
.build()
.children(vec![
tag("span").build().into()
])
Text is just cast to the target node type using into:
rsx!(<div>"foobar"</div>)
becomes
tag("div")
.build()
.children(vec![
"foobar".into()
])
Uppercase tags are transformed to a builder pattern:
rsx!(<MyComponent foo="bar"><div /></MyComponent>)
becomes
MyComponent::new()
.foo("bar")
.children(vec![
tag("div").build().into()
])
.build()
.into()