template

package
v2.10.0 Latest Latest
Warning

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

Go to latest
Published: May 15, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package template is a text/template binding for Starlark.

Index

Constants

This section is empty.

Variables

View Source
var Module = starlark.StringDict{
	"run": starlark.NewBuiltin("run", func(th *starlark.Thread, fn *starlark.Builtin, args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error) {
		var tpl string
		var data ourstar.Any
		if err := starlark.UnpackArgs(fn.Name(), args, kwargs, "template", &tpl, "data", &data); err != nil {
			return nil, errors.Wrap(err, "unpack args")
		}
		t, err := template.New("<arg>").Parse(tpl)
		if err != nil {
			return nil, errors.Wrap(err, "parse template")
		}
		var result bytes.Buffer
		if err := t.Execute(&result, data.Value); err != nil {
			return nil, errors.Wrap(err, "execute template")
		}
		return starlark.String(result.String()), nil
	},
	),
}

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

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