feat: add minijinja
Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
parent
f0b4c91c63
commit
5ccfb6d31e
@ -5,6 +5,7 @@ use std::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
|
use minijinja::context;
|
||||||
use tokio::io::AsyncWriteExt;
|
use tokio::io::AsyncWriteExt;
|
||||||
use tokio_stream::{wrappers::ReadDirStream, StreamExt};
|
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"))?;
|
.ok_or(anyhow::anyhow!("file didn't have a jinja2 format"))?;
|
||||||
|
|
||||||
let mut dest_file = tokio::fs::File::create(dest.join(file_name)).await?;
|
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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -3,4 +3,4 @@
|
|||||||
some = {
|
some = {
|
||||||
thing = "some"
|
thing = "some"
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user