templating

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package templating assists in template based code generation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateFile

func CreateFile(path, tmplName string, tmpl *template.Template, ctx any) error

CreateFile creates path, executes tmpl with dot ctx, and handles closing.

func Funcs

func Funcs(base *template.Template) *template.Template

Funcs adds the standard function map to base.

Types

type File

type File struct {
	Dir  string // Dir is the destination directory of this file, within the test directory.
	Name string // Name is the filename of this file.
	Desc string // Desc is a human-readable description for this file.
	Glob string // Glob is the slash-delimited glob of source templates for this file.
}

File holds information about a templated file.

type Generator

type Generator struct {
	Files     []File // Files is the list of files this generator will make.
	Templates Set    // Templates is the map of templates to use for files in testFiles.
}

Generator is a mixin struct for dealing with templated parts of generators.

func NewGenerator

func NewGenerator(files []File, builder SetBuilder) (*Generator, error)

NewGenerator creates a Generator using files and builder.

func (*Generator) Generate

func (t *Generator) Generate(dir string, ctx any) error

Generate generates each of the templated files in this generator into dir. We pass ctx to each template.

type Set

type Set map[string]*template.Template

Set maps filenames to templates to use to generate them.

func (Set) Generate

func (s Set) Generate(files []File, dir string, ctx any) error

Generate generates each of the templated files in this set into dir. We pass ctx to each template.

type SetBuilder

type SetBuilder struct {
	Srcs  []Source         // Srcs is an ordered set of template sources.
	Funcs template.FuncMap // Funcs is the custom function map to apply to the templates.
}

SetBuilder is a builder for Set.

func (*SetBuilder) BuildFiles

func (b *SetBuilder) BuildFiles(files []File) (Set, error)

BuildFiles uses the builder's source set to parse templates for files.

type Source

type Source struct {
	Name string // Name is the name of the source.
	Src  fs.FS  // Src is the source filesystem.
}

Source names a source of template files.

Jump to

Keyboard shortcuts

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