jet
jet copied to clipboard
add time related utility functions
I think most users would benefit from having something like now()
available, which would expose Go's time.Now(). This would give you immediate access to all the Methods on Go's time.Time type. Other useful functions could be parseTime()
(time.Parse) and since()
(time.Since).
My personal opinion is that we shouldn't open the door to Jet becoming a kitchen sink of functions.
Currently per the docs we have isset()
and len()
and map()
and then escape helpers, which I think are all very "basic" and germane. The strings stuff is a little less intuitive to have but string handling is probably the next most universal thing, and what's done is done there.
Rather than adding more builtin functions, maybe make a set of Jet functions available as a library that's easy to pull in and attach to your renderer? Something like Sprig perhaps: https://github.com/Masterminds/sprig
This way everything is orthogonal and Jet and its builtins can stay focused on the mechanics of rendering, data traversal, etc.
Good idea! I agree making it easy enough to make it available yourself is enough.
Maybe you haven't seen the new array() and slice() builtins (array is just an alias for people unfamiliar with the concept of a slice). They feel at home in the list of built-ins, though, next to map().
Ah, yeah I hadn't seen those two. But yeah, those are exactly what I would think of as core builtins. Data manipulation and traversal within the templates and so on.
In terms of what could go in a utility library, here's looking at Sprig for inspiration again: http://masterminds.github.io/sprig/
Looks like strings, math, date, some control flow, default-fallback, encoding, lists, dictionaries, file path, UUIDs, crypto...
Also looking through the Go stdlib...maybe some caching regexp functions...url handling...sorting...
Anyway, tons could be done there. I wonder if it would make sense to put it in the Jet repo, or better as its own? In some ways I think having it in the same repo would be good, although it may increase the number of dependencies Jet has if the utilities started pulling in lots of stuff.
It would be part of the module, but in its own package, so you have to explicitly import it. Then again, most of the functions will be from the standard library, so there wouldn't be many (if any) external dependencies when you pull in these "extension packages".