initial commit
This commit is contained in:
commit
69b7a05e48
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
/target
|
||||
/Cargo.lock
|
10
Cargo.toml
Normal file
10
Cargo.toml
Normal file
|
@ -0,0 +1,10 @@
|
|||
[package]
|
||||
name = "roxy_tera_parser"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
roxy_core = { git = "https://github.com/kitsunecafe/roxy-core.git" }
|
||||
tera = "1.19.1"
|
37
src/lib.rs
Normal file
37
src/lib.rs
Normal file
|
@ -0,0 +1,37 @@
|
|||
use roxy_core::roxy::Parse;
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub struct TeraParser {
|
||||
pub tera: tera::Tera,
|
||||
context: tera::Context,
|
||||
}
|
||||
|
||||
impl TeraParser {
|
||||
pub fn new(tera: tera::Tera, context: tera::Context) -> Self {
|
||||
Self { tera, context }
|
||||
}
|
||||
}
|
||||
|
||||
impl Parse for TeraParser {
|
||||
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
|
||||
.add_raw_template(path, template.as_str())
|
||||
.map_err(err)?;
|
||||
|
||||
self.tera.render_to(path, &self.context, dst).map_err(err)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[test]
|
||||
fn it_works() {
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue