7 releases (breaking)

0.7.0 Apr 2, 2024
0.6.0 Mar 17, 2024
0.5.0 Mar 17, 2024
0.4.0 Mar 15, 2024
0.1.0 Mar 13, 2024

#106 in Template engine

Download history 281/week @ 2024-03-09 163/week @ 2024-03-16 21/week @ 2024-03-23 110/week @ 2024-03-30 12/week @ 2024-04-06

149 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