aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--askama_derive/src/generator.rs2
-rw-r--r--askama_derive/src/heritage.rs4
-rw-r--r--askama_parser/src/lib.rs4
-rw-r--r--askama_parser/src/node.rs21
4 files changed, 19 insertions, 12 deletions
diff --git a/askama_derive/src/generator.rs b/askama_derive/src/generator.rs
index 626c7d2..f33829d 100644
--- a/askama_derive/src/generator.rs
+++ b/askama_derive/src/generator.rs
@@ -214,7 +214,7 @@ fn find_used_templates(
for n in parsed.nodes() {
match n {
Node::Extends(extends) => {
- let extends = input.config.find_template(extends, Some(&path))?;
+ let extends = input.config.find_template(extends.path, Some(&path))?;
let dependency_path = (path.clone(), extends.clone());
if dependency_graph.contains(&dependency_path) {
return Err(format!(
diff --git a/askama_derive/src/heritage.rs b/askama_derive/src/heritage.rs
index 1122e39..f09b83e 100644
--- a/askama_derive/src/heritage.rs
+++ b/askama_derive/src/heritage.rs
@@ -58,10 +58,10 @@ impl Context<'_> {
while let Some(nodes) = nested.pop() {
for n in nodes {
match n {
- Node::Extends(extends_path) if top => match extends {
+ Node::Extends(e) if top => match extends {
Some(_) => return Err("multiple extend blocks found".into()),
None => {
- extends = Some(config.find_template(extends_path, Some(path))?);
+ extends = Some(config.find_template(e.path, Some(path))?);
}
},
Node::Macro(m) if top => {
diff --git a/askama_parser/src/lib.rs b/askama_parser/src/lib.rs
index 6822233..bd7edde 100644
--- a/askama_parser/src/lib.rs
+++ b/askama_parser/src/lib.rs
@@ -16,8 +16,8 @@ use nom::{error_position, AsChar, IResult, InputTakeAtPosition};
pub use self::expr::Expr;
pub use self::node::{
- BlockDef, Call, Cond, CondTest, If, Import, Include, Let, Lit, Loop, Macro, Match, Node, Raw,
- Target, When, Whitespace, Ws,
+ BlockDef, Call, Cond, CondTest, Extends, If, Import, Include, Let, Lit, Loop, Macro, Match,
+ Node, Raw, Target, When, Whitespace, Ws,
};
mod expr;
diff --git a/askama_parser/src/node.rs b/askama_parser/src/node.rs
index cb6da92..b955549 100644
--- a/askama_parser/src/node.rs
+++ b/askama_parser/src/node.rs
@@ -24,7 +24,7 @@ pub enum Node<'a> {
If(If<'a>),
Match(Match<'a>),
Loop(Loop<'a>),
- Extends(&'a str),
+ Extends(Extends<'a>),
BlockDef(BlockDef<'a>),
Include(Include<'a>),
Import(Import<'a>),
@@ -53,7 +53,7 @@ impl<'a> Node<'a> {
map(|i| If::parse(i, s), Self::If),
|i| Self::r#for(i, s),
map(|i| Match::parse(i, s), Self::Match),
- Self::extends,
+ map(Extends::parse, Self::Extends),
map(Include::parse, Self::Include),
map(Import::parse, Self::Import),
map(|i| BlockDef::parse(i, s), Self::BlockDef),
@@ -135,11 +135,6 @@ impl<'a> Node<'a> {
))
}
- fn extends(i: &'a str) -> IResult<&'a str, Self> {
- let (i, (_, name)) = tuple((ws(keyword("extends")), ws(str_lit)))(i)?;
- Ok((i, Self::Extends(name)))
- }
-
fn r#break(i: &'a str, s: &State<'_>) -> IResult<&'a str, Self> {
let mut p = tuple((
opt(Whitespace::parse),
@@ -857,6 +852,18 @@ impl<'a> Include<'a> {
}
}
+#[derive(Debug, PartialEq)]
+pub struct Extends<'a> {
+ pub path: &'a str,
+}
+
+impl<'a> Extends<'a> {
+ fn parse(i: &'a str) -> IResult<&'a str, Self> {
+ let (i, path) = preceded(ws(keyword("extends")), cut(ws(str_lit)))(i)?;
+ Ok((i, Self { path }))
+ }
+}
+
/// First field is "minus/plus sign was used on the left part of the item".
///
/// Second field is "minus/plus sign was used on the right part of the item".