Alternative macro for building Html
in Yew.
This example represents the root App
component of a Yew application.
It shows interpolation in text nodes, interpolation in attributes,
multiple nodes in the root of the macro, shortened tag closing,
using tags in match expressions.
```rust use yew::prelude::*; use yewalthtml::ah;
enum LoadState { Loading, Failed, Loaded, }
pub fn App() -> Html { let name = "Yew"; let italic_style = "font-style: italic";
use LoadState::*;
let state = Loaded;
ah! {
<h1 style=italic_style>"Hello " name "!"</>
match state {
Loading => "Loading...",
Failed => "Load failed!",
Loaded => <p>"Welcome to "<code>"yew-alt-html"</>"!"</>,
}
}
} ```
html!
?This crate experiments on creating a macro that would be easier to use.
For this, the html!
syntax
that was a bit cumbersome to use
is replaced by direct usage of values in ah!
.
Following problems should be solved by this crate:
{}
inside tags even when values are simple literals.{}
(mind that shorthand still uses { variable }
).<></>
when using multiple nodes in the macro root.Most html!
syntax
should be supported by the ah!
macro.
If your code does not work by just replacing html!
with ah!
,
submit an issue.
Some syntax is limited (for example, using >
in attributes without an if
).
Suggested solution would be moving complex values into variables before ah!
,
or wrapping values in {}
braces just like you do in html!
.
match
cases
(requires wrapping the tag in ah!
currently), similar to if
(added in 0.2.0).html!
under the hood: adding more checks
(that are currently handled by html!
)
and generating virtual dom manually.