Crates.io | leptos_macabre |
lib.rs | leptos_macabre |
version | 0.1.0 |
source | src |
created_at | 2024-01-16 16:28:22.929151 |
updated_at | 2024-01-16 16:28:22.929151 |
description | Horribly simple wrapper around leptos_dom, focused on server-side rendering. |
homepage | |
repository | https://github.com/chrisp60/leptos_macabre |
max_upload_size | |
id | 1101776 |
size | 35,432 |
Scary simple server-side rendering. Powered by Leptos.
use leptos_macabre::*;
let result: Result<_, &str> = Ok("Done!");
let style = "color: green;";
section! {
h1!{ "Uploads" },
match result {
Ok(msg) => div! {
@htmx-get="/uploads";
@style;
p!{ "Status: ", msg },
},
Err(err) => strong! {
@class="error";
"Uh Oh: " err
},
}
};
@
and end with ;
.impl leptos::IntoAttribute
.r#type
) are not supported.impl leptos::IntoView
.Due to everything being a minimally recursive macro_rules!
, auto-complete and suggestions
are incredibly snappy.
.into_view()
Every macro in this crate returns a View
, this intentionally diverts from
leptos to not require .into_view()
on each arm (an understandable requirement).
use leptos_macabre::*;
let result = Some(true);
let href = "#section";
match result {
Some(true) => a!(@href; "Go here!"),
Some(false) => p!(@class="bad"; "Uh-oh!"),
None => div!(),
};
Each element is a separate macro. This saves many keystrokes. It is different from most Rust HTML macros.
use leptos::*;
use leptos_macabre::*;
view! { <button>"27 keystrokes"</button> }
button! { "10 keystrokes" }
This crate exports the leptos_dom
items needed to work. If you just want
to make HTML on the server, you can skip adding leptos
as its own dependency.
No reactivity that can't be implemented with a script!
or normal html event
handlers. No signals. Performance will probably be worse when compared directly
to leptos::view!
.
leptos
components with props are minimally supported. The generated Prop*
struct would need to be provided as an argument, meaning you skip
many of the conveniences of using #[component]
in the first place (optional
props etc).
use leptos_macabre::*;
use leptos::component;
#[component]
fn MyButton() -> impl leptos::IntoView {}
#[component]
fn MyA(href: &'static str) -> impl leptos::IntoView {}
p!{ MyButton };
p!{ MyButton() };
p!{ MyA(MyAProps { href: "#red" }) };
Since children are just expressions returning impl IntoView
, you can swap out
components with boring old functions.
use leptos_macabre::*;
fn my_button() -> impl leptos::IntoView { }
fn my_a(href: &'static str) -> impl leptos::IntoView {}
fn my_b(inner: Option<bool>) -> impl leptos::IntoView {}
div! {
my_button,
my_button(),
my_a("#red"),
my_b(Some(true)) ,
};
I always thought the horrorshow
crate was neat, and leptos
is close to the
disease leptospirosis. It is all just a little grim. Secondly, this crate is
created with nested macro_rules!
, something truly horrendous.