Documentation ¶
Index ¶
- func Execute(t TemplateEngine, params Params, origin string, dest string) error
- func Walk(fs afero.Fs, t TemplateEngine, params Params, srcPath string, outPath string) error
- type ConfigLoader
- type DirConfig
- type FileEntry
- type FileTemplater
- type FilenameTemplater
- type IsTemplate
- type Params
- type TemplateEngine
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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 ¶
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 ¶
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 TemplateEngine ¶
type TemplateEngine interface { FileTemplater FilenameTemplater IsTemplate ConfigLoader }
A TemplateEngine must implement the FileTemplater, FilenameTemplater, IsTemplate and ConfigLoader interfaces.