moving to fem.mint

This commit is contained in:
kitsunecafe 2024-01-29 15:10:08 -05:00
parent 42af0529bf
commit 40bf884770
2 changed files with 0 additions and 69 deletions

View file

@ -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"

View file

@ -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<u8>) -> 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<u8>) -> 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()), "<h1>fox :3</h1>\n");
}
}