theme

package
v0.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2026 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Overview

Package theme provides theme loading, switching, and rendering for the frontend.

Index

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 Info

type Info struct {
	Name     string
	Config   Config
	IsActive bool
}

Info represents a theme with its configuration and active status.

type Manager

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

Manager handles theme loading, switching, and rendering.

func NewManager

func NewManager(themesDir string, logger *slog.Logger) *Manager

NewManager creates a new theme manager.

func (*Manager) GetActiveTheme

func (m *Manager) GetActiveTheme() *Theme

GetActiveTheme returns the currently active theme.

func (*Manager) GetTheme

func (m *Manager) GetTheme(name string) (*Theme, error)

GetTheme returns a theme by name.

func (*Manager) HasTheme

func (m *Manager) HasTheme(name string) bool

HasTheme checks if a theme exists.

func (*Manager) ListThemes

func (m *Manager) ListThemes() []*Config

ListThemes returns all loaded theme configs, sorted by name.

func (*Manager) ListThemesWithActive

func (m *Manager) ListThemesWithActive() []Info

ListThemesWithActive returns all themes with active status, sorted by name.

func (*Manager) LoadThemes

func (m *Manager) LoadThemes() error

LoadThemes scans the themes directory and loads all themes.

func (*Manager) ReloadTheme

func (m *Manager) ReloadTheme(name string) error

ReloadTheme reloads a specific theme from disk.

func (*Manager) SetActiveTheme

func (m *Manager) SetActiveTheme(name string) error

SetActiveTheme sets the active theme by name.

func (*Manager) SetFuncMap

func (m *Manager) SetFuncMap(funcMap template.FuncMap)

SetFuncMap sets the template function map to use when parsing templates.

func (*Manager) TemplateFuncs

func (m *Manager) TemplateFuncs() template.FuncMap

TemplateFuncs returns template functions provided by the theme manager. These should be merged with the renderer's template functions.

func (*Manager) ThemeCount

func (m *Manager) ThemeCount() int

ThemeCount returns the number of loaded themes.

func (*Manager) ThemesDir

func (m *Manager) ThemesDir() string

ThemesDir returns the themes directory path.

func (*Manager) Translate

func (m *Manager) Translate(lang, key string, args ...any) string

Translate returns a translation for the given key, checking the active theme first, then falling back to the global i18n catalog. This is the recommended function for frontend templates.

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

func (t *Theme) GetContentTemplateName(pageName string) string

GetContentTemplateName returns the content template name for a given page.

func (*Theme) GetSettingDefault

func (t *Theme) GetSettingDefault(key string) string

GetSettingDefault returns the default value for a setting.

func (*Theme) GetTemplate

func (t *Theme) GetTemplate(name string) string

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

func (t *Theme) HasSetting(key string) bool

HasSetting returns true if the theme has a setting with the given key.

func (*Theme) Render

func (t *Theme) Render(w io.Writer, templateName string, data any) error

Render executes a template with the given data.

func (*Theme) RenderContent

func (t *Theme) RenderContent(w io.Writer, pageName string, data any) error

RenderContent renders just the content portion (for AJAX/partial rendering).

func (*Theme) RenderPage

func (t *Theme) RenderPage(w io.Writer, pageName string, data any) error

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

func (*Theme) Translate

func (t *Theme) Translate(lang, key string) (string, bool)

Translate returns a translation for the given key in the specified language. Returns empty string if no theme-specific translation exists (caller should fall back to global).

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.

Jump to

Keyboard shortcuts

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