Skip to content

Commit

Permalink
Expose template functions for writers
Browse files Browse the repository at this point in the history
  • Loading branch information
jgustie committed Nov 30, 2021
1 parent 297c1e8 commit 9c0c447
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions pkg/konjure/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@ type Writer struct {
// Flag indicating nodes should be sorted before writing.
Sort bool
// Flag indicating we should attempt to restore vertical white space using
// line numbers prior to writing.
// line numbers prior to writing YAML output.
RestoreVerticalWhiteSpace bool
// Additional functions to use while evaluating Go templates.
Functions template.FuncMap
}

// Write delegates to the format specific writer.
Expand Down Expand Up @@ -106,8 +108,9 @@ func (w *Writer) Write(nodes []*yaml.RNode) error {

case "template", "go-template":
ww = &TemplateWriter{
Writer: w.Writer,
Template: w.Format[templateStart:],
Writer: w.Writer,
Template: w.Format[templateStart:],
Functions: w.Functions,
}

case "columns", "custom-columns":
Expand All @@ -120,6 +123,7 @@ func (w *Writer) Write(nodes []*yaml.RNode) error {

ww = &TemplateWriter{
Writer: tabwriter.NewWriter(w.Writer, 3, 0, 3, ' ', 0),
Functions: w.Functions,
WrappingAPIVersion: "v1",
WrappingKind: "List",
Template: "{{ if .items }}" + strings.Join(headers, "\t") +
Expand Down

0 comments on commit 9c0c447

Please sign in to comment.