Skip to content

Commit

Permalink
Merge pull request #16 from bossm8/fb/toYaml
Browse files Browse the repository at this point in the history
Add custom function `toYaml`
  • Loading branch information
bossm8 authored Feb 26, 2024
2 parents 466d62e + 16d1f2b commit c3519b0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ The templater includes [sprig](https://github.com/Masterminds/sprig) (which is a
included in [helm](https://helm.sh/docs/chart_template_guide/functions_and_pipelines/))
to extend the limited set of [go template functions](https://pkg.go.dev/text/template#hdr-Functions).

It also contains a limited set of custom functions:

- `toYaml`
Paste yaml structures into templates:
```yaml
values: {{ toYaml .data | nindent 2 }}
```
### Variants YML
Flag: `--variants.def`
Expand Down Expand Up @@ -244,8 +252,8 @@ build-images:
--destination ${NAME}:${TAG}
done
needs:
job: generate-dockerfiles
artifacts: true
- job: generate-dockerfiles
artifacts: true
```

### Binary
Expand Down
14 changes: 13 additions & 1 deletion utils/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,23 @@ import (
"gopkg.in/yaml.v3"
)

// https://github.com/technosophos/k8s-helm/commit/431cc46cad3ae5248e32df1f6c44f2f4ce5547ba
func toYaml(v interface{}) string {
data, err := yaml.Marshal(v)
if err != nil {
return ""
}
return string(data)
}

// Parses a template defined in a file.
func ParseTemplate(
file string,
) *template.Template {
tpl := template.New(filepath.Base(file)).Funcs(sprig.FuncMap())
tpl := template.New(filepath.Base(file)).Funcs(
template.FuncMap{
"toYaml": toYaml,
}).Funcs(sprig.FuncMap())

var err error

Expand Down

0 comments on commit c3519b0

Please sign in to comment.