template

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2026 License: MIT Imports: 10 Imported by: 2

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func TemplateFuncs

func TemplateFuncs() template.FuncMap

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

func New(pluginName string, embedFS embed.FS) *Loader

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

func (l *Loader) CustomDir() string

CustomDir returns the directory where custom templates for this plugin would be located.

func (*Loader) CustomPath

func (l *Loader) CustomPath(filename string) string

CustomPath returns the path where a custom template would be located.

func (*Loader) DumpAllTemplates

func (l *Loader) DumpAllTemplates(force bool) ([]string, error)

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

func (l *Loader) DumpTemplate(filename string, force bool) error

DumpTemplate writes an embedded template to the custom templates directory. If force is false, it will not overwrite existing custom templates.

func (*Loader) GetInfo

func (l *Loader) GetInfo(filename string) Info

GetInfo returns information about a specific template.

func (*Loader) HasCustomTemplate

func (l *Loader) HasCustomTemplate(filename string) bool

HasCustomTemplate checks if a custom template exists for the given filename.

func (*Loader) ListEmbeddedTemplates

func (l *Loader) ListEmbeddedTemplates() ([]string, error)

ListEmbeddedTemplates returns a list of all embedded template files.

func (*Loader) Load

func (l *Loader) Load(filename string) (content []byte, fromCustom bool, err error)

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:

  1. Custom template in ~/.config/tinct/templates/{pluginName}/{filename}
  2. Versioned template in templates/{version}/{filename} (if targetVersion is set)
  3. Default embedded template at {filename}

func (*Loader) WithCustomBase

func (l *Loader) WithCustomBase(customBase string) *Loader

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

func (l *Loader) WithTargetVersion(version string) *Loader

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.

func (*Loader) WithVerbose

func (l *Loader) WithVerbose(verbose bool, logger Logger) *Loader

WithVerbose enables verbose logging for template operations.

type Logger

type Logger interface {
	Printf(format string, v ...any)
}

Logger is a simple interface for logging messages.

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.

Jump to

Keyboard shortcuts

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