From 411efb89278305a0c38f1f28924a02e03b161679 Mon Sep 17 00:00:00 2001 From: max Date: Fri, 8 Dec 2023 14:38:35 +0200 Subject: Deduplicating some code in `find_used_templates` Signed-off-by: max --- askama_derive/src/input.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'askama_derive') 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); -- cgit