quicktemplate icon indicating copy to clipboard operation
quicktemplate copied to clipboard

Use custom Localizer/Formatter

Open aight8 opened this issue 5 years ago • 0 comments

Using all the {%s,d,u shortcuts is nice, it would be awesome when I could define my own "Writer", at least for all the basic stuff. Greater were when I could define an own localizer/formatter object which is passed trough all the render functions.

This would it really easy to pass a localizer/formatter once and then it's propagated down to all other building blocks.

With go2 generics It would be easy. But for now, It must be solved by define a custom type to the parser - so it use those for the basic write operations and also make it accessible directly in the template.

I can also imagine a template syntax which can access the methods more easily (like golang template funcmap). Like: {%! DoSomething() %} is translated to call the DoSomething method on the defined object. Because the parser have no clue about the return value, the return value must be printer like {%v ... %}. Later this could be optimized by on-compile reflection.

aight8 avatar Dec 03 '20 14:12 aight8