-
Notifications
You must be signed in to change notification settings - Fork 58
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
Deprecate most of "templatelib" in favor of Sprig #23
base: master
Are you sure you want to change the base?
Conversation
I have successfully tested this against all of https://github.com/docker-library/docs with no changes. 😅 |
@@ -68,55 +69,33 @@ func stringsModifierActionFactory(a func(string, string) string) func([]string, | |||
} | |||
} | |||
|
|||
var FuncMap = template.FuncMap{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 liketoJson
vsjson
, 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. 🤞 😅)