template

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2019 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package template contains functions for rendering templates.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RenderAll

func RenderAll(templatePath string, excludedPaths []string, outputPath string, values Scope) error

RenderAll renders all templates in the path (directory or a single file) to an output path (directory or file) using the provided value scope.

Types

type ErrScopeMergeConflict

type ErrScopeMergeConflict struct {
	Path string
}

ErrScopeMergeConflict indicates that a conflict occurred when merging two scopes at the specified path.

func (ErrScopeMergeConflict) Error

func (e ErrScopeMergeConflict) Error() string

type Scope

type Scope map[interface{}]interface{}

Scope represents a single lexical value scope. Scopes can be nested.

func ParseScope

func ParseScope(v interface{}) (Scope, bool)

ParseScope casts the value to Scope.

func (Scope) GetScopeAt

func (scope Scope) GetScopeAt(path string) (Scope, error)

GetScopeAt returns scope at the specified path. If path doesn't exist or points to a value that cannot be interpreted as a Scope (see ParseScope), the function signals an error.

func (Scope) Merge

func (scope Scope) Merge(other Scope) Scope

Merge combines two scopes together. If a key appears in both scopes, the other scope wins.

func (Scope) Replace

func (scope Scope) Replace(other Scope)

Replace replaces contents of this scope with keys and values of the other one.

func (Scope) UpdateScopeAt

func (scope Scope) UpdateScopeAt(path string, f func(Scope) Scope) error

UpdateScopeAt transforms a scope pointed to by the path (e.g. "foo.bar.baz"). It will create scopes along the way if they don't exist. In case the value pointed by the path already exists and cannot be interpreted as a Scope (see ParseScope), the function signals ErrScopeMergeConflict.

type Template

type Template interface {
	Render(out io.Writer, values ...interface{}) error
	RenderString(values ...interface{}) (string, error)
}

Template represents a template that can be rendered using provided values.

func Load

func Load(path string) (Template, error)

Load loads template from the path.

func Parse

func Parse(source string) (Template, error)

Parse parses template in the source string.

Jump to

Keyboard shortcuts

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