tera-template-macro

Crates.iotera-template-macro
lib.rstera-template-macro
version0.1.3
sourcesrc
created_at2024-09-30 17:45:53.371998
updated_at2024-10-20 21:18:49.360722
descriptionProc Macro for tera-hot-reload crate
homepagehttps://github.com/oxidlabs/tera-template-macro
repository
max_upload_size
id1391992
size10,023
(Tebarem)

documentation

README

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.

Commit count: 0

cargo fmt