From 3f1f748f7d0f028071b040df340cbd7000843f36 Mon Sep 17 00:00:00 2001 From: kitsunecafe <10284516+kitsunecafe@users.noreply.github.com> Date: Mon, 19 Feb 2024 06:39:28 -0500 Subject: [PATCH] add include to test --- src/lib.rs | 18 +++++++++++------- tests/base.html | 8 +++++++- tests/include-me.html | 2 ++ tests/index.md | 3 ++- tests/middle.html | 9 +++++---- 5 files changed, 27 insertions(+), 13 deletions(-) create mode 100644 tests/include-me.html diff --git a/src/lib.rs b/src/lib.rs index e51ebb2..feb9eb5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,7 +1,4 @@ -use std::{ - fs, - path::Path, -}; +use std::{fs, path::Path}; use once_cell::sync::Lazy; use regex::Regex; @@ -47,6 +44,7 @@ impl<'a> TeraParser<'a> { fn load_template>(&mut self, path: &P, src: &[u8]) -> Result<(), tera::Error> { let path = path.as_ref().canonicalize()?; + println!("loading {path:?}"); let str = String::from_utf8_lossy(src).to_string(); for (_, [_, layout_path]) in EXPANSION_RE .captures_iter(&str.as_str()) @@ -61,8 +59,7 @@ impl<'a> TeraParser<'a> { let next_template = fs::read(&path)?; self.load_template(&path, &next_template)?; - self.tera - .add_template_file(&path, Some(layout_path))?; + self.tera.add_template_file(&path, Some(layout_path))?; } Ok(()) @@ -115,6 +112,13 @@ mod tests { 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()); + let expect = [ + 10, 32, 32, 10, 32, 32, 10, 60, 112, 62, 104, 105, 32, 102, 114, 111, 109, 32, 97, 32, + 109, 97, 99, 114, 111, 33, 32, 110, 119, 110, 60, 47, 112, 62, 10, 10, 32, 32, 60, 112, + 62, 102, 114, 111, 109, 32, 97, 110, 32, 105, 110, 99, 108, 117, 100, 101, 33, 33, 33, + 60, 47, 112, 62, 10, 10, 10, 10, 32, 32, 10, 32, 32, 32, 32, 10, 32, 32, 10, 32, 32, + 32, 32, 58, 51, 10, 10, 10, 10, + ]; + assert_eq!(expect, dst.as_slice()); } } diff --git a/tests/base.html b/tests/base.html index 569cf52..7df917a 100644 --- a/tests/base.html +++ b/tests/base.html @@ -1 +1,7 @@ -:3 +{% import "macros.html" as macros %} + +{% block main %} + {{ macros::test() }} + {% include "include-me.html" %} +{% endblock main %} + diff --git a/tests/include-me.html b/tests/include-me.html new file mode 100644 index 0000000..c0c860f --- /dev/null +++ b/tests/include-me.html @@ -0,0 +1,2 @@ +

from an include!!!

+ diff --git a/tests/index.md b/tests/index.md index 0f7c60a..5b1ed55 100644 --- a/tests/index.md +++ b/tests/index.md @@ -1,5 +1,6 @@ {% extends "middle.html" %} {% block content %} - super() + {{ super() }} + :3 {% endblock content %} diff --git a/tests/middle.html b/tests/middle.html index 5f8fb73..830cdcb 100644 --- a/tests/middle.html +++ b/tests/middle.html @@ -1,6 +1,7 @@ {% extends "base.html" %} -{% import "macros.html" as macros %} -{% block content %} - {{ macros::test() }} -{% endblock content %} +{% block main %} + {{ super() }} + {% block content %} + {% endblock content %} +{% endblock main %}