Documentation
¶
Overview ¶
Package theme provides theme loading, switching, and rendering for the frontend.
Index ¶
- Constants
- type Config
- type Info
- type Manager
- func (m *Manager) CustomDir() string
- func (m *Manager) EmbeddedFS() embed.FS
- func (m *Manager) GetActiveTheme() *Theme
- func (m *Manager) GetTheme(name string) (*Theme, error)
- func (m *Manager) HasTheme(name string) bool
- func (m *Manager) IsEmbedded(name string) bool
- func (m *Manager) ListThemes() []*Config
- func (m *Manager) ListThemesWithActive() []Info
- func (m *Manager) LoadThemes() error
- func (m *Manager) ReloadTheme(name string) error
- func (m *Manager) SetActiveTheme(name string) error
- func (m *Manager) SetFuncMap(funcMap template.FuncMap)
- func (m *Manager) TemplateFuncs() template.FuncMap
- func (m *Manager) ThemeCount() int
- func (m *Manager) Translate(lang, key string, args ...any) string
- type Setting
- type Theme
- func (t *Theme) GetContentTemplateName(pageName string) string
- func (t *Theme) GetSettingDefault(key string) string
- func (t *Theme) GetTemplate(name string) string
- func (t *Theme) HasSetting(key string) bool
- func (t *Theme) Render(w io.Writer, templateName string, data any) error
- func (t *Theme) RenderContent(w io.Writer, pageName string, data any) error
- func (t *Theme) RenderEngine() string
- func (t *Theme) RenderPage(w io.Writer, pageName string, data any) error
- func (t *Theme) Translate(lang, key string) (string, bool)
- type WidgetArea
Constants ¶
const ( EngineTempl = "templ" EngineHTML = "html" )
Theme engine constants.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
Name string `json:"name"`
Version string `json:"version"`
Author string `json:"author"`
Description string `json:"description"`
Screenshot string `json:"screenshot"`
Engine string `json:"engine,omitempty"`
Templates map[string]string `json:"templates"`
Settings []Setting `json:"settings"`
WidgetAreas []WidgetArea `json:"widget_areas,omitempty"`
}
Config represents the configuration loaded from theme.json.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager handles theme loading, switching, and rendering. It supports loading themes from both embedded filesystem (core themes) and external filesystem (custom themes). External themes override embedded themes with the same name.
func NewManager ¶
NewManager creates a new theme manager. embeddedFS contains core themes embedded in the binary. customDir is the path to custom/themes directory for user themes.
func (*Manager) EmbeddedFS ¶ added in v0.2.0
EmbeddedFS returns the embedded filesystem for core themes.
func (*Manager) GetActiveTheme ¶
GetActiveTheme returns the currently active theme.
func (*Manager) IsEmbedded ¶ added in v0.2.0
IsEmbedded checks if a theme is embedded (core) or external (custom).
func (*Manager) ListThemes ¶
ListThemes returns all loaded theme configs, sorted by name.
func (*Manager) ListThemesWithActive ¶
ListThemesWithActive returns all themes with active status, sorted by name.
func (*Manager) LoadThemes ¶
LoadThemes loads themes from both embedded and external sources. External themes override embedded themes with the same name.
func (*Manager) ReloadTheme ¶
ReloadTheme reloads a specific theme from disk. Only works for external (non-embedded) themes.
func (*Manager) SetActiveTheme ¶
SetActiveTheme sets the active theme by name.
func (*Manager) SetFuncMap ¶
SetFuncMap sets the template function map to use when parsing templates.
func (*Manager) TemplateFuncs ¶
TemplateFuncs returns template functions provided by the theme manager.
func (*Manager) ThemeCount ¶
ThemeCount returns the number of loaded themes.
type Setting ¶
type Setting struct {
Key string `json:"key"`
Label string `json:"label"`
Type string `json:"type"` // text, color, image, select
Default string `json:"default"`
Options []string `json:"options,omitempty"`
}
Setting represents a configurable option for a theme.
type Theme ¶
type Theme struct {
Name string // directory name (used as identifier)
Path string // filesystem path to theme directory (empty for embedded)
Config Config // parsed theme.json
Templates *template.Template // parsed templates
StaticPath string // path to static files (empty for embedded)
Translations map[string]map[string]string // lang -> key -> translation (optional overrides)
IsEmbedded bool // true if theme is embedded in binary
EmbeddedFS fs.FS // embedded filesystem for static files (nil for external themes)
}
Theme represents a loaded theme with its templates and configuration.
func (*Theme) GetContentTemplateName ¶
GetContentTemplateName returns the content template name for a given page.
func (*Theme) GetSettingDefault ¶
GetSettingDefault returns the default value for a setting.
func (*Theme) GetTemplate ¶
GetTemplate returns the template file path for a given template name. Falls back to a default if not specified in theme config.
func (*Theme) HasSetting ¶
HasSetting returns true if the theme has a setting with the given key.
func (*Theme) RenderContent ¶
RenderContent renders just the content portion (for AJAX/partial rendering).
func (*Theme) RenderEngine ¶ added in v0.9.0
RenderEngine returns the normalized render engine for this theme. If Config.Engine is explicitly "templ" or "html" (case-insensitive), that value is returned. Otherwise embedded themes default to "templ" and custom filesystem themes default to "html".
func (*Theme) RenderPage ¶
RenderPage renders a page template within the base layout. It handles the template composition by: 1. Getting the content block for the specific page 2. Injecting it into the base layout 3. Executing the combined template
type WidgetArea ¶
type WidgetArea struct {
ID string `json:"id"`
Name string `json:"name"`
Description string `json:"description,omitempty"`
}
WidgetArea represents a location in the theme where widgets can be placed.