Documentation
¶
Overview ¶
Package theme provides theme loading, switching, and rendering for the frontend.
Index ¶
- type Config
- type Info
- type Manager
- func (m *Manager) GetActiveTheme() *Theme
- func (m *Manager) GetTheme(name string) (*Theme, error)
- func (m *Manager) HasTheme(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) ThemesDir() string
- 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) RenderPage(w io.Writer, pageName string, data any) error
- func (t *Theme) Translate(lang, key string) (string, bool)
- type WidgetArea
Constants ¶
This section is empty.
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"`
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.
func NewManager ¶
NewManager creates a new theme manager.
func (*Manager) GetActiveTheme ¶
GetActiveTheme returns the currently active theme.
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 scans the themes directory and loads all themes.
func (*Manager) ReloadTheme ¶
ReloadTheme reloads a specific theme from disk.
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. These should be merged with the renderer's template functions.
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
Config Config // parsed theme.json
Templates *template.Template // parsed templates
StaticPath string // path to static files
Translations map[string]map[string]string // lang -> key -> translation (optional overrides)
}
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) 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.