diff --git a/src/lib.rs b/src/lib.rs index 1d86542..e51ebb2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,7 +1,6 @@ use std::{ - fs::{self, read, File}, - io::BufReader, - path::{Path, PathBuf}, + fs, + path::Path, }; use once_cell::sync::Lazy; @@ -10,7 +9,7 @@ use roxy_core::roxy::Parse; const DEFAULT_CONTEXT: Lazy = Lazy::new(|| tera::Context::default()); const EXPANSION_RE: Lazy = Lazy::new(|| { - Regex::new("\\{% (extends|include) \"?(.+?)\"? %\\}").expect("couldn't load regex") + Regex::new(r#"\{% (extends|include|import) "?(.+?)"? .*?%\}"#).expect("couldn't load regex") }); #[derive(Debug)] @@ -109,13 +108,13 @@ mod tests { use crate::{TeraParser, TeraParserOptions}; - //#[test] - //fn capture_test() { - // let mut tera = tera::Tera::default(); - // let mut parser = TeraParser::new(&mut tera, TeraParserOptions::default()); - // let data = fs::read("./tests/index.md").unwrap(); - // let mut dst = Vec::new(); - // parser.parse("./tests/index.md", &data, &mut dst); - // println!("{dst:?}"); - //} + #[test] + fn capture_test() { + let mut tera = tera::Tera::default(); + let mut parser = TeraParser::new(&mut tera, TeraParserOptions::default()); + let data = fs::read("./tests/index.md").unwrap(); + let mut dst = Vec::new(); + parser.parse("./tests/index.md", &data, &mut dst).unwrap(); + assert_eq!([58, 51, 10], dst.as_slice()); + } } diff --git a/tests/index.md b/tests/index.md index 80a81bc..0f7c60a 100644 --- a/tests/index.md +++ b/tests/index.md @@ -1,2 +1,5 @@ {% extends "middle.html" %} +{% block content %} + super() +{% endblock content %} diff --git a/tests/macros.html b/tests/macros.html new file mode 100644 index 0000000..b80b2e1 --- /dev/null +++ b/tests/macros.html @@ -0,0 +1,4 @@ +{% macro test() %} +

hi from a macro! nwn

+{% endmacro test %} + diff --git a/tests/middle.html b/tests/middle.html index 5cb6467..5f8fb73 100644 --- a/tests/middle.html +++ b/tests/middle.html @@ -1,2 +1,6 @@ {% extends "base.html" %} +{% import "macros.html" as macros %} +{% block content %} + {{ macros::test() }} +{% endblock content %}