aboutsummaryrefslogtreecommitdiffstats
path: root/askama_derive/src/generator.rs
diff options
context:
space:
mode:
authorLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2023-10-06 11:36:59 +0200
committerLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2023-11-01 12:52:09 +0100
commit7979d5c1dd790d1821c9c4c77c848f47ac49c769 (patch)
tree897aeb90363218d698c86c44f366d7ca4f31a2e3 /askama_derive/src/generator.rs
parentb9e2187cd8b4a335113c966c0e9b53f3726e59d3 (diff)
downloadaskama-7979d5c1dd790d1821c9c4c77c848f47ac49c769.tar.gz
askama-7979d5c1dd790d1821c9c4c77c848f47ac49c769.tar.bz2
askama-7979d5c1dd790d1821c9c4c77c848f47ac49c769.zip
Attach find_used_templates() to TemplateInput
Diffstat (limited to 'askama_derive/src/generator.rs')
-rw-r--r--askama_derive/src/generator.rs43
1 files changed, 1 insertions, 42 deletions
diff --git a/askama_derive/src/generator.rs b/askama_derive/src/generator.rs
index 3374161..21b8d25 100644
--- a/askama_derive/src/generator.rs
+++ b/askama_derive/src/generator.rs
@@ -31,7 +31,7 @@ pub(crate) fn build_template(ast: &syn::DeriveInput) -> Result<String, CompileEr
};
let mut templates = HashMap::new();
- find_used_templates(&input, &mut templates, source)?;
+ input.find_used_templates(&mut templates, source)?;
let mut contexts = HashMap::new();
for (path, parsed) in &templates {
@@ -66,47 +66,6 @@ pub(crate) fn build_template(ast: &syn::DeriveInput) -> Result<String, CompileEr
Ok(code)
}
-fn find_used_templates(
- input: &TemplateInput<'_>,
- map: &mut HashMap<PathBuf, Parsed>,
- source: String,
-) -> Result<(), CompileError> {
- let mut dependency_graph = Vec::new();
- let mut check = vec![(input.path.clone(), source)];
- while let Some((path, source)) = check.pop() {
- let parsed = Parsed::new(source, input.syntax)?;
- for n in parsed.nodes() {
- match n {
- Node::Extends(extends) => {
- 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!(
- "cyclic dependency in graph {:#?}",
- dependency_graph
- .iter()
- .map(|e| format!("{:#?} --> {:#?}", e.0, e.1))
- .collect::<Vec<String>>()
- )
- .into());
- }
- dependency_graph.push(dependency_path);
- let source = get_template_source(&extends)?;
- check.push((extends, source));
- }
- Node::Import(import) => {
- let import = input.config.find_template(import.path, Some(&path))?;
- let source = get_template_source(&import)?;
- check.push((import, source));
- }
- _ => {}
- }
- }
- map.insert(path, parsed);
- }
- Ok(())
-}
-
struct Generator<'a> {
// The template input state: original struct AST and attributes
input: &'a TemplateInput<'a>,