rinja-rs / rinja

A template rendering engine based on Jinja, generating type-safe Rust code at compile time.
https://rinja.readthedocs.io
Apache License 2.0
144 stars 10 forks source link

Request: Allow comments on macro arguments #273

Open chrisp60 opened 4 hours ago

chrisp60 commented 4 hours ago

I am using git main

Admittedly, this use case is derived from a somewhat degenerate pattern.

I can define this macro...

{% macro input(name, value = "") %}
   <input name="{{ name }}" value="{{ value }}">
{% endmacro input %}

This fails to compile...

{% macro input(
    {# the name attribute of the input #}
    name, 
    value = "",
) %}
   <input name="{{ name }}" value="{{ value }}">
{% endmacro input %}

The error provided is... error: expected)to close macro argument list The error correctly points to the issue.

My use case for wanting this feature is the below macro definition. I have to make a substantial amount of user forms for my project.

{% macro input(
  name, 
  value = "", 
  label = "",
  prefix = "",
  kind = "text",
  autocomplete = "",
  required = false,
  div = "col-md-12 col-lg-4",
  attrs = "",
  ...[plus many more]
) %}

Why I am requesting this

Why this may not be a good feature

I would not at all be disappointed if this was rejected. If approved, I could attempt an implementation

GuillaumeGomez commented 4 hours ago

Problem here is that you want to be able add a delimiter inside a delimiter, which is not allowed in the jinja syntax. I agree it would be nice to be able to add docs on arguments, but in this case, it'd make rinja not compliant with jinja.

chrisp60 commented 3 hours ago

Yeah that is not something I did not even begin to consider. Up to you if you want to leave this up as a possibility for the future.

I imagine the compatibility is something you would prefer to keep. I am inclined to believe you if you say it just isn't possible.