bloom-rsx

Crates.iobloom-rsx
lib.rsbloom-rsx
version
sourcesrc
created_at2024-07-15 20:12:54.471793
updated_at2024-07-15 20:14:45.236748
descriptionA JSX-like syntax for bloom
homepage
repositoryhttps://github.com/mismosmi/bloom/tree/main/bloom-rsx
max_upload_size
id1304274
size0
Michel Smola (mismosmi)

documentation

README

bloom-rsx

Essentially, bloom-rsx implements rsx in a way that it just calls a builder-pattern based on the builder-pattern crate.

Tags

Lower-case tags will be transformed to calls to a tag function that must be in scope (bloom-html provides one for HtmlNodes):

rsx!(<div id="foo" on_click=|| {} />)

will be transformed into (the equivalent of)

tag("div")
    .attr("id", "foo")
    .on("click", || {})
    .build()
    .into()

Children

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

Text is just cast to the target node type using into:

rsx!(<div>"foobar"</div>)

becomes

tag("div")
  .build()
  .children(vec![
    "foobar".into()
  ])

Components

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()
Commit count: 0

cargo fmt