Crate hotman

Crate hotman 

Source
Expand description

github crates.io docs.rs

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 accept attribute
Action
The action attribute
Align
The align attribute
Allow
The allow attribute
Alt
The alt attribute
Async
The async attribute
Autocomplete
The autocomplete attribute
Autofocus
The autofocus attribute
Autoplay
The autoplay attribute
Charset
The charset attribute
Checked
The checked attribute
Cite
The cite attribute
Class
The class attribute
Clear
The clear attribute
Color
The color attribute
Cols
The cols attribute
Colspan
The colspan attribute
Command
The command attribute
Comment
An HTML comment
Content
The content attribute
Controls
The controls attribute
Coords
The coords attribute
Crossorigin
The crossorigin attribute
Data
The data attribute
Datetime
The datetime attribute
Decoding
The decoding attribute
Default
The default attribute
Defer
The defer attribute
Dir
The dir attribute
Dirname
The dirname attribute
Disabled
The disabled attribute
Download
The download attribute
Enctype
The enctype attribute
Events
The HTML events
For
The for attribute
Form
The form attribute
Formaction
The formaction attribute
Formenctype
The formenctype attribute
Formmethod
The formmethod attribute
Formnovalidate
The formnovalidate attribute
Formtarget
The formtarget attribute
GlobalAttributes
Wrapper around attributes that are common to all elements
GlobalAttributesInner
Attributes that are common to all elements
Headers
The headers attribute
Height
The height attribute
High
The high attribute
Href
The href attribute
Hreflang
The hreflang attribute
HttpEquiv
The http_equiv attribute
Icon
The icon attribute
Id
The id attribute
Importance
The importance attribute
Integrity
The integrity attribute
Intrinsicsize
The intrinsicsize attribute
Ismap
The ismap attribute
Itemscope
The itemscope attribute
Kind
The kind attribute
Label
The label attribute
List
The list attribute
Loading
The loading attribute
Loop
The loop attribute
Low
The low attribute
Manifest
The manifest attribute
Max
The max attribute
MaxLength
The max_length attribute
Maxlength
The maxlength attribute
Media
The media attribute
Method
The method attribute
Min
The min attribute
MinLength
The min_length attribute
Minlength
The minlength attribute
Multiple
The multiple attribute
Muted
The muted attribute
Name
The name attribute
Nomodule
The nomodule attribute
Nonce
The nonce attribute
Noshade
The noshade attribute
Novalidate
The novalidate attribute
On
Add an event handler to an element
Open
The open attribute
Optimum
The optimum attribute
Page
A full HTML document.
Pattern
The pattern attribute
Ping
The ping attribute
Placeholder
The placeholder attribute
Playsinline
The playsinline attribute
Poster
The poster attribute
Preload
The preload attribute
Profile
The profile attribute
Radiogroup
The radiogroup attribute
Readonly
The readonly attribute
Referrerpolicy
The referrerpolicy attribute
Rel
The rel attribute
Required
The required attribute
Reversed
The reversed attribute
Rows
The rows attribute
Rowspan
The rowspan attribute
Sandbox
The sandbox attribute
Scope
The scope attribute
Selected
The selected attribute
Shape
The shape attribute
Size
The size attribute
Sizes
The sizes attribute
Span
The span attribute
Src
The src attribute
Srcdoc
The srcdoc attribute
Srclang
The srclang attribute
Srcset
The srcset attribute
Start
The start attribute
Step
The step attribute
Style
The style attribute
Target
The target attribute
Title
The title attribute
Type
The type attribute
Usemap
The usemap attribute
Value
The value attribute
Width
The width attribute
Wrap
The wrap attribute
Xmlns
The xmlns attribute

Enums§

Event
Types of event handlers
Node
An HTML node

Constants§

BR
Short alias for br(())

Traits§

Element
Trait for types of elements
ElementData
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