Crates.io | tera-template-macro |
lib.rs | tera-template-macro |
version | 0.1.3 |
source | src |
created_at | 2024-09-30 17:45:53.371998 |
updated_at | 2024-10-20 21:18:49.360722 |
description | Proc Macro for tera-hot-reload crate |
homepage | https://github.com/oxidlabs/tera-template-macro |
repository | |
max_upload_size | |
id | 1391992 |
size | 10,023 |
This crate provides a proc macro for the tera-hot-reload crate, allowing for easier and more efficient templating in Rust.
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()))
}
The following dependencies are required to use this crate:
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.
This crate is released under the MIT license. Please see the LICENSE
file for more details.