diff --git a/Cargo.toml b/Cargo.toml index 57a308b..5f33b36 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,5 +6,3 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -pulldown-cmark = "0.9.3" -tera = "1.19.1" diff --git a/src/roxy.rs b/src/roxy.rs index 55d360f..976cc0e 100644 --- a/src/roxy.rs +++ b/src/roxy.rs @@ -41,49 +41,6 @@ impl Parse for Parser { } } -#[derive(Debug)] -pub struct Markdown; - -impl Markdown { - pub fn new() -> Self { - Self - } -} - -impl Parse for Markdown { - fn parse(&mut self, _path: &str, src: &[u8], dst: &mut Vec) -> std::io::Result<()> { - let src = String::from_utf8_lossy(src).to_string(); - let parser = pulldown_cmark::Parser::new(src.as_str()); - pulldown_cmark::html::write_html(dst, parser) - } -} - -#[derive(Debug, Default)] -pub struct Html { - pub tera: tera::Tera, - context: tera::Context, -} - -impl Html { - pub fn new(tera: tera::Tera, context: tera::Context) -> Self { - Self { tera, context } - } -} - -impl Parse for Html { - fn parse(&mut self, path: &str, src: &[u8], dst: &mut Vec) -> std::io::Result<()> { - // TODO: This error is a hack - let err = |_| std::io::Error::new(std::io::ErrorKind::InvalidData, "fail"); - 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) - } -} - pub struct Asset<'a, R> { path: &'a str, data: R, @@ -170,27 +127,3 @@ impl Roxy { } } -#[cfg(test)] -mod tests { - use crate::roxy::{Html, Markdown, Parser}; - - use super::Parse; - - #[test] - fn md_and_html() { - let mut parsers = Parser::new(); - parsers.push(Markdown::new()); - let mut ctx = tera::Context::new(); - - ctx.insert("test", "fox"); - parsers.push(Html::new(tera::Tera::default(), ctx)); - - let mut buf = Vec::new(); - - parsers - .parse("test.html", b"# {{ test }} :3", &mut buf) - .unwrap(); - - assert_eq!(String::from_utf8_lossy(buf.as_slice()), "

fox :3

\n"); - } -}