8 releases (breaking)

0.8.0 May 7, 2024
0.7.0 Apr 2, 2024
0.6.0 Mar 17, 2024
0.5.0 Mar 17, 2024
0.1.0 Mar 13, 2024

#98 in #html-templating

Download history 371/week @ 2024-03-11 94/week @ 2024-03-18 117/week @ 2024-04-01 5/week @ 2024-04-08 173/week @ 2024-05-06

173 downloads per month

MIT license

66KB
1.5K SLoC

Toph

Server-side html templating in Rust.

Here is an example to whet your appetite:

HTML Output

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<I: IntoIterator<Item = N>, N>(children: I) -> Node
where
    N: Into<Node>,
{
    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();
}

Dependencies

~2MB
~60K SLoC