renderer

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2018 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package renderer implements data-driven templates for generating textual output

The renderer extends the standard golang text/template and sprig functions.

Templates are executed by applying them to a data structure (configuration). Values in the template refer to elements of the data structure (typically a field of a struct or a key in a map).

Actions can be combined using UNIX-like pipelines.

The input text for a template is UTF-8-encoded text in any format.

Detailed documentation on the syntax and available functions can be found here:

Index

Constants

View Source
const (
	// MissingKeyInvalidOption is the renderer option to continue execution on missing key and print "<no value>"
	MissingKeyInvalidOption = "missingkey=invalid"
	// MissingKeyErrorOption is the renderer option to stops execution immediately with an error on missing key
	MissingKeyErrorOption = "missingkey=error"
	// LeftDelim is the default left template delimiter
	LeftDelim = "{{"
	// RightDelim is the default right template delimiter
	RightDelim = "}}"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Renderer

type Renderer struct {
	// contains filtered or unexported fields
}

Renderer structure holds parameters and options

func New

func New() *Renderer

New creates a new renderer with the specified parameters and zero or more options

func (*Renderer) Delim

func (r *Renderer) Delim(left, right string) *Renderer

Delim mutates Renderer with new left and right delimiters

func (*Renderer) Execute

func (r *Renderer) Execute(t *template.Template) (string, error)

Execute is a basic template execution function

func (*Renderer) Functions

func (r *Renderer) Functions(extraFunctions template.FuncMap) *Renderer

Functions mutates Renderer with new template functions

func (*Renderer) NamedRender

func (r *Renderer) NamedRender(templateName, rawTemplate string) (string, error)

NamedRender is the main rendering function, see also Render, Parameters and ExtraFunctions

func (*Renderer) Options

func (r *Renderer) Options(options ...string) *Renderer

Options mutates Renderer with new template functions

func (*Renderer) Parameters

func (r *Renderer) Parameters(parameters map[string]interface{}) *Renderer

Parameters mutates Renderer with new template parameters

func (*Renderer) Parse

func (r *Renderer) Parse(templateName, rawTemplate string, extraFunctions template.FuncMap) (*template.Template, error)

Parse is a basic template parsing function

func (*Renderer) Render

func (r *Renderer) Render(rawTemplate string) (string, error)

Render is a simple rendering function, also used as a custom template function to allow in-template recursive rendering, see also NamedRender

func (*Renderer) Validate

func (r *Renderer) Validate() error

Validate checks the internal state and returns error if necessary

Jump to

Keyboard shortcuts

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