Skip to content

Commit

Permalink
feat: conveniently access an Output's template func map
Browse files Browse the repository at this point in the history
  • Loading branch information
muesli committed Sep 22, 2022
1 parent 6dd5b52 commit 6a2da83
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions templatehelper.go
Expand Up @@ -4,11 +4,17 @@ import (
"text/template"
)

// TemplateFuncs returns template helpers for the given output.
func (o Output) TemplateFuncs() template.FuncMap {
return TemplateFuncs(o.Profile)
}

// TemplateFuncs contains a few useful template helpers.
func TemplateFuncs(p Profile) template.FuncMap {
if p == Ascii {
return noopTemplateFuncs
}

return template.FuncMap{
"Color": func(values ...interface{}) string {
s := p.String(values[len(values)-1].(string))
Expand Down

0 comments on commit 6a2da83

Please sign in to comment.