diff --git a/golink.go b/golink.go index 7bbffcd..b58b60c 100644 --- a/golink.go +++ b/golink.go @@ -651,7 +651,10 @@ func (e expandEnv) User() (string, error) { var expandFuncMap = texttemplate.FuncMap{ "PathEscape": url.PathEscape, "QueryEscape": url.QueryEscape, + "TrimPrefix": strings.TrimPrefix, "TrimSuffix": strings.TrimSuffix, + "ToLower": strings.ToLower, + "ToUpper": strings.ToUpper, "Match": regexMatch, } diff --git a/golink_test.go b/golink_test.go index f65fda4..564a56b 100644 --- a/golink_test.go +++ b/golink_test.go @@ -411,12 +411,30 @@ func TestExpandLink(t *testing.T) { remainder: "a/b+c", want: "http://host.com/a%2Fb%2Bc", }, + { + name: "template-with-trimprefix-func", + long: `http://host.com/{{TrimPrefix .Path "BUG-"}}`, + remainder: "BUG-123", + want: "http://host.com/123", + }, { name: "template-with-trimsuffix-func", long: `http://host.com/{{TrimSuffix .Path "/"}}`, remainder: "a/", want: "http://host.com/a", }, + { + name: "template-with-tolower-func", + long: `http://host.com/{{ToLower .Path}}`, + remainder: "BUG-123", + want: "http://host.com/bug-123", + }, + { + name: "template-with-toupper-func", + long: `http://host.com/{{ToUpper .Path}}`, + remainder: "bug-123", + want: "http://host.com/BUG-123", + }, { name: "template-with-match-func", long: `http://host.com/{{if Match "\\d+" .Path}}id/{{.Path}}{{else}}search/{{.Path}}{{end}}`, diff --git a/tmpl/help.html b/tmpl/help.html index 63e5489..7b66b61 100644 --- a/tmpl/help.html +++ b/tmpl/help.html @@ -63,7 +63,10 @@

Advanced destination links