#tera-templates #tera

macro tera-template-macro

Proc Macro for tera-hot-reload crate

4 releases

0.1.3 Oct 20, 2024
0.1.2 Oct 17, 2024
0.1.1 Oct 17, 2024
0.1.0 Sep 30, 2024

#973 in Procedural macros

Download history 169/week @ 2024-09-28 21/week @ 2024-10-05 259/week @ 2024-10-12 207/week @ 2024-10-19 23/week @ 2024-10-26

519 downloads per month
Used in 2 crates (via tera-hot-reload)

MIT license

8KB
90 lines

Tera Template Macro

Overview

This crate provides a proc macro for the tera-hot-reload crate, allowing for easier and more efficient templating in Rust.

Usuage

Basic usuage example

use tera_hot_reload::TeraTemplate;

// create static tera
pub static TERA: LazyLock<RwLock<Tera>> = LazyLock::new(|| {
    RwLock::new(tera::Tera::new("templates/**/*").expect("Failed to create Tera instance"))
});

// Create a template
#[derive(TeraTemplate)]
#[template(path="index.html")]
struct HelloTemplate {
    name: String,
    greeting: String,
}

//                                  axum::response::IntoResponse
async fn index() -> impl IntoResponse {
    let context = HelloTemplate {
        name: "World".to_string(),
        greeting: "Hello".to_string()
    };
    
    // axum::response::Html
    Html(context.render(TERA.read().unwrap().clone()))
}

Dependencies

The following dependencies are required to use this crate:

  • Tera (version 1.20.0 or higher)
  • syn (version 2.0.72 or higher)
  • quote (version 1.0.37 or higher)
  • proc-macro2 (version 1.0.86 or higher)

Contributing

If you want to contribute to this project, please feel free to create a new branch and submit a pull request. You can also check out the Tera documentation for more information on how to use the Tera template engine.

License

This crate is released under the MIT license. Please see the LICENSE file for more details.

Dependencies

~7–16MB
~206K SLoC