Skip to content

Commit

Permalink
✨ Add repo and tag template funcs
Browse files Browse the repository at this point in the history
  • Loading branch information
gabe565 committed May 6, 2022
1 parent 65f9402 commit f8b374e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
13 changes: 13 additions & 0 deletions pkg/template/funcs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package template

import "strings"

func DockerRepo(image string) string {
split := strings.SplitN(image, ":", 2)
return split[0]
}

func DockerTag(image string) string {
split := strings.SplitN(image, ":", 2)
return split[1]
}
9 changes: 8 additions & 1 deletion pkg/template/line_comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ import (
"text/template"
)

var funcMap = sprig.TxtFuncMap()

func init() {
funcMap["repo"] = DockerRepo
funcMap["tag"] = DockerTag
}

func RecurseNode(conf config.Config, node *yaml.Node) error {
if len(node.Content) == 0 {
if err := TemplateLineComment(conf, node); err != nil {
Expand All @@ -26,7 +33,7 @@ func RecurseNode(conf config.Config, node *yaml.Node) error {
func TemplateLineComment(conf config.Config, node *yaml.Node) error {
if node.LineComment != "" && strings.HasPrefix(node.LineComment, conf.Prefix) {
tmpl, err := template.New("").
Funcs(sprig.TxtFuncMap()).
Funcs(funcMap).
Delims(conf.LeftDelim, conf.RightDelim).
Option("missingkey=error").
Parse(strings.TrimSpace(node.LineComment[len(conf.Prefix):]))
Expand Down

0 comments on commit f8b374e

Please sign in to comment.