yew-alt-html

crates.io download docs.rs

Alternative macro for building Html in Yew.

Example

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, }

[function_component]

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"</>"!"</>,
    }
}

} ```

Why another 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:

Possible issues

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!.

Planned