-
Notifications
You must be signed in to change notification settings - Fork 108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add time related utility functions #160
Comments
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 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". |
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 beparseTime()
(time.Parse) andsince()
(time.Since).The text was updated successfully, but these errors were encountered: