calathea/src/template/mod.rs

26 lines
777 B
Rust

mod list;
mod update;
mod view;
pub use list::{List, ListItem};
pub use update::Update;
pub use view::View;
pub trait Template {
/// Returns the name or path used to identify the template in the Tera struct
fn template(&self) -> &'static str;
/// Render the template with the given context
fn render_ctx(&self, tera: &tera::Tera, ctx: &tera::Context) -> tera::Result<String> {
tera.render(self.template(), ctx)
}
/// Render the template without providing a context. This is useful for types that manage their
/// own context.
///
/// By default, this simply renders the template with an empty context.
fn render(&self, tera: &tera::Tera) -> tera::Result<String> {
self.render_ctx(tera, &tera::Context::new())
}
}