Discover Packages
github.com/bluebrown/treasure-map
module
Version:
v0.0.0-...-da5d8ec
Opens a new window with list of versions in this module.
Published: Apr 18, 2022
License: 0BSD
Opens a new window with license information.
README
README
¶
Treasure Map
A collection of go template functions. Some functions are inspired by helm , i.e. include and tpl.
Usage
Some function require to close over the template itself. Therefore, the MakeFuncMap function takes the template as argument and returns the fully constructed map. In the below example sprigs TxtFuncMap is passed as base map.
import (
"testing"
"text/template"
"github.com/Masterminds/sprig/v3"
"github.com/bluebrown/treasure-map/textfunc"
)
func main() {
tpl := template.New("")
tpl.Funcs(textfunc.MapClosure(sprig.TxtFuncMap(), tpl))
}
Functions
Function
Description
Returns
Example
include
render a previously associated template
string
{{ include "my-helper" . }}
tpl
render a template snippet
string
{{ tpl "{{ .foo.bar }}" . }}
table
convert to table, list of object or list of lists
string
{{ table . }}
fromJson
convert a json string to map or slice (any)
interface{}
{{ fromJson . }}
toYaml
convert to yaml
string
{{ toYaml . }}
mustToYaml
convert to yaml, errors if encoding fails
string, error
{{ mustToYaml . }}
fromYaml
convert from yaml
interface{}
{{ fromYaml . }}
toToml
convert to toml
string
{{ toToml . }}
mustToToml
convert to toml, errors if encoding fails
string, error
{{ mustToToml . }}
fromToml
convert from toml
interface{}
{{ fromToml . }}
iter
get an iterator to use in range
[]int
{{ range iter 5 }}{{.}}{{end}}
Expand ▾
Collapse ▴
Directories
¶
Click to show internal directories.
Click to hide internal directories.