Open Keats opened 3 weeks ago
I could be wrong but it looks like you also changed as_str
to str
?
new filters wanted (no deps only)
pad
(see https://github.com/Keats/tera/pull/921)repeat(n)
- repeat a string n times, result could either be an array or a joined string, though an array would probably be better for broader usecaseswanted changes of behaviour
I know you have some opinions on https://github.com/Keats/tera/issues/421 though I think it should be revisited, at least concerning basic regex - no need for complicated capture groups and such.
It would be nice to be able to use positional args, though this isn't filters-specific as it also applies to macros. Maybe through some prefix before the argument name in the declaration, e.g. {% macro say_hello(*name) %}
where the asterisk changes it from a kwarg to a positional arg?
Would it ever be possible to use https://keats.github.io/tera/docs/#map to apply a macro/filter to all elements of an array? This could be implemented without breaking existing behavior since a new kwarg could be used, e.g. | map(func=self::say_hello)
.
For repeat
I would follow what Python does, eg:
>>> " " * 10
' '
>>> [0] * 10
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
>>>
so the output depends on the input.
For pad, I think a format
filter would be better so it can be used for padding but also for displaying floats with 2 decimals for example.
tera-contrib
crateFor
repeat
I would follow what Python does, eg:>>> " " * 10 ' ' >>> [0] * 10 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] >>>
so the output depends on the input.
Makes sense to me... are you saying you are okay adding a filter like this?
For pad, I think a
format
filter would be better so it can be used for padding but also for displaying floats with 2 decimals for example.
Hmm how would displaying a float with 2 decimals work? I'm thinking of pad
being used like {{ "def" | pad(len=6, fill="_", before=true) }}
-> "___def"
.
- I want to keep kwargs only. It's slightly less nice when there's a single required argument but otherwise it's much more readable imo.
I agree but even that case where there is only a single required argument is pretty common I'd think. Besides, most programming languages default to positional arguments and the only language I can think of off the top of my head that does kwargs is Python, which also supports positional args.
are you saying you are okay adding a filter like this?
Yes. Either that or overload *
to do that automatically in the template without the repeat filter, one or the other.
For format, I'm thinking to basically use the Rust format: https://saghm.github.io/five-rust-things/#padding-format-operator
Here is the issue to mention:
Known missing:
Current changes:
pat
argument for start/end rather than separate filtersint
andfloat
filter do not have a default anymoreround
filter does not take acommon
method anymore, it's the default and should not be filled if neededindent
filter now takes awidth
param rather thanprefix
map
,group_by
andfilter
filter will error if the attribute ends up being undefined on one of the valueas_str
has been renamed tostr