Documentation
¶
Overview ¶
Package theme provides shared theming manifest definitions, loaders, and a simple in-memory registry.
Index ¶
- Variables
- type AssetResolver
- type Assets
- type Manifest
- type ManifestRef
- type MemoryRegistry
- func (r *MemoryRegistry) Get(name string, opts ...QueryOption) (*Manifest, error)
- func (r *MemoryRegistry) List() []ManifestRef
- func (r *MemoryRegistry) Register(manifest *Manifest) error
- func (r *MemoryRegistry) Theme(name string, opts ...QueryOption) (*Manifest, error)
- func (r *MemoryRegistry) Themes() []ManifestRef
- type QueryOption
- type Registry
- type RendererConfig
- type ResolvedSelection
- type Selection
- func (s Selection) Asset(key string) (string, bool)
- func (s Selection) CSSVariables(prefix string) map[string]string
- func (s Selection) Partials(fallbacks map[string]string) map[string]string
- func (s Selection) RendererTheme(fallbacks map[string]string) RendererConfig
- func (s Selection) Snapshot() ResolvedSelection
- func (s Selection) Template(key, fallback string) string
- func (s Selection) Tokens() map[string]string
- type Selector
- type TemplateResolver
- type ThemeProvider
- type ThemeSelector
- type TokenProvider
- type ValidationError
- type Variant
Constants ¶
This section is empty.
Variables ¶
var ( // ErrThemeNotFound is returned when a theme name has no registered manifests. ErrThemeNotFound = errors.New("theme not found") // ErrVersionNotFound is returned when a specific version cannot be located. ErrVersionNotFound = errors.New("theme version not found") )
Functions ¶
This section is empty.
Types ¶
type AssetResolver ¶
AssetResolver resolves asset URLs/paths.
type Assets ¶
type Assets struct {
Prefix string `json:"prefix,omitempty" yaml:"prefix,omitempty"`
Files map[string]string `json:"files,omitempty" yaml:"files,omitempty"`
}
Assets groups static assets and optional prefix/CDN root.
type Manifest ¶
type Manifest struct {
Name string `json:"name" yaml:"name"`
Version string `json:"version" yaml:"version"`
Description string `json:"description,omitempty" yaml:"description,omitempty"`
Tokens map[string]string `json:"tokens,omitempty" yaml:"tokens,omitempty"`
Fonts map[string]string `json:"fonts,omitempty" yaml:"fonts,omitempty"`
Assets Assets `json:"assets,omitempty" yaml:"assets,omitempty"`
Templates map[string]string `json:"templates,omitempty" yaml:"templates,omitempty"`
Variants map[string]Variant `json:"variants,omitempty" yaml:"variants,omitempty"`
}
Manifest defines the shape of a theme file that downstream systems (go-cms, go-formgen) can consume.
func LoadBytes ¶
LoadBytes parses a manifest from raw bytes. If format is empty, it will try JSON then YAML.
func LoadFile ¶
LoadFile reads a manifest from a given fs.FS path, inferring format from the extension.
func (Manifest) CSSVariables ¶
CSSVariables returns a CSS variable map (prefixed with "--" unless overridden) for a variant.
func (Manifest) TokensForVariant ¶
TokensForVariant merges base tokens with the requested variant (variant tokens take precedence).
type ManifestRef ¶
ManifestRef summarizes a stored manifest.
type MemoryRegistry ¶
type MemoryRegistry struct {
// contains filtered or unexported fields
}
MemoryRegistry is a minimal in-memory implementation of Registry and ThemeProvider.
func NewRegistry ¶
func NewRegistry() *MemoryRegistry
NewRegistry constructs an empty MemoryRegistry.
func (*MemoryRegistry) Get ¶
func (r *MemoryRegistry) Get(name string, opts ...QueryOption) (*Manifest, error)
Get fetches a manifest by name, optionally constrained to a version with fallback to the latest.
func (*MemoryRegistry) List ¶
func (r *MemoryRegistry) List() []ManifestRef
List returns a sorted list of all stored manifests.
func (*MemoryRegistry) Register ¶
func (r *MemoryRegistry) Register(manifest *Manifest) error
Register validates and stores a manifest. Existing entries for the same name+version are overwritten.
func (*MemoryRegistry) Theme ¶
func (r *MemoryRegistry) Theme(name string, opts ...QueryOption) (*Manifest, error)
Theme is an alias for Get to satisfy ThemeProvider.
func (*MemoryRegistry) Themes ¶
func (r *MemoryRegistry) Themes() []ManifestRef
Themes is an alias for List to satisfy ThemeProvider.
type QueryOption ¶
type QueryOption func(*queryOptions)
QueryOption modifies how registry lookups behave.
func WithVersion ¶
func WithVersion(version string) QueryOption
WithVersion requests a specific manifest version.
func WithoutFallback ¶
func WithoutFallback() QueryOption
WithoutFallback disables fallback to the latest version when a specific one is missing.
type Registry ¶
type Registry interface {
Register(manifest *Manifest) error
Get(name string, opts ...QueryOption) (*Manifest, error)
List() []ManifestRef
}
Registry defines methods to register and retrieve theme manifests.
type RendererConfig ¶
type RendererConfig struct {
Theme string
Variant string
Partials map[string]string
Tokens map[string]string
CSSVars map[string]string
AssetURL func(string) string
}
RendererConfig bundles resolved partials, tokens, CSS vars, and an asset resolver for renderers.
type ResolvedSelection ¶ added in v0.3.0
type ResolvedSelection struct {
Theme string
Variant string
Tokens map[string]string
Assets map[string]string
Templates map[string]string
AssetPrefix string
}
ResolvedSelection is a complete theme snapshot with merged variant/base values.
type Selection ¶
Selection holds the chosen theme/variant and provides resolvers for templates, assets, and tokens.
func (Selection) Asset ¶
Asset returns a themed asset path with prefix handling (variant overrides then base). Bool indicates presence.
func (Selection) CSSVariables ¶
CSSVariables returns CSS vars for the variant with the provided prefix (defaults to "--" if empty).
func (Selection) RendererTheme ¶
func (s Selection) RendererTheme(fallbacks map[string]string) RendererConfig
RendererTheme builds a RendererConfig given a set of fallback partials.
func (Selection) Snapshot ¶ added in v0.3.0
func (s Selection) Snapshot() ResolvedSelection
Snapshot returns a fully resolved selection payload for integrations that need merged assets/templates/tokens.
type Selector ¶
type Selector struct {
Registry ThemeProvider
DefaultTheme string
DefaultVariant string
}
Selector is the default implementation of ThemeSelector using a ThemeProvider registry.
type TemplateResolver ¶
type TemplateResolver interface {
Template(key, fallback string) string
Partials(fallbacks map[string]string) map[string]string
}
TemplateResolver resolves templates by key with optional fallbacks.
type ThemeProvider ¶
type ThemeProvider interface {
Theme(name string, opts ...QueryOption) (*Manifest, error)
Themes() []ManifestRef
}
ThemeProvider exposes read-only registry access for downstream consumers.
type ThemeSelector ¶
type ThemeSelector interface {
Select(themeName, variant string, opts ...QueryOption) (*Selection, error)
}
ThemeSelector selects a theme/variant and exposes resolvers.
type TokenProvider ¶
type TokenProvider interface {
Tokens() map[string]string
CSSVariables(prefix string) map[string]string
}
TokenProvider exposes tokens and CSS variables for a theme/variant.
type ValidationError ¶
type ValidationError struct {
Issues []string
}
ValidationError aggregates manifest validation issues.
func (ValidationError) Error ¶
func (e ValidationError) Error() string
Error implements the error interface.
type Variant ¶
type Variant struct {
Description string `json:"description,omitempty" yaml:"description,omitempty"`
Tokens map[string]string `json:"tokens,omitempty" yaml:"tokens,omitempty"`
Templates map[string]string `json:"templates,omitempty" yaml:"templates,omitempty"`
Assets Assets `json:"assets,omitempty" yaml:"assets,omitempty"`
}
Variant captures token/template/asset overrides for a named variant (e.g., light/dark).