puerto 0.10.1

Puerto — Rust full-stack DDD framework CLI. Scaffolds Clean Architecture projects with auto-wired DI, SQLx support, and zero manual wiring. Formerly puerto-framework.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
use include_dir::{Dir, include_dir};
use tera::Tera;

static TEMPLATES: Dir<'_> = include_dir!("$CARGO_MANIFEST_DIR/src/templates");

pub fn render(template_name: &str, ctx: &tera::Context) -> Result<String, tera::Error> {
    let content = TEMPLATES
        .get_file(template_name)
        .ok_or_else(|| tera::Error::msg(format!("template not found: {template_name}")))?
        .contents_utf8()
        .ok_or_else(|| tera::Error::msg("template not UTF-8"))?;
    let mut tera = Tera::default();
    tera.add_raw_template(template_name, content)?;
    tera.render(template_name, ctx)
}