feat: add minijinja

Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
Kasper Juul Hermansen 2024-05-20 21:00:09 +02:00
parent f0b4c91c63
commit 5ccfb6d31e
Signed by: kjuulh
GPG Key ID: 57B6E1465221F912
2 changed files with 13 additions and 2 deletions

View File

@ -5,6 +5,7 @@ use std::{
};
use anyhow::Context;
use minijinja::context;
use tokio::io::AsyncWriteExt;
use tokio_stream::{wrappers::ReadDirStream, StreamExt};
@ -167,7 +168,17 @@ async fn process_template_file(
.ok_or(anyhow::anyhow!("file didn't have a jinja2 format"))?;
let mut dest_file = tokio::fs::File::create(dest.join(file_name)).await?;
dest_file.write_all(file.as_bytes()).await?;
let mut env = minijinja::Environment::new();
env.add_template(file_name.to_str().unwrap_or_default(), &file)
.context(format!(
"failed to load template at: {}",
template_file.display()
))?;
let tmpl = env.get_template(file_name.to_str().unwrap_or_default())?;
let rendered = tmpl.render(context! {})?;
dest_file.write_all(rendered.as_bytes()).await?;
Ok(())
}

View File

@ -3,4 +3,4 @@
some = {
thing = "some"
}
}
}