dirtempl

package module
v0.0.0-...-ce42be8 Latest Latest
Warning

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

Go to latest
Published: May 23, 2020 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Execute

func Execute(t TemplateEngine, params Params, origin string, dest string) error

Execute executes the dirtempl found at origin and writes the results to dest. It calls the TemplateEngine t with params whenever required.

func Walk

func Walk(fs afero.Fs, t TemplateEngine, params Params, srcPath string, outPath string) error

Walk performs exactly the same operations as Execute but on a afero.Fs instead of the OS file system.

Types

type ConfigLoader

type ConfigLoader interface {
	ConfigName() string
	LoadConfig(r io.Reader, params Params) (*DirConfig, error)
}

A ConfigLoader is responsible for loading DirConfigs. LoadConfig is called for every file with name ConfigName() found in the template tree. It must read the config from r and return it. Typically it also renders it as a template. All official engines perform themselves on the config and then parse it using gitlab.com/Ma_124/dirtempl/dirtempl_yaml

type DirConfig

type DirConfig struct {
	// Files maps the filenames to their FileEntries
	Files map[string]FileEntry `yaml:"files,omitempty"`
}

A DirConfig is a directory level configuration file which determines how the files in that directory are handled. It is typically found in files named _dirtempl.yml (see ConfigLoader).

type FileEntry

type FileEntry struct {
	// Ignored: skips file; not included at destination (other options are ignored)
	Ignored bool `yaml:"ignore,omitempty"`
	// DestinationNames: sets names of resulting files
	DestinationNames []string `yaml:"dest,omitempty"`
	// TemplatedContent: sets weather it contains a template (overrides TemplateEngine.IsTemplate)
	TemplatedContent string `yaml:"templated,omitempty"`
}

A FileEntry specifies how the file it applies to is handled when encountered in a template.

type FileTemplater

type FileTemplater interface {
	ExecuteFile(r io.ReadCloser, w io.WriteCloser, params Params) error
}

FileTemplater exposes the function ExecuteFile which is used to execute file templates. Implementations must read the template from r and write the rendered results to w. It's the callee's responsibility to close r and w.

type FilenameTemplater

type FilenameTemplater interface {
	ExecuteFilename(templ string, params Params) (string, error)
}

FilenameTemplater exposes the function ExecuteFilename which is used to execute filename templates. Implementations must use template from templ and return the rendered results.

type IsTemplate

type IsTemplate interface {
	IsTemplate(name string) string
}

IsTemplate exposes the function IsTemplate which is used to determine whether the file with filename name is a template. If it is not a template implementations must return an empty string. If it is they must return the default filename for the rendered result.

Example: The Pongo2 template engine uses .p2 as a file extension. The pongo2 engine's implementation checks if this suffix is present and if present returns the file name with out the extension.

text-template.p2      --> text-template
text-template.html.p2 --> text-template.html
not-a-template.html   --> ""

type Params

type Params interface{}

Params are passed to TemplateEngines.

type TemplateEngine

type TemplateEngine interface {
	FileTemplater
	FilenameTemplater
	IsTemplate
	ConfigLoader
}

A TemplateEngine must implement the FileTemplater, FilenameTemplater, IsTemplate and ConfigLoader interfaces.

Jump to

Keyboard shortcuts

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