template

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package template provides utilities for loading plugin templates with custom override support.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Info

type Info struct {
	Filename       string
	EmbeddedExists bool
	CustomExists   bool
	CustomPath     string
	UsingCustom    bool
}

GetTemplateInfo returns information about a template.

type Loader

type Loader struct {
	// contains filtered or unexported fields
}

Loader handles loading templates with support for custom overrides. It checks for custom templates in ~/.config/tinct/templates/{pluginName}/. and falls back to embedded templates if custom ones don't exist.

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 first. filename should be the template filename (e.g., "theme.conf.tmpl"). Returns the template content and whether it was loaded from a custom override.

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) 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.

Jump to

Keyboard shortcuts

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