fix macros; add new test

This commit is contained in:
KitsuneCafe 2024-02-19 05:58:49 -05:00
parent 13868747c2
commit 2335737cd4
4 changed files with 23 additions and 13 deletions

View file

@ -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<tera::Context> = Lazy::new(|| tera::Context::default());
const EXPANSION_RE: Lazy<Regex> = 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());
}
}

View file

@ -1,2 +1,5 @@
{% extends "middle.html" %}
{% block content %}
super()
{% endblock content %}

4
tests/macros.html Normal file
View file

@ -0,0 +1,4 @@
{% macro test() %}
<p>hi from a macro! nwn</p>
{% endmacro test %}

View file

@ -1,2 +1,6 @@
{% extends "base.html" %}
{% import "macros.html" as macros %}
{% block content %}
{{ macros::test() }}
{% endblock content %}