template

package
v0.0.0-...-4f8c79a Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2015 License: BSD-3-Clause Imports: 9 Imported by: 1

Documentation

Overview

Package template contains utilities for working with Go templates. Most of the utilities here are convenience methods focused on writing templates to disk.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckMissingFields

func CheckMissingFields(tpl FieldCheck, data MapData) (err error)

func GlobBatch

func GlobBatch(glob, target string) (map[string]string, error)

This accepts a glob and a target directory and converts it to a map containing entries where the key is a matching file and the value is a file in the target directory having the same name.

func WriteFile

func WriteFile(file string, tpl *template.Template, data interface{}, mode os.FileMode) (err error)

Utility to write a template out to a file

Types

type BatchTemplater

type BatchTemplater interface {
	// The keys in the provided map are read as templates from
	// a data source. The result of executing each template
	// with the provided data is written into the data source named by the
	// corresponding value. Any errors will result in the operation
	// being aborted.
	Execute(templates map[string]string, data interface{}) (err error)
}

A batch templater is used to apply the same data to a batch of templates.

type FieldCheck

type FieldCheck struct {
	Name       string
	Text       string
	LeftDelim  string
	RightDelim string
	Funcs      []map[string]interface{}
}

type FileBatchTemplater

type FileBatchTemplater struct {
	Perm os.FileMode
}

A FileBatchTemplater is a BatchTemplater that uses files as a data source and sink

func NewFileBatchTemplater

func NewFileBatchTemplater(perm os.FileMode) *FileBatchTemplater

Creates a new batched templater which will write files out with the specified permissions.

func (*FileBatchTemplater) Execute

func (t *FileBatchTemplater) Execute(files map[string]string, data interface{}) (err error)

type MapData

type MapData interface {
	Get(string) interface{}
}

MapData wraps a map passed to the template.Execute function.

Jump to

Keyboard shortcuts

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