hypo
A tiny crate that renders html through macros.
Hypotext is the source leading to the hypertext.
Design
- Minimal interface
- One macro per element, which take attributes and children
- Composition favored over a complex DSL
- Formatting support
- Macros are used in functional style
- Syntax is chosen carefully to be accepted by rustfmt
- Zero intermediary allocations
- Only allocates on full template render
- Render without std if buffer is available
- Zero procedural macros
- Only declarative macros
- Even those are tiny and simple
- Zero dependencies
- Can be used with zero dependencies
- Couple dependencies might be enabled via features
Usage
use *;
let page = html!;
# let mut s = Stringnew;
# page.render;
# assert_eq!;
Control flow
This crate does not provide any syntax for control flow primitives.
It prioritize native structs that implement Render so the user can use it's combinatory methods and primitives to achieve some interesting control flow results.
# use *;
let section = ;
# let mut s = Stringnew;
# section.render;
# assert_eq!;
# let mut s = Stringnew;
# section.render;
# assert_eq!;
# let mut s = Stringnew;
# section.render;
# assert_eq!;
Feature flags
No features are enabled by default, which means this crate does not carry any dependencies. But hear me out...
-
kebab: Attributes will have the underline (_) replaced by a dash (-) in compile time. This is useful for cleanly adding an
hx-getfor example, for no runtime cost. -
perf: The Render implementation for numbers won't use Display, instead leveraging a performance oriented library. This might give you a rendering performance boost if you have lots of numbers.
Versus
-
vy, the main inspiration of this library.
- Hypotext has syntax that allows for conditional attributes and classes, without giving up formatting.
- Hypotext has no procedural macros, even with all features enabled.
- I'd pick hypotext over it because it's simpler and more powerful.
-
maud, de facto compiled html macro dsl.
- Hypotext has way less dsl, which could work as a pro or a con.
- Hypotext has no procedural macros, even with all features enabled.
- Hypotext does not allocate intermediary containers.
- I'd pick maud if you prefer it's dsl.
-
askama, actual html templates jinja style.
- Hypotext has a simpler syntax for composition (just functions).
- Hypotext will avoid the html change of context, which could work as a pro or con.
- I'd pick askama if you want to have raw html files.