Documentation ¶
Index ¶
- Variables
- func FindAndReadAttributes(name string, dirs []string) (interface{}, error)
- func FindAndReadAttributesInto(name string, dirs []string, dest interface{}) error
- func FindTemplateInDirs(name string, refpaths []string) (string, error)
- func ReadTemplateAttributesFromPath(tplpath string) (interface{}, error)
- func ReadTemplateAttributesFromPathInto(tplpath string, into interface{}) error
- func ReadTemplateAttributesFromReader(templ io.Reader) (interface{}, error)
- func ReadTemplateAttributesFromReaderInto(templ io.Reader, into interface{}) error
- func ReadTemplateAttributesFromString(templ string) (interface{}, error)
- func ReadTemplateAttributesFromStringInto(templ string, into interface{}) error
- type Generator
- func (g *Generator) FindTemplate(name string) (string, error)
- func (g *Generator) FromPath(tplpath string, dot interface{}) error
- func (g *Generator) FromString(templ string, dot interface{}) error
- func (g *Generator) FromTemplate(refpaths []string, dot interface{}) error
- func (g *Generator) WithFuncs(funcs map[string]interface{}) *Generator
- func (g *Generator) WithName(name string) *Generator
- func (g *Generator) WithRefpaths(refpaths []string) *Generator
- type TemplateAttributes
Constants ¶
This section is empty.
Variables ¶
var Now = time.Now
Now returns the current time. You can provide your own Now function for testing.
Functions ¶
func FindAndReadAttributes ¶
FindAndReadAttributes finds the template and reads the attributes from it.
func FindAndReadAttributesInto ¶
FindAndReadAttributesInto finds the template and reads the attributes from it into the specified destination.
func FindTemplateInDirs ¶
FindTemplateInDirs finds the first readable template in the given list of directories.
func ReadTemplateAttributesFromPath ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 (*Generator) FindTemplate ¶
FindTemplate finds the first readable template in the list of reference directories.
func (*Generator) FromPath ¶
FromPath reads a template from the given file path and executes it with the specified dot value.
func (*Generator) FromString ¶
FromString executes the given literal template with the specified dot value.
func (*Generator) FromTemplate ¶
FromTemplate reads a template from a named file within a set of reference directories and executes it with the specified dot value.
func (*Generator) WithRefpaths ¶
Create a copy of a generator with a changed refpaths.
type TemplateAttributes ¶
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{}}.