From ceb079732d6373051b713483abc0351e42ce60ac Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 12 Feb 2026 21:44:20 +0000 Subject: [PATCH] Convert Jinja2 replace() filter syntax to Tera named arguments Jinja2 uses positional args: replace('-', '_') Tera uses named args: replace(from="-", to="_") Added conversion in preprocess_jinja2_compat() to handle this automatically for IQL templates. https://claude.ai/code/session_01ShAyjRLWBYC3tPsusCxggv --- src/core/templating.rs | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/core/templating.rs b/src/core/templating.rs index b69b4b0..6a72390 100644 --- a/src/core/templating.rs +++ b/src/core/templating.rs @@ -233,12 +233,25 @@ fn split_dict_entries(s: &str) -> Vec { } /// Pre-process Jinja2-specific syntax into Tera-compatible equivalents. -/// Currently handles: -/// - `{{ uuid() }}` -> `{{ uuid }}` (Jinja2 function call to Tera variable) +/// Handles: +/// - `{{ uuid() }}` -> `{{ uuid }}` (function call to variable) +/// - `replace('x', 'y')` -> `replace(from="x", to="y")` (positional to named args) fn preprocess_jinja2_compat(template: &str) -> String { + let mut result = template.to_string(); + // Convert {{ uuid() }} to {{ uuid }} - let re = Regex::new(r"\{\{\s*uuid\(\)\s*\}\}").unwrap(); - re.replace_all(template, "{{ uuid }}").to_string() + let uuid_re = Regex::new(r"\{\{\s*uuid\(\)\s*\}\}").unwrap(); + result = uuid_re.replace_all(&result, "{{ uuid }}").to_string(); + + // Convert Jinja2 replace('from', 'to') to Tera replace(from="from", to="to") + // Matches: replace('x', 'y') or replace("x", "y") with any quoting combo + let replace_re = + Regex::new(r#"replace\(\s*['"]([^'"]*)['"]\s*,\s*['"]([^'"]*)['"]\s*\)"#).unwrap(); + result = replace_re + .replace_all(&result, r#"replace(from="$1", to="$2")"#) + .to_string(); + + result } /// Render a single query template with the given context.