mitsuhiko / minijinja

MiniJinja is a powerful but minimal dependency template engine for Rust compatible with Jinja/Jinja2
https://docs.rs/minijinja/
Apache License 2.0
1.66k stars 101 forks source link

starlark integration #544

Closed hhoeflin closed 3 months ago

hhoeflin commented 3 months ago

Hi,

I was wondering if you ever considered making starlark (https://github.com/facebook/starlark-rust) part of jinja? With its roots in python, i thought that would potentially be a great fit to make minijinja a bit more accessible also to people who come from jinja2 and need some custom filters they have in python.

Thanks for your work

mitsuhiko commented 3 months ago

I’m not even sure what this would look like or what needs that would solve. Could you be more specific in what you have in mind?

mitsuhiko commented 3 months ago

Closing due to inactivity.

hhoeflin commented 3 months ago

Sorry was on vacation and couldn't reply in time.

The basic idea here would be to provide a jinja-tag that allows to define starlark functions in the template itself or to provide separate starlark modules that are read. These would then provide any functionality for which the standard filters are not enough or for light processing where some logic is needed.

An advantage compared to the current custom functions or filters would be that

As starlark is safe to execute for untrusted code (outside of denial of service attack scenarios), this would help in the scenario where you would have to trust and run someone elses code.

Given jinja's roots in python, I thought starlark fills the gap where currently custom functionality needs to be provided in rust (minijinja) or a custom python environment needs to be build (jinja2) and get jinja to a place where it could be run in a CLI-only fashion in many more scenarios.

Of course I am not a power-user so I don't know if this is a really useful suggestion. I mostly wanted to make the suggestion as I was quite surprised in my search that really no-one had brought this up before.

mitsuhiko commented 3 months ago

I think stuff like this could be explored independently of minijinja/jinja2 to see if there is appetite.