Documentation
¶
Overview ¶
Package template provides template utilities and functions for tinct plugins. This package is designed for use by both internal and external plugins.
Package template provides template utilities and functions for tinct plugins.
Index ¶
- func TemplateFuncs() template.FuncMap
- type Info
- type Loader
- func (l *Loader) CustomDir() string
- func (l *Loader) CustomPath(filename string) string
- func (l *Loader) DumpAllTemplates(force bool) ([]string, error)
- func (l *Loader) DumpTemplate(filename string, force bool) error
- func (l *Loader) GetInfo(filename string) Info
- func (l *Loader) HasCustomTemplate(filename string) bool
- func (l *Loader) ListEmbeddedTemplates() ([]string, error)
- func (l *Loader) Load(filename string) (content []byte, fromCustom bool, err error)
- func (l *Loader) WithCustomBase(customBase string) *Loader
- func (l *Loader) WithTargetVersion(version string) *Loader
- func (l *Loader) WithVerbose(verbose bool, logger Logger) *Loader
- type Logger
- type PaletteProvider
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func TemplateFuncs ¶
TemplateFuncs returns standard template functions for all output plugins. These functions provide consistent color access and formatting across all templates.
Types ¶
type Info ¶
type Info struct {
Filename string
EmbeddedExists bool
CustomExists bool
CustomPath string
UsingCustom bool
}
Info contains information about a template.
type Loader ¶
type Loader struct {
// contains filtered or unexported fields
}
Loader handles loading templates with support for custom overrides and versioned templates. It checks for custom templates in ~/.config/tinct/templates/{pluginName}/ and falls back to embedded templates if custom ones don't exist.
Versioned templates allow plugins to support multiple versions of target applications. Templates can be organized in version subdirectories (e.g., templates/0.53/). The loader selects the highest version that doesn't exceed the target version.
func New ¶
New creates a new template loader for the specified plugin. embedFS should be the embedded filesystem containing the plugin's default templates. pluginName is used to locate custom templates in ~/.config/tinct/templates/{pluginName}/.
func (*Loader) CustomDir ¶
CustomDir returns the directory where custom templates for this plugin would be located.
func (*Loader) CustomPath ¶
CustomPath returns the path where a custom template would be located.
func (*Loader) DumpAllTemplates ¶
DumpAllTemplates writes all embedded templates to the custom templates directory. Returns the list of successfully dumped templates and any errors encountered. If force is false and some templates already exist, it will skip those but continue processing remaining templates.
func (*Loader) DumpTemplate ¶
DumpTemplate writes an embedded template to the custom templates directory. If force is false, it will not overwrite existing custom templates.
func (*Loader) HasCustomTemplate ¶
HasCustomTemplate checks if a custom template exists for the given filename.
func (*Loader) ListEmbeddedTemplates ¶
ListEmbeddedTemplates returns a list of all embedded template files.
func (*Loader) Load ¶
Load reads a template file, checking for custom overrides and versioned templates. filename should be the template filename (e.g., "theme.conf.tmpl"). Returns the template content and whether it was loaded from a custom override.
Template resolution order:
- Custom template in ~/.config/tinct/templates/{pluginName}/{filename}
- Versioned template in templates/{version}/{filename} (if targetVersion is set)
- Default embedded template at {filename}
func (*Loader) WithCustomBase ¶
WithCustomBase sets a custom base directory for template storage. This is useful for dumping templates to a non-default location.
func (*Loader) WithTargetVersion ¶ added in v0.1.28
WithTargetVersion sets the target application version for versioned template selection. When set, the loader will search for version-specific templates in subdirectories like templates/0.53/ and select the highest version that doesn't exceed targetVersion.
type PaletteProvider ¶ added in v0.1.1
type PaletteProvider interface {
GetPaletteHelper() *colour.PaletteHelper
}
PaletteProvider is an interface for types that can provide a PaletteHelper. Both pkg/colour.ThemeData and internal/colour.ThemeData implement this.