Deprecate most of "templatelib" in favor of Sprig#23
Deprecate most of "templatelib" in favor of Sprig#23tianon wants to merge 1 commit intodocker-library:masterfrom
Conversation
|
I have successfully tested this against all of https://github.com/docker-library/docs with no changes. 😅 |
| } | ||
| } | ||
|
|
||
| var FuncMap = template.FuncMap{ |
There was a problem hiding this comment.
I guess I could get fancy with github.com/imdario/mergo to avoid changing the signature of templatelib.FuncMap, but I'm not aware of any actual users of it, so I'm not sure it's worth going to the trouble? 😇
(I'd love to convert our uses of functions like trimSuffixes, trimPrefixes, join, and getenv to be compatible with their Sprig counterparts so we could deprecate/remove our custom versions too, which shouldn't be too much work.)
It implements many of the same functions like `first`, `last`, `ternary`, etc, some just with a different name like `toJson` vs `json`, and gives us *many* more useful functions.
| // turns: git://github.com/jsmith/some-repo.git | ||
| // into: https://github.com/jsmith/some-repo | ||
| funcMap["trimPrefixes"] = stringsActionFactory("trimPrefixes", false, stringsModifierActionFactory(strings.TrimPrefix)) | ||
| funcMap["trimSuffixes"] = stringsActionFactory("trimSuffixes", false, stringsModifierActionFactory(strings.TrimSuffix)) |
There was a problem hiding this comment.
These support a list of prefixes/suffixes, but I'm reasonably certain we've never actually used that functionality, so all our uses should be able to port to trimPrefix and trimSuffix.
There was a problem hiding this comment.
Just confirmed, trimPrefixes is something we've never actually used, and trimSuffixes is literally only used with .git as a single argument. 😅
| // Everybody: {{- join ", " .Names -}} | ||
| // Concat: {{- join "/" "https://github.com" "jsmith" "some-repo" -}} | ||
| funcMap["join"] = stringsActionFactory("join", true, strings.Join) | ||
| // (this differs slightly from the Sprig "join" in that it accepts either a list of strings or multiple arguments - Sprig instead has an explicit "list" function which can create a list of strings *from* a list of arguments so that multiple-signature usability like this is not necessary) |
There was a problem hiding this comment.
I guess in looking at https://masterminds.github.io/sprig/string_slice.html, the key here will be to verify that we can start porting to the list ... | join ... syntax with this implementation so that at some point we can drop this.
It implements many of the same functions like
first,last,ternary, etc, some just with a different name liketoJsonvsjson, and gives us many more useful functions.Closes #22
(This includes a workaround/implementation for Masterminds/sprig#276 which could hopefully be dropped in a future version. 🤞 😅)