Open nkh opened 1 year ago
Greetings!
This is really great idea, and I wish I had thought of it earlier.
A challenge is determining a parsable pattern that works for all current tag types:
<% ... %>
<%"..."%>
<%% ... %>
Of course we'll also want the delimiter(s) to be configurable.
I tend to want to put the formatting at the end of the tag vs the beginning to keep the focus on the data, but having it at the beginning will be easier to parse.
When using the default delimiters <% %>
, I think we need to wrap the formatting in something like |%xx|
so that the %
doesn't conflict, especially if the default statement delimiter %
is configured.
Something like:
<%|%xx| ... %>
<%|%xx|"..."%>
<%|%xx|% ... %>
I do see value in a more verbose version, so maybe when the tag and statement delimiters are configured to be something other than <% %>
and %
we could support something like:
{{%xx ... }}
{{%xx "..."}}
{{%xx $ ... }}
Essentially I see the default delimiters as |%
and |
and being able to configure them as %
and
(space) as long as they don't cause conflicts.
NOTE: I'm considering the %
to be a configurable delimiter here so you could even remove it, ie:
<%|xx| ... %>
<%|xx|"..."%>
<%|xx|% ... %>
I'm interested in your thoughts on these
Thanks for taking the time to create the discussion and for your interest in my project!
-TW
hi, what about
{{ '%s %03d' $text $figure }}
that can be passed as is to printf, no need for a new format if an old one works and in this case it fits right in.
it would also make the template below possible
<%
color=green
%>
{{"$color %s" $some_variable}}
And maybe even
{{"%$format" $variable}}
it would have been nice to dynamically generate tables but the code below can't repeat dash signs
printf '=%.0s' {1..100}
after testing a bit more I found out that the code below would work
printf -- '-%.0s' {1..13}
which means accepting
{{ -- '-%.0s' {1..13} }}
+------------------+---------+-------------------+
| | | |
+------------------+---------+-------------------+
| {{%-13s $1 }} | ....... | {{%17s $ENV_VARIABLE}} |
| {{%-13s $2 }} | ....... | {{%17s $ENV_VARIABLE}} |
+---------------+---------+-------------------+
# ugly but parameterized
+-{{ -- '-%.0s' {1..13} }}-+---------+-{{ -- '-%.0s' {1..17} }}-+
| {{ -- '-%.0s' {1..13} }} | | {{ -- '-%.0s' {1..17} }} |
+-{{ -- '-%.0s' {1..13} }}-+---------+-{{ -- '-%.0s' {1..17} }}-+
| {{ '%-13s' $1 }} | ....... | {{ '%17s' $ENV_VARIABLE}} |
| {{ '%-13s' $1 }} | ....... | {{ '%17s' $ENV_VARIABLE}} |
+-{{ -- '-%.0s' {1..13} }}-+---------+-{{ -- '-%.0s' {1..17} }}-+
# and with some pre-computation
{{ $HEADER }}
| {{ '%-13s' $1 }} | ....... | {{ '%17s' $ENV_VARIABLE}} |
| {{ '%-13s' $1 }} | ....... | {{ '%17s' $ENV_VARIABLE}} |
{{ $FOOTER}}
# and with column formats in variables
{{ $HEADER }}
| $cf1 $1 }} | ....... | {{ $cf2 $ENV_VARIABLE}} |
| $cf1 $1 }} | ....... | {{ $cf2 $ENV_VARIABLE}} |
{{ $FOOTER}}
Hi, nice work
Would it be possible to pass a format string to printf? Here's an example without
and with,