handle template includes

This commit is contained in:
KitsuneCafe 2024-02-05 15:21:49 -05:00
parent d7a364b1af
commit 6084b9072b

View file

@ -6,7 +6,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 \"?(.+?)\"? %\\}").expect("couldn't load regex"));
Lazy::new(|| Regex::new("\\{% (extends|include) \"?(.+?)\"? %\\}").expect("couldn't load regex"));
#[derive(Debug)]
pub struct TeraParserOptions {
@ -44,7 +44,7 @@ impl<'a> TeraParser<'a> {
fn load_template(&mut self, path: &str, src: &[u8]) -> Result<(), tera::Error> {
let str = String::from_utf8_lossy(src).to_string();
if let Some(captures) = EXPANSION_RE.captures(&str.as_str()) {
if let Some(layout_path) = captures.get(1) {
if let Some(layout_path) = captures.get(2) {
let layout_path = layout_path.as_str();
let path = PathBuf::from(path).parent().map(|p| p.join(layout_path)).unwrap();
@ -87,6 +87,8 @@ impl<'a> Parse for TeraParser<'a> {
#[cfg(test)]
mod tests {
#[test]
fn it_works() {}
use roxy_core::roxy::Parse;
use crate::{TeraParser, TeraParserOptions};
}