@@ -70,9 +70,14 @@ func stringsModifierActionFactory(a func(string, string) string) func([]string,
70
70
// TODO write some tests for these
71
71
72
72
var FuncMap = template.FuncMap {
73
+ // {{- $isGitHub := hasPrefix "https://github.com/" $url -}}
74
+ // {{- $isHtml := hasSuffix ".html" $url -}}
73
75
"hasPrefix" : swapStringsFuncBoolArgsOrder (strings .HasPrefix ),
74
76
"hasSuffix" : swapStringsFuncBoolArgsOrder (strings .HasSuffix ),
75
77
78
+ // {{- $hugeIfTrue := .SomeValue | ternary "HUGE" "not so huge" -}}
79
+ // if .SomeValue is truthy, $hugeIfTrue will be "HUGE"
80
+ // (otherwise, "not so huge")
76
81
"ternary" : func (truthy interface {}, falsey interface {}, val interface {}) interface {} {
77
82
if t , ok := template .IsTrue (val ); ! ok {
78
83
panic (fmt .Sprintf (`template.IsTrue(%+v) says things are NOT OK` , val ))
@@ -83,14 +88,26 @@ var FuncMap = template.FuncMap{
83
88
}
84
89
},
85
90
91
+ // First Tag: {{- .Tags | first -}}
92
+ // Last Tag: {{- .Tags | last -}}
86
93
"first" : thingsActionFactory ("first" , true , func (args []interface {}, arg interface {}) interface {} { return arg }),
87
94
"last" : thingsActionFactory ("last" , false , func (args []interface {}, arg interface {}) interface {} { return arg }),
88
95
96
+ // JSON data dump: {{ json . }}
97
+ // (especially nice for taking data and piping it to "jq")
98
+ // (ie "some-tool inspect --format '{{ json . }}' some-things | jq .")
89
99
"json" : func (v interface {}) (string , error ) {
90
100
j , err := json .Marshal (v )
91
101
return string (j ), err
92
102
},
93
- "join" : stringsActionFactory ("join" , true , strings .Join ),
103
+
104
+ // Everybody: {{- join ", " .Names -}}
105
+ // Concat: {{- join "/" "https://github.com" "jsmith" "some-repo" -}}
106
+ "join" : stringsActionFactory ("join" , true , strings .Join ),
107
+
108
+ // {{- $mungedUrl := $url | replace "git://" "https://" | trimSuffixes ".git" -}}
109
+ // turns: git://github.com/jsmith/some-repo.git
110
+ // into: https://github.com/jsmith/some-repo
94
111
"trimPrefixes" : stringsActionFactory ("trimPrefixes" , false , stringsModifierActionFactory (strings .TrimPrefix )),
95
112
"trimSuffixes" : stringsActionFactory ("trimSuffixes" , false , stringsModifierActionFactory (strings .TrimSuffix )),
96
113
"replace" : stringsActionFactory ("replace" , false , func (strs []string , str string ) string {
0 commit comments