toph

Crates.iotoph
lib.rstoph
version0.7.0
sourcesrc
created_at2024-03-13 12:29:48.673309
updated_at2024-04-02 19:39:05.466697
descriptionSimple server-side html generation
homepage
repositoryhttps://git.sr.ht/~eanyanwu/toph
max_upload_size
id1171663
size88,326
(wake-sleeper)

documentation

README

# Toph Server-side html templating in Rust. Here is an example to whet your appetite: ![HTML Output](./html-output.png) ```rust use toph::component::{stack, cluster}; use toph::tag::{div_, body_, button_, head_, html_, doctype_}; use toph::{Node, attr}; const BUTTON: &str = " button { padding: 0.5rem 1.25rem; font-weight: bold; border: 2px solid black; box-shadow: 2px 2px black; }"; const CARD: &str = ".card { padding: 1rem; border: 5px solid black; }"; pub fn custom_card, N>(children: I) -> Node where N: Into, { div_.with(attr![class = "card"]) .stylesheet(CARD) .set(children) } fn main() { let button = |text: &str| button_.set([text]).stylesheet(BUTTON); let left = custom_card([stack(3, [button("Hello"), button("World")])]); let right = custom_card([stack(3, [button("Goodbye"), button("World")])]); let html = [ doctype_, html_.set([head_, body_.set([cluster(3, [left, right])])]), ]; std::fs::write("components.html", Node::render(html)).unwrap(); } ```
Commit count: 0

cargo fmt