Skip to content

Commit a35adee

Browse files
committed
Make call_tag a standalone function
This will allow it to be used in `SimpleBlockTag::render` in addition to `SimpleTag::render`.
1 parent 80dcb8c commit a35adee

File tree

1 file changed

+17
-18
lines changed

1 file changed

+17
-18
lines changed

src/render/tags.rs

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -765,22 +765,21 @@ impl Render for For {
765765
}
766766
}
767767

768-
impl SimpleTag {
769-
fn call_tag<'t>(
770-
&self,
771-
py: Python<'_>,
772-
template: TemplateString<'t>,
773-
args: VecDeque<Bound<'_, PyAny>>,
774-
kwargs: Bound<'_, PyDict>,
775-
) -> RenderResult<'t> {
776-
let func = self.func.bind(py);
777-
match func.call(
778-
PyTuple::new(py, args).expect("All arguments should be valid Python objects"),
779-
Some(&kwargs),
780-
) {
781-
Ok(content) => Ok(Cow::Owned(content.to_string())),
782-
Err(error) => Err(error.annotate(py, self.at, "here", template).into()),
783-
}
768+
fn call_tag<'t>(
769+
py: Python<'_>,
770+
func: &Arc<Py<PyAny>>,
771+
at: (usize, usize),
772+
template: TemplateString<'t>,
773+
args: VecDeque<Bound<'_, PyAny>>,
774+
kwargs: Bound<'_, PyDict>,
775+
) -> RenderResult<'t> {
776+
let func = func.bind(py);
777+
match func.call(
778+
PyTuple::new(py, args).expect("All arguments should be valid Python objects"),
779+
Some(&kwargs),
780+
) {
781+
Ok(content) => Ok(Cow::Owned(content.to_string())),
782+
Err(error) => Err(error.annotate(py, at, "here", template).into()),
784783
}
785784
}
786785

@@ -851,14 +850,14 @@ impl Render for SimpleTag {
851850
let py_context = add_context_to_args(py, &mut args, context)?;
852851

853852
// Actually call the tag
854-
let result = self.call_tag(py, template, args, kwargs);
853+
let result = call_tag(py, &self.func, self.at, template, args, kwargs);
855854

856855
retrieve_context(py, py_context, context);
857856

858857
// Return the result of calling the tag
859858
result
860859
} else {
861-
self.call_tag(py, template, args, kwargs)
860+
call_tag(py, &self.func, self.at, template, args, kwargs)
862861
}
863862
}
864863
}

0 commit comments

Comments
 (0)