make parser take a reference to context

This commit is contained in:
KitsuneCafe 2024-02-01 14:30:59 -05:00
parent abb1178657
commit f66b69ffc1

View file

@ -1,24 +1,25 @@
use roxy_core::roxy::Parse;
#[derive(Debug, Default)]
pub struct TeraParser {
#[derive(Debug)]
pub struct TeraParser<'a> {
pub tera: tera::Tera,
context: tera::Context,
context: &'a tera::Context,
}
impl TeraParser {
pub fn new(tera: tera::Tera, context: tera::Context) -> Self {
impl<'a> TeraParser<'a> {
pub fn new(tera: tera::Tera, context: &'a tera::Context) -> Self {
Self { tera, context }
}
}
impl Parse for TeraParser {
impl<'a> Parse for TeraParser<'a> {
fn parse(&mut self, path: &str, src: &[u8], dst: &mut Vec<u8>) -> std::io::Result<()> {
// TODO: This error is a hack
let err = |e: tera::Error| {
println!("{e:?}");
std::io::Error::new(std::io::ErrorKind::InvalidData, e.to_string())
};
let template = String::from_utf8_lossy(src).to_string();
self.tera