gen

package
v0.0.0-...-6b27f02 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2022 License: GPL-2.0 Imports: 14 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Now = time.Now

Now returns the current time. You can provide your own Now function for testing.

Functions

func FindAndReadAttributes

func FindAndReadAttributes(name string, dirs []string) (interface{}, error)

FindAndReadAttributes finds the template and reads the attributes from it.

func FindAndReadAttributesInto

func FindAndReadAttributesInto(name string, dirs []string, dest interface{}) error

FindAndReadAttributesInto finds the template and reads the attributes from it into the specified destination.

func FindTemplateInDirs

func FindTemplateInDirs(name string, refpaths []string) (string, error)

FindTemplateInDirs finds the first readable template in the given list of directories.

func ReadTemplateAttributesFromPath

func ReadTemplateAttributesFromPath(tplpath string) (interface{}, error)

ReadTemplateAttributesFromPath looks for our special start and end strings * in the file at the specified path. If found, it parses the string between * and returns that value.

func ReadTemplateAttributesFromPathInto

func ReadTemplateAttributesFromPathInto(tplpath string, into interface{}) error

ReadTemplateAttributesFromPathInto looks for our special start and end strings * in the file at the specified path. If found, it parses the string between * into the given location.

func ReadTemplateAttributesFromReader

func ReadTemplateAttributesFromReader(templ io.Reader) (interface{}, error)

ReadTemplateAttributesFromReader looks for our special start and end strings * in the given stream. If found, it parses the string between and returns * that value.

func ReadTemplateAttributesFromReaderInto

func ReadTemplateAttributesFromReaderInto(templ io.Reader, into interface{}) error

ReadTemplateAttributesFromReaderInto looks for our special start and end strings * in the given stream. If found, it parses the string between into the given * pointer value.

func ReadTemplateAttributesFromString

func ReadTemplateAttributesFromString(templ string) (interface{}, error)

ReadTemplateAttributesFromString looks for our special start and end strings * in the given string. If found, it parses the string between and returns * that value.

func ReadTemplateAttributesFromStringInto

func ReadTemplateAttributesFromStringInto(templ string, into interface{}) error

ReadTemplateAttributesFromStringInto looks for our special start and end strings * in the given string. If found, it parses the string between into the given pointer.

Types

type Generator

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

Generator provides a type that can generate output from either text or HTML templates from a literal string, a specific file path, or a named file from a reference directory.

func New

func New(name string, isHTML bool, w io.Writer, source data.Source) *Generator

New creates a Generator.

func (*Generator) FindTemplate

func (g *Generator) FindTemplate(name string) (string, error)

FindTemplate finds the first readable template in the list of reference directories.

func (*Generator) FromPath

func (g *Generator) FromPath(tplpath string, dot interface{}) error

FromPath reads a template from the given file path and executes it with the specified dot value.

func (*Generator) FromString

func (g *Generator) FromString(templ string, dot interface{}) error

FromString executes the given literal template with the specified dot value.

func (*Generator) FromTemplate

func (g *Generator) FromTemplate(refpaths []string, dot interface{}) error

FromTemplate reads a template from a named file within a set of reference directories and executes it with the specified dot value.

func (*Generator) WithFuncs

func (g *Generator) WithFuncs(funcs map[string]interface{}) *Generator

Create a copy of a generator with a changed funcs.

func (*Generator) WithName

func (g *Generator) WithName(name string) *Generator

Create a copy of a generator with a changed name.

func (*Generator) WithRefpaths

func (g *Generator) WithRefpaths(refpaths []string) *Generator

Create a copy of a generator with a changed refpaths.

type TemplateAttributes

type TemplateAttributes struct {
	Name       string
	Attributes interface{}
	Err        error
}

TemplateAttributes holds the information for one file from a directory.

func ReadDirFilesAttributes

func ReadDirFilesAttributes(tpldir string) ([]*TemplateAttributes, error)

ReadDirFilesAttributes calls ReadDirFilesAttributesAs with a newDestPointer * that creates an interface{}. This allows reading generic JSON data from each * file in the directory.

func ReadDirFilesAttributesAs

func ReadDirFilesAttributesAs(tpldir string, newDestPointer func() interface{}) ([]*TemplateAttributes, error)

ReadDirFilesAttributesAs scans the given directory looking for files * with the right filename extension. For each found, it looks for * and parses the contents of our special attribute strings. * It returns an array of results holding that information. * If there are errors reading individual files, those errors * are returned in the array, along with an overall error * that tells how many files had errors. * newDestPointer is a function that is called just before reading * the contents of each file. It should return a new instance of * a location where the contents of that file should be stored. * Typically it will look like: func()interface{}{return &MyStruct{}}.

Jump to

Keyboard shortcuts

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