🔏 A safe and simple template engine with the ergonomics of JSX
render
itself is a combination of traits, structs and macros that together unify and
boost the experience of composing tree-shaped data structures. This works best with HTML and
XML rendering, but can work with other usages as well, like ReasonML's Pastel
library for terminal colors.
How?
A renderable component is a struct that implements the Renderable
trait. There
are multiple macros that provide a better experience implementing Renderable:
html!
for the JSX ergonomics#[component]
for the syntactic-sugar of function components
Why this is different from typed-html
?
typed-html
is a wonderful library. Unfortunately, it focused its power in strictness of the HTML spec itself, and doesn't allow arbitrary compositions of custom elements.
render
takes a different approach. For now, HTML is not typed at all. It can get any key and get any string value. The main focus is custom components, so you can create a composable and declarative template with no runtime errors.
Usage
// A simple HTML 5 doctype declaration
use HTML5Doctype;
use ;
// This can be any layout we want
// This can be a route in Rocket, the web framework,
// for instance.
# use assert_eq;
# let actual = some_page;
# let expected = concat!;
# assert_eq!;