aboutsummaryrefslogtreecommitdiffstats
path: root/askama_derive/src/input.rs
diff options
context:
space:
mode:
authorLibravatar max <gmx.sht@gmail.com>2023-12-08 14:38:35 +0200
committerLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2024-01-17 17:58:53 +0100
commit411efb89278305a0c38f1f28924a02e03b161679 (patch)
tree06af7e2433f9cb714e1a62777b10dd9b1c031e68 /askama_derive/src/input.rs
parent5cad82f38e800a42717284f20e7e0923add1e32f (diff)
downloadaskama-411efb89278305a0c38f1f28924a02e03b161679.tar.gz
askama-411efb89278305a0c38f1f28924a02e03b161679.tar.bz2
askama-411efb89278305a0c38f1f28924a02e03b161679.zip
Deduplicating some code in `find_used_templates`
Signed-off-by: max <gmx.sht@gmail.com>
Diffstat (limited to '')
-rw-r--r--askama_derive/src/input.rs15
1 files changed, 9 insertions, 6 deletions
diff --git a/askama_derive/src/input.rs b/askama_derive/src/input.rs
index 54facdc..7314d2e 100644
--- a/askama_derive/src/input.rs
+++ b/askama_derive/src/input.rs
@@ -118,6 +118,12 @@ impl TemplateInput<'_> {
let mut nested = vec![parsed.nodes()];
while let Some(nodes) = nested.pop() {
for n in nodes {
+ let mut add_to_check = |path: PathBuf| -> Result<(), CompileError> {
+ let source = get_template_source(&path)?;
+ check.push((path, source));
+ Ok(())
+ };
+
use Node::*;
match n {
Extends(extends) if top => {
@@ -134,21 +140,18 @@ impl TemplateInput<'_> {
.into());
}
dependency_graph.push(dependency_path);
- let source = get_template_source(&extends)?;
- check.push((extends, source));
+ add_to_check(extends)?;
}
Macro(m) if top => {
nested.push(&m.nodes);
}
Import(import) if top => {
let import = self.config.find_template(import.path, Some(&path))?;
- let source = get_template_source(&import)?;
- check.push((import, source));
+ add_to_check(import)?;
}
Include(include) => {
let include = self.config.find_template(include.path, Some(&path))?;
- let source = get_template_source(&include)?;
- check.push((include, source));
+ add_to_check(include)?;
}
BlockDef(b) => {
nested.push(&b.nodes);