hotman

Crates.iohotman
lib.rshotman
version0.1.0
sourcesrc
created_at2023-07-05 17:22:27.328398
updated_at2023-07-05 17:22:27.328398
descriptionSimple HTML generation with no macros
homepage
repositoryhttps://github.com/kaikalii/hotman
max_upload_size
id909246
size40,429
Kai Schmidt (kaikalii)

documentation

https://docs.rs/hotman

README

github crates.io docs.rs

html
hot male
hotman

🥵 Simple HTML generation in pure Rust with no macros 🥵

See the documentation for usage details.

Static Example

use hotman::*;

let dom = html((
    Comment("A simple login page"),
    head((
        meta(Charset("utf-8")),
        title("Login"),
        script(Src("/script.js")),
    )),
    body((
        h1("Login"),
        form((
            (Action("/login"), Method("POST")),
            input((
                Type("text"),
                Name("username"),
                Placeholder("Username"),
                On(Change, "validate_username()"),
                Autofocus,
            )),
            input((
                Type("password"),
                Name("password"),
                Placeholder("Password"),
                On(Change, "validate_password()"),
            )),
            input((Type("submit"), Value("Login"))),
        )),
        BR,
        p((
            "Don't have an account? ",
            a((Href("/register"), "Register")),
        )),
    )),
))
.page();

println!("{dom}");

Dynamic Example

use hotman::*;

struct User {
    id: u64,
    username: String,
    password: String,
}

impl User {
    fn new(id: u64, username: String, password: String) -> Self {
        Self {
            id,
            username,
            password,
        }
    }
}

// Some example users
let users = vec![
    User::new(0, "Alice".into(), "hunter2".into()),
    User::new(1, "Bob".into(), "swordfish".into()),
    User::new(2, "Charlie".into(), "1337".into()),
];

let users_table = table((
    Style("border-collapse: collapse;"),
    tr((th("ID"), th("Username"), th("Password"))),
    users.iter().map(|user| {
        tr((
            td(user.id.to_string()),
            td(&user.username),
            td(&user.password),
        ))
    }),
));

println!("{users_table}");
Commit count: 41

cargo fmt