Crates.io | hotman |
lib.rs | hotman |
version | 0.1.0 |
source | src |
created_at | 2023-07-05 17:22:27.328398 |
updated_at | 2023-07-05 17:22:27.328398 |
description | Simple HTML generation with no macros |
homepage | |
repository | https://github.com/kaikalii/hotman |
max_upload_size | |
id | 909246 |
size | 40,429 |
html
hot male
hotman
🥵 Simple HTML generation in pure Rust with no macros 🥵
See the documentation for usage details.
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}");
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}");