glance
glance copied to clipboard
Use sprig for custom api templates
Description
I noticed on the custom API handler, all functions are implemented within the file.
I'd recommend using this sprig instead so there's more functions available.
For what its worth, sprig is used in oh-my-posh as well and is a very mature library.
I second this. I also stumbled upon the allegedly better maintained sprout.
Someone from the Discord server already mentioned sprig a while ago and I've been looking at their docs for inspiration, but I haven't straight up added the library for a couple of reasons.
- I want to keep the templates simple and with idiomatic ways of doing things. The lisp/clojure-style syntax that Go's templates use gets ugly very quickly when surrounded by HTML, so the less code it takes to achieve something, the better. IMO Sprout provides too many "low-level" functions that allow you to fiddle around with minute and unnecessary details, making the templates more imperative, when I want them to be more declarative. I prefer adding new functions as necessary and having them work well with one another.
- There are name collisions with existing functions, meaning this would be a backwards-incompatible change, which would unnecessarily break a bunch of the existing custom widgets.
- It's one more place where you have to look at docs. If you're someone who isn't familiar with Go's template syntax and want to make a custom widget, you now have to read Go's docs, gjson's docs, Glance's docs, and Sprout's docs. That's a lot and very cumbersome.
- It's another dependency, and I'm trying to keep them to a minimum.