yate/lib.rs
1//! yate is a simple, idiomatic, combined html template engine and static site
2//! generator.
3//!
4//! Templating is done through composing html macro generated string chunks that
5//! can be returned by Rust functions. The macro, powered by [syn-rsx], supports
6//! arbitrary Rust syntax in braced blocks in various html positions which
7//! unlocks using regular language features without being limited by specialized
8//! template syntax. The fact that the composed content is just a string makes
9//! it very flexible and allows e.g. serving it with a webserver or write it as
10//! static content.
11//!
12//! Embedded Rust code in braced blocks inside the `html!` macro must return
13//! something that implements [`std::fmt::Display`]. More information about
14//! supported syntax can be found [here].
15//!
16//! # Example
17//!
18//! [here]: https://docs.rs/syn-rsx/latest/syn_rsx/#features
19//!
20//! ```
21//! # async {
22//! use yate::html;
23//!
24//! fn content() -> String {
25//! html! { <div>"content"</div> }
26//! }
27//!
28//! fn index() -> String {
29//! html! {
30//! <!DOCTYPE html>
31//! <html>
32//! <head></head>
33//! <body>
34//! {content()}
35//! </body>
36//! </html>
37//! }
38//! }
39//!
40//! std::fs::write("index.html", index())?;
41//! #
42//! # Ok::<(), Box<dyn std::error::Error>>(()) };
43//! ```
44//!
45//! # Html escaping
46//!
47//! There is syntax sugar available that passes expressions in braced blocks
48//! into `html_escape::escape_text()`. Works like this:
49//!
50//! ```
51//! let div = yate::html! { <div>{%= "<uwu>" %}</div> };
52//! assert_eq!(div, "<div><uwu></div>")
53//! ```
54//!
55//! [syn-rsx]: https://crates.io/crates/syn-rsx
56
57pub use html_escape;
58pub use html_to_string_macro::html;