treasure-map

module
v0.0.0-...-da5d8ec Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 18, 2022 License: 0BSD

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}}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL