#dom #reactive #front-end #ui

macro mogwai-macros

Declarative RSX macro for constructing mogwai ViewBuilder

2 releases

0.1.0 Jan 6, 2023
0.1.0-alpha Dec 31, 2022

#159 in #dom

Download history 1/week @ 2024-02-11 6/week @ 2024-02-18 29/week @ 2024-02-25 5/week @ 2024-03-03 8/week @ 2024-03-10 4/week @ 2024-03-24 50/week @ 2024-03-31 3/week @ 2024-04-07 4/week @ 2024-04-21

58 downloads per month
Used in 3 crates (2 directly)

MIT license

23KB
439 lines

mogwai-macros

Provides procedural macros builder! and view!, which allow the use of RSX to declare mogwai views.

Example - this RSX:

    view!(
        <footer class="info">
            <p>"Double click to edit a todo"</p>
            <p>
                "Written by "
                <a href="https://github.com/schell">"Schell Scivally"</a>
            </p>
            <p>
                "Part of "
                <a href="http://todomvc.com">"TodoMVC"</a>
            </p>
        </footer>
    ).run()

will roughly generate this rust code:

    (mogwai::gizmo::dom::View::element("footer") as View<web_sys::HtmlElement>)
        .attribute("class", "info")
        .with(
            (mogwai::gizmo::dom::View::element("p") as View<web_sys::HtmlElement>)
                .with("Double click to edit a todo"),
        )
        .with(
            (mogwai::gizmo::dom::View::element("p") as View<web_sys::HtmlElement>)
                .with("Written by ")
                .with(
                    (mogwai::gizmo::dom::View::element("a")
                        as View<web_sys::HtmlElement>)
                        .attribute("href", "https://github.com/schell")
                        .with("Schell Scivally"),
                ),
        )
        .with(
            (mogwai::gizmo::dom::View::element("p") as View<web_sys::HtmlElement>)
                .with("Part of ")
                .with(
                    (mogwai::gizmo::dom::View::element("a")
                        as View<web_sys::HtmlElement>)
                        .attribute("href", "http://todomvc.com")
                        .with("TodoMVC"),
                ),
        )
        .run()

Dependencies

~1.5MB
~34K SLoC