templates

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2018 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrUnsupportedContextType is thrown when an unsupported type is attempted to be wired into a template context.
	ErrUnsupportedContextType = errors.New("unsupported type added to context")
)

Functions

This section is empty.

Types

type Book

type Book struct {
	Name     string
	Original []byte
	Template *template.Template
}

Book is a reference to a specific template

type Context

type Context struct {
	Local              *core.Local
	Build              *core.Build
	Competition        *core.Competition
	Command            *core.Command
	DNS                *core.DNS
	DNSRecord          *core.DNSRecord
	Environment        *core.Environment
	Host               *core.Host
	Identity           *core.Identity
	Network            *core.Network
	RemoteFile         *core.RemoteFile
	Script             *core.Script
	Team               *core.Team
	User               *core.User
	Remote             *core.Remote
	AMI                *core.AMI
	Laforge            *core.Laforge
	Metadata           *core.Metadata
	ProvisionedNetwork *core.ProvisionedNetwork
	ProvisionedHost    *core.ProvisionedHost
	ProvisioningStep   *core.ProvisioningStep
	Revision           *core.Revision
	Connection         *core.Connection
	Dict               Dict
}

Context is a meta structure that wraps pointers to any type that needs to be accessed inside of a build template. This uinfied struct helps keep a single convention on how to get to and access data inside of build templates.

func NewContext

func NewContext(i ...interface{}) (*Context, error)

NewContext takes a varadic list of objects to be embedded into the returned template context

func (*Context) Attach

func (c *Context) Attach(i ...interface{}) error

Attach wires up all the core Laforge types into a cohesive Context bundle for template rendering

func (*Context) Clone

func (c *Context) Clone() *Context

Clone duplicates the current contexts including pointer references to the dependent objects. Note it does not clone the Dict - that remains locally resident.

func (*Context) Get

func (c *Context) Get(key string) string

Get returns a temp value set in the context's dictionary.

func (*Context) Localize

func (c *Context) Localize()

Localize is a function to set the context's localization

func (*Context) Set

func (c *Context) Set(key, val string) string

Set attachs the val string to the key in the Context dictionary and returns the val for pipelining.

type Dict

type Dict map[string]string

Dict is a temporary dictionary to be used for context

type Library

type Library struct {
	sync.RWMutex
	Books map[string]*Book
}

Library is a holder for all the templates used by a builder

func NewLibrary

func NewLibrary() *Library

NewLibrary returns a new zero value Library

func (*Library) AddBook

func (l *Library) AddBook(name string, data []byte) (*Book, error)

AddBook adds a new template to the library index

func (*Library) Execute

func (l *Library) Execute(name string, context *Context) ([]byte, error)

Execute uses the denoted book and renders a template based off of the passed context

func (*Library) ExecuteGroup

func (l *Library) ExecuteGroup(baseID string, appendIDs []string, context *Context) ([]byte, error)

ExecuteGroup uses the denoted book with all secondary books chained and renders a template based off of the passed context

Jump to

Keyboard shortcuts

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