Crates.io | yew-alt-html |
lib.rs | yew-alt-html |
version | 0.4.0 |
source | src |
created_at | 2023-07-14 20:29:30.387566 |
updated_at | 2023-10-28 09:49:38.051592 |
description | Alternative macro for building Html in Yew. |
homepage | |
repository | https://github.com/kirillsemyonkin/yew-alt-html |
max_upload_size | |
id | 916608 |
size | 78,550 |
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.
use yew::prelude::*;
use yew_alt_html::ah;
enum LoadState {
Loading,
Failed,
Loaded,
}
#[function_component]
pub fn App() -> Html {
let name = "Yew";
let italic_style = "font-style: italic";
use LoadState::*;
let state = Loaded;
let items = vec![1, 2, 3];
ah! {
<h1 style=italic_style>"Hello " name "!"</>
match state {
Loading => "Loading...",
Failed => "Load failed!",
Loaded => <p>"Welcome to "<code>"yew-alt-html"</>"!"</>,
}
<ul>
for item in items {
<li>item</>
}
</>
}
}
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.match
just like if
.{ for ... }
notation (fixed in 0.4.0).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
(fixed in 0.2.0).html!
under the hood: adding more checks
(that are currently handled by html!
)
and generating virtual dom manually.