Skip to content

oxidlabs/tera-template-macro

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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()))
}

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.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages