Skip to content
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

Open
sauerbraten opened this issue Jul 3, 2020 · 4 comments
Open

add time related utility functions #160

sauerbraten opened this issue Jul 3, 2020 · 4 comments

Comments

@sauerbraten
Copy link
Collaborator

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).

@tooolbox
Copy link
Contributor

tooolbox commented Jul 3, 2020

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.

@sauerbraten
Copy link
Collaborator Author

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().

@tooolbox
Copy link
Contributor

tooolbox commented Jul 3, 2020

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.

@sauerbraten
Copy link
Collaborator Author

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".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants