handle template includes
This commit is contained in:
parent
d7a364b1af
commit
6084b9072b
10
src/lib.rs
10
src/lib.rs
|
@ -6,7 +6,7 @@ use roxy_core::roxy::Parse;
|
||||||
|
|
||||||
const DEFAULT_CONTEXT: Lazy<tera::Context> = Lazy::new(|| tera::Context::default());
|
const DEFAULT_CONTEXT: Lazy<tera::Context> = Lazy::new(|| tera::Context::default());
|
||||||
const EXPANSION_RE: Lazy<Regex> =
|
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)]
|
#[derive(Debug)]
|
||||||
pub struct TeraParserOptions {
|
pub struct TeraParserOptions {
|
||||||
|
@ -44,7 +44,7 @@ impl<'a> TeraParser<'a> {
|
||||||
fn load_template(&mut self, path: &str, src: &[u8]) -> Result<(), tera::Error> {
|
fn load_template(&mut self, path: &str, src: &[u8]) -> Result<(), tera::Error> {
|
||||||
let str = String::from_utf8_lossy(src).to_string();
|
let str = String::from_utf8_lossy(src).to_string();
|
||||||
if let Some(captures) = EXPANSION_RE.captures(&str.as_str()) {
|
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 layout_path = layout_path.as_str();
|
||||||
let path = PathBuf::from(path).parent().map(|p| p.join(layout_path)).unwrap();
|
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)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
#[test]
|
use roxy_core::roxy::Parse;
|
||||||
fn it_works() {}
|
|
||||||
|
use crate::{TeraParser, TeraParserOptions};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue