make parser take a reference to context
This commit is contained in:
parent
abb1178657
commit
f66b69ffc1
13
src/lib.rs
13
src/lib.rs
|
@ -1,24 +1,25 @@
|
||||||
use roxy_core::roxy::Parse;
|
use roxy_core::roxy::Parse;
|
||||||
|
|
||||||
#[derive(Debug, Default)]
|
#[derive(Debug)]
|
||||||
pub struct TeraParser {
|
pub struct TeraParser<'a> {
|
||||||
pub tera: tera::Tera,
|
pub tera: tera::Tera,
|
||||||
context: tera::Context,
|
context: &'a tera::Context,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TeraParser {
|
impl<'a> TeraParser<'a> {
|
||||||
pub fn new(tera: tera::Tera, context: tera::Context) -> Self {
|
pub fn new(tera: tera::Tera, context: &'a tera::Context) -> Self {
|
||||||
Self { tera, context }
|
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<()> {
|
fn parse(&mut self, path: &str, src: &[u8], dst: &mut Vec<u8>) -> std::io::Result<()> {
|
||||||
// TODO: This error is a hack
|
// TODO: This error is a hack
|
||||||
let err = |e: tera::Error| {
|
let err = |e: tera::Error| {
|
||||||
println!("{e:?}");
|
println!("{e:?}");
|
||||||
std::io::Error::new(std::io::ErrorKind::InvalidData, e.to_string())
|
std::io::Error::new(std::io::ErrorKind::InvalidData, e.to_string())
|
||||||
};
|
};
|
||||||
|
|
||||||
let template = String::from_utf8_lossy(src).to_string();
|
let template = String::from_utf8_lossy(src).to_string();
|
||||||
|
|
||||||
self.tera
|
self.tera
|
||||||
|
|
Loading…
Reference in a new issue