renderer

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2018 License: Apache-2.0 Imports: 13 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.

See renderer.ExtraFunctions for our custom functions.

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

func Gzip added in v0.0.4

func Gzip(input interface{}) (string, error)

Gzip compresses the input using gzip algorithm

func ToYaml added in v0.0.4

func ToYaml(marshallable interface{}) (string, error)

ToYaml is a template function, it turns a marshallable structure into a YAML fragment

func Ungzip added in v0.0.4

func Ungzip(input interface{}) (string, error)

Ungzip un-compresses the input using gzip algorithm

Types

type Renderer

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

Renderer structure holds configuration and options

func New

func New(configuration configuration.Configuration, opts ...string) *Renderer

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

func (*Renderer) Delim added in v0.0.5

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

Delim mutates Renderer with new left and right delimiters

func (*Renderer) Execute added in v0.0.5

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

Execute is a basic template execution function

func (*Renderer) ExtraFunctions added in v0.0.4

func (r *Renderer) ExtraFunctions() template.FuncMap

ExtraFunctions provides additional template functions to the standard (text/template) ones, it adds sprig functions and custom functions:

  • render - calls the render from inside of the template, making the renderer recursive
  • readFile - reads a file from a given path, relative paths are translated to absolute paths, based on root function
  • root - the root path for rendering, used relative to absolute path translation in any file based operations
  • toYaml - provides a configuration data structure fragment as a YAML format
  • gzip - use gzip compression inside the templates, for best results use with b64enc
  • ungzip - use gzip extraction inside the templates, for best results use with b64dec

func (*Renderer) FileRender added in v0.0.5

func (r *Renderer) FileRender(inputPath, outputPath string) error

FileRender is used to render files by path, see also Render

func (*Renderer) Parse added in v0.0.5

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

Parse is a basic template parsing function

func (*Renderer) ReadFile

func (r *Renderer) ReadFile(file string) (string, error)

ReadFile is a template function that allows for an in-template file opening

func (*Renderer) Render

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

Render is the main rendering function, see also SimpleRender, Configuration and ExtraFunctions

func (*Renderer) SimpleRender added in v0.0.4

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

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

func (*Renderer) Validate added in v0.0.5

func (r *Renderer) Validate() error

Validate checks the internal state and returns error if necessary

Directories

Path Synopsis
Package configuration defines data structure (configuration) for the data-driven renderer Configuration is a tree structure and can be created from a YAML files or 'key=value' pairs.
Package configuration defines data structure (configuration) for the data-driven renderer Configuration is a tree structure and can be created from a YAML files or 'key=value' pairs.

Jump to

Keyboard shortcuts

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