Expand description
html
hot male
hotman.
🥵 Simple HTML generation in pure Rust with no macros 🥵
§Usage
Writing HTML with hotman is very similar to writing HTML itself.
All the same words are there, only the punctuation is different.
§Elements
Html elements are constructed using functions with the same name as the tag.
Examples are head, body, div, and p.
Elements can be converted to strings with the Display trait (and by extension, the ToString::to_string method).
§ElementData
The ElementData trait is implemented for any type which adds either attributes or children to an element.
ElementData is also implemented for Options, arrays, Vecs, some iterators, and tuples of ElementDatas up to 20.
The element functions all take an ElementData as their argument, so you can pass tuples for multiple values.
§Attributes
Attributes are represented by structs with the same name as the attribute. They implement ElementData.
Examples are Id, Href, Class, and Style.
§Events
Individual event handler attributes do not each have their own struct.
Instead, they can be added to elements via the On struct.
On implements ElementData and consists of an Event and a string representing the handler.
§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}");§Iteration
A blanket implementation of ElementData for any Iterator would conflict with the implementaiton for tuples.
As a workaround, ElementData is implemented for the Map, FilterMap, and FlatMap iterators.
Because you usually map data to elements anyway, these implementations are usually more than enough.
let number_list = {
use hotman::*;
ul((1..=5).map(|i| li(i.to_string())))
};
assert_eq!(number_list.to_string(), "\
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
</ul>");§Scoping
To make writing HTML as short as possible, hotman exports every element, attribute, and event in the root of the crate.
This means that there are many potential name conflicts with surrounding code.
It is recommended to scope use hotman::* to a small block of code:
let page_head = {
use hotman::*;
head((title("My Page"), meta((Name("Description"), Content("A page")))))
};Re-exports§
pub use Event::*;
Modules§
- attribute_
traits - Traits that mark elements as having attributes
- element_
structs - Structs that represent HTML elements
Structs§
- Accept
- The
acceptattribute - Action
- The
actionattribute - Align
- The
alignattribute - Allow
- The
allowattribute - Alt
- The
altattribute - Async
- The
asyncattribute - Autocomplete
- The
autocompleteattribute - Autofocus
- The
autofocusattribute - Autoplay
- The
autoplayattribute - Charset
- The
charsetattribute - Checked
- The
checkedattribute - Cite
- The
citeattribute - Class
- The
classattribute - Clear
- The
clearattribute - Color
- The
colorattribute - Cols
- The
colsattribute - Colspan
- The
colspanattribute - Command
- The
commandattribute - Comment
- An HTML comment
- Content
- The
contentattribute - Controls
- The
controlsattribute - Coords
- The
coordsattribute - Crossorigin
- The
crossoriginattribute - Data
- The
dataattribute - Datetime
- The
datetimeattribute - Decoding
- The
decodingattribute - Default
- The
defaultattribute - Defer
- The
deferattribute - Dir
- The
dirattribute - Dirname
- The
dirnameattribute - Disabled
- The
disabledattribute - Download
- The
downloadattribute - Enctype
- The
enctypeattribute - Events
- The HTML events
- For
- The
forattribute - Form
- The
formattribute - Formaction
- The
formactionattribute - Formenctype
- The
formenctypeattribute - Formmethod
- The
formmethodattribute - Formnovalidate
- The
formnovalidateattribute - Formtarget
- The
formtargetattribute - Global
Attributes - Wrapper around attributes that are common to all elements
- Global
Attributes Inner - Attributes that are common to all elements
- Headers
- The
headersattribute - Height
- The
heightattribute - High
- The
highattribute - Href
- The
hrefattribute - Hreflang
- The
hreflangattribute - Http
Equiv - The
http_equivattribute - Icon
- The
iconattribute - Id
- The
idattribute - Importance
- The
importanceattribute - Integrity
- The
integrityattribute - Intrinsicsize
- The
intrinsicsizeattribute - Ismap
- The
ismapattribute - Itemscope
- The
itemscopeattribute - Kind
- The
kindattribute - Label
- The
labelattribute - List
- The
listattribute - Loading
- The
loadingattribute - Loop
- The
loopattribute - Low
- The
lowattribute - Manifest
- The
manifestattribute - Max
- The
maxattribute - MaxLength
- The
max_lengthattribute - Maxlength
- The
maxlengthattribute - Media
- The
mediaattribute - Method
- The
methodattribute - Min
- The
minattribute - MinLength
- The
min_lengthattribute - Minlength
- The
minlengthattribute - Multiple
- The
multipleattribute - Muted
- The
mutedattribute - Name
- The
nameattribute - Nomodule
- The
nomoduleattribute - Nonce
- The
nonceattribute - Noshade
- The
noshadeattribute - Novalidate
- The
novalidateattribute - On
- Add an event handler to an element
- Open
- The
openattribute - Optimum
- The
optimumattribute - Page
- A full HTML document.
- Pattern
- The
patternattribute - Ping
- The
pingattribute - Placeholder
- The
placeholderattribute - Playsinline
- The
playsinlineattribute - Poster
- The
posterattribute - Preload
- The
preloadattribute - Profile
- The
profileattribute - Radiogroup
- The
radiogroupattribute - Readonly
- The
readonlyattribute - Referrerpolicy
- The
referrerpolicyattribute - Rel
- The
relattribute - Required
- The
requiredattribute - Reversed
- The
reversedattribute - Rows
- The
rowsattribute - Rowspan
- The
rowspanattribute - Sandbox
- The
sandboxattribute - Scope
- The
scopeattribute - Selected
- The
selectedattribute - Shape
- The
shapeattribute - Size
- The
sizeattribute - Sizes
- The
sizesattribute - Span
- The
spanattribute - Src
- The
srcattribute - Srcdoc
- The
srcdocattribute - Srclang
- The
srclangattribute - Srcset
- The
srcsetattribute - Start
- The
startattribute - Step
- The
stepattribute - Style
- The
styleattribute - Target
- The
targetattribute - Title
- The
titleattribute - Type
- The
typeattribute - Usemap
- The
usemapattribute - Value
- The
valueattribute - Width
- The
widthattribute - Wrap
- The
wrapattribute - Xmlns
- The
xmlnsattribute
Enums§
Constants§
- BR
- Short alias for
br(())
Traits§
- Element
- Trait for types of elements
- Element
Data - A piece of data that can be added to an element
Functions§
- a
- Make a
<a>element - abbr
- Make a
<abbr>element - area
- Make a
<area>element - audio
- Make a
<audio>element - b
- Make a
<b>element - base
- Make a
<base>element - bdi
- Make a
<bdi>element - bdo
- Make a
<bdo>element - blockquote
- Make a
<blockquote>element - body
- Make a
<body>element - br
- Make a
<br>element - button
- Make a
<button>element - canvas
- Make a
<canvas>element - caption
- Make a
<caption>element - cite
- Make a
<cite>element - code
- Make a
<code>element - col
- Make a
<col>element - colgroup
- Make a
<colgroup>element - dd
- Make a
<dd>element - del
- Make a
<del>element - details
- Make a
<details>element - dfn
- Make a
<dfn>element - div
- Make a
<div>element - dl
- Make a
<dl>element - dt
- Make a
<dt>element - em
- Make a
<em>element - embed
- Make a
<embed>element - fieldset
- Make a
<fieldset>element - form
- Make a
<form>element - h1
- Make a
<h1>element - h2
- Make a
<h2>element - h3
- Make a
<h3>element - h4
- Make a
<h4>element - h5
- Make a
<h5>element - h6
- Make a
<h6>element - head
- Make a
<head>element - hr
- Make a
<hr>element - html
- Make a
<html>element - i
- Make a
<i>element - iframe
- Make a
<iframe>element - img
- Make a
<img>element - input
- Make a
<input>element - ins
- Make a
<ins>element - kbd
- Make a
<kbd>element - label
- Make a
<label>element - legend
- Make a
<legend>element - li
- Make a
<li>element - link
- Make a
<link>element - map
- Make a
<map>element - mark
- Make a
<mark>element - menu
- Make a
<menu>element - menuitem
- Make a
<menuitem>element - meta
- Make a
<meta>element - meter
- Make a
<meter>element - noscript
- Make a
<noscript>element - object
- Make a
<object>element - ol
- Make a
<ol>element - option
- Make a
<option>element - output
- Make a
<output>element - p
- Make a
<p>element - param
- Make a
<param>element - progress
- Make a
<progress>element - q
- Make a
<q>element - rp
- Make a
<rp>element - rt
- Make a
<rt>element - samp
- Make a
<samp>element - script
- Make a
<script>element - select
- Make a
<select>element - slot
- Make a
<slot>element - small
- Make a
<small>element - source
- Make a
<source>element - span
- Make a
<span>element - strong
- Make a
<strong>element - style
- Make a
<style>element - sub
- Make a
<sub>element - summary
- Make a
<summary>element - sup
- Make a
<sup>element - table
- Make a
<table>element - tbody
- Make a
<tbody>element - td
- Make a
<td>element - template
- Make a
<template>element - textarea
- Make a
<textarea>element - tfoot
- Make a
<tfoot>element - th
- Make a
<th>element - thead
- Make a
<thead>element - time
- Make a
<time>element - title
- Make a
<title>element - tr
- Make a
<tr>element - track
- Make a
<track>element - ul
- Make a
<ul>element - var
- Make a
<var>element - video
- Make a
<video>element - wbr
- Make a
<wbr>element