add include to test
This commit is contained in:
parent
2335737cd4
commit
3f1f748f7d
18
src/lib.rs
18
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<P: AsRef<Path>>(&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());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1 +1,7 @@
|
|||
:3
|
||||
{% import "macros.html" as macros %}
|
||||
|
||||
{% block main %}
|
||||
{{ macros::test() }}
|
||||
{% include "include-me.html" %}
|
||||
{% endblock main %}
|
||||
|
||||
|
|
2
tests/include-me.html
Normal file
2
tests/include-me.html
Normal file
|
@ -0,0 +1,2 @@
|
|||
<p>from an include!!!</p>
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
{% extends "middle.html" %}
|
||||
{% block content %}
|
||||
super()
|
||||
{{ super() }}
|
||||
:3
|
||||
{% endblock content %}
|
||||
|
||||
|
|
|
@ -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 %}
|
||||
|
||||
|
|
Loading…
Reference in a new issue