From 6084b9072b9965612a3d5b17f8edc1714e3cde0a Mon Sep 17 00:00:00 2001 From: KitsuneCafe <10284516+kitsunecafe@users.noreply.github.com> Date: Mon, 5 Feb 2024 15:21:49 -0500 Subject: [PATCH] handle template includes --- src/lib.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index c81bce1..6d89b75 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -6,7 +6,7 @@ use roxy_core::roxy::Parse; const DEFAULT_CONTEXT: Lazy = Lazy::new(|| tera::Context::default()); const EXPANSION_RE: Lazy = - 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}; } +