#html-templating #html #template #hypermedia

hypersynthetic

An HTML template engine that chose composition over inheritance

8 releases

0.3.1 May 4, 2024
0.3.0 Oct 18, 2023
0.2.1 Sep 1, 2023
0.1.3 Aug 21, 2023

#100 in Template engine

Download history 4/week @ 2024-02-22 3/week @ 2024-02-29 2/week @ 2024-03-07 3/week @ 2024-03-14 24/week @ 2024-03-28 8/week @ 2024-04-04 160/week @ 2024-05-02 2/week @ 2024-05-09

162 downloads per month

MIT/Apache

18KB
198 lines

hypersynthetic

Hypersynthetic is a library for writing HTML inside Rust. It is inspired by JSX and HEEx templates, and tries to be different from Tera and Minijinja in one key aspect: it only allows reusing HTML code via composition not via inheritance. It is suitable for building traditional web applications, where backend responds with HTML.

Here is an example of what hypersynthetic can do:

Example

use hypersynthetic::prelude::*;

#[component]
fn TodoItem(text: &str, done: bool) -> HtmlFragment {
    let text_decoration = if done { "line-through" } else { "none" };

    html! {
        <li style="text-decoration: {text_decoration};">
            {text}
        </li>
    }
}

fn main() {
    let todo_list = vec![
        ("Buy Milk", true),
        ("Read Rust Book", false),
        ("Write Web App using html! macro", false),
    ];

    let rendered_list = html! {
        <ul>
            <TodoItem :for={(text, done) in todo_list} text={text} done={done} />
        </ul>
    };

    // ... Render `rendered_list` into your application.
}

In this example:

The TodoItem component displays a to-do item, striking it through if it’s done. The main function defines a list of to-dos and uses the :for attribute to loop over them, rendering each one using the TodoItem component.

Features

  • rocket: Enables integration with the Rocket web framework and allows to return HtmlFragment from handlers. To use this feature, add features = ["rocket"] in your Cargo.toml when adding this library as a dependency.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~0.6–36MB
~517K SLoC