themes

package
v0.45.0 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2026 License: MIT Imports: 10 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrTemplateThemeRequired indicates the theme ID is missing.
	ErrTemplateThemeRequired = errors.New("themes: theme id required")
	// ErrTemplateNameRequired indicates the template name is missing.
	ErrTemplateNameRequired = errors.New("themes: template name required")
	// ErrTemplateSlugRequired indicates the slug is missing.
	ErrTemplateSlugRequired = errors.New("themes: template slug required")
	// ErrTemplatePathRequired indicates the file path is missing.
	ErrTemplatePathRequired = errors.New("themes: template path required")
	// ErrTemplateSlugConflict indicates a duplicate slug within a theme.
	ErrTemplateSlugConflict = errors.New("themes: template slug already exists for theme")
	// ErrTemplateRegionsInvalid indicates malformed region metadata.
	ErrTemplateRegionsInvalid = errors.New("themes: template regions invalid")
)

Functions

This section is empty.

Types

type Manifest added in v0.39.0

type Manifest struct {
	Name          string              `json:"name"`
	Description   *string             `json:"description,omitempty"`
	Version       string              `json:"version"`
	Author        *string             `json:"author,omitempty"`
	WidgetAreas   []ThemeWidgetArea   `json:"widget_areas,omitempty"`
	MenuLocations []ThemeMenuLocation `json:"menu_locations,omitempty"`
	Assets        *ThemeAssets        `json:"assets,omitempty"`
	Metadata      map[string]any      `json:"metadata,omitempty"`
}

Manifest mirrors the expected theme.json structure.

func LoadManifest added in v0.39.0

func LoadManifest(path string) (*Manifest, error)

LoadManifest reads and parses a manifest from disk.

func ParseManifest added in v0.39.0

func ParseManifest(r io.Reader) (*Manifest, error)

ParseManifest decodes manifest JSON from a reader.

type RegionInfo added in v0.39.0

type RegionInfo struct {
	Key            string
	Name           string
	AcceptsBlocks  bool
	AcceptsWidgets bool
	Fallbacks      []string
}

RegionInfo summarises template region capabilities for consumers.

type RegisterTemplateInput added in v0.39.0

type RegisterTemplateInput struct {
	ThemeID      uuid.UUID
	Name         string
	Slug         string
	Description  *string
	TemplatePath string
	Regions      map[string]TemplateRegion
	Metadata     map[string]any
}

type RegisterThemeInput added in v0.39.0

type RegisterThemeInput struct {
	Name        string
	Description *string
	Version     string
	Author      *string
	ThemePath   string
	Config      ThemeConfig
	Activate    bool
}

func ManifestToThemeInput added in v0.39.0

func ManifestToThemeInput(themePath string, manifest *Manifest) (RegisterThemeInput, error)

ManifestToThemeInput converts a manifest into a registration payload.

type Service added in v0.39.0

type Service interface {
	RegisterTheme(ctx context.Context, input RegisterThemeInput) (*Theme, error)
	GetTheme(ctx context.Context, id uuid.UUID) (*Theme, error)
	GetThemeByName(ctx context.Context, name string) (*Theme, error)
	ListThemes(ctx context.Context) ([]*Theme, error)
	ListActiveThemes(ctx context.Context) ([]*Theme, error)

	ActivateTheme(ctx context.Context, id uuid.UUID) (*Theme, error)
	DeactivateTheme(ctx context.Context, id uuid.UUID) (*Theme, error)

	RegisterTemplate(ctx context.Context, input RegisterTemplateInput) (*Template, error)
	UpdateTemplate(ctx context.Context, input UpdateTemplateInput) (*Template, error)
	DeleteTemplate(ctx context.Context, id uuid.UUID) error
	GetTemplate(ctx context.Context, id uuid.UUID) (*Template, error)
	ListTemplates(ctx context.Context, themeID uuid.UUID) ([]*Template, error)

	TemplateRegions(ctx context.Context, templateID uuid.UUID) ([]RegionInfo, error)
	ThemeRegionIndex(ctx context.Context, themeID uuid.UUID) (map[string][]RegionInfo, error)

	ListActiveSummaries(ctx context.Context) ([]ThemeSummary, error)
}

Service exposes theme management capabilities.

type Template

type Template struct {
	bun.BaseModel `bun:"table:templates,alias:tp"`

	ID           uuid.UUID                 `bun:",pk,type:uuid" json:"id"`
	ThemeID      uuid.UUID                 `bun:"theme_id,notnull,type:uuid" json:"theme_id"`
	Name         string                    `bun:"name,notnull" json:"name"`
	Slug         string                    `bun:"slug,notnull" json:"slug"`
	Description  *string                   `bun:"description" json:"description,omitempty"`
	TemplatePath string                    `bun:"template_path,notnull" json:"template_path"`
	Regions      map[string]TemplateRegion `bun:"regions,type:jsonb,notnull" json:"regions"`
	Metadata     map[string]any            `bun:"metadata,type:jsonb" json:"metadata,omitempty"`
	CreatedAt    time.Time                 `bun:"created_at,nullzero,default:current_timestamp" json:"created_at"`
	UpdatedAt    time.Time                 `bun:"updated_at,nullzero,default:current_timestamp" json:"updated_at"`

	Theme *Theme `bun:"rel:belongs-to,join:theme_id=id" json:"theme,omitempty"`
}

Template defines the layout surface for pages within a theme.

type TemplateRegion

type TemplateRegion struct {
	Name            string   `json:"name"`
	Description     *string  `json:"description,omitempty"`
	AcceptsWidgets  bool     `json:"accepts_widgets"`
	AcceptsBlocks   bool     `json:"accepts_blocks"`
	FallbackRegions []string `json:"fallback_regions,omitempty"`
}

TemplateRegion describes an individual block/widget surface exposed by a template.

type Theme

type Theme struct {
	bun.BaseModel `bun:"table:themes,alias:t"`

	ID          uuid.UUID   `bun:",pk,type:uuid" json:"id"`
	Name        string      `bun:"name,notnull,unique" json:"name"`
	Description *string     `bun:"description" json:"description,omitempty"`
	Version     string      `bun:"version,notnull" json:"version"`
	Author      *string     `bun:"author" json:"author,omitempty"`
	IsActive    bool        `bun:"is_active,notnull,default:false" json:"is_active"`
	ThemePath   string      `bun:"theme_path,notnull" json:"theme_path"`
	Config      ThemeConfig `bun:"config,type:jsonb" json:"config"`
	CreatedAt   time.Time   `bun:"created_at,nullzero,default:current_timestamp" json:"created_at"`
	UpdatedAt   time.Time   `bun:"updated_at,nullzero,default:current_timestamp" json:"updated_at"`

	Templates []*Template `bun:"rel:has-many,join:id=theme_id" json:"templates,omitempty"`
}

Theme captures a complete site design (templates, assets, metadata).

type ThemeAssets

type ThemeAssets struct {
	BasePath *string  `json:"base_path,omitempty"`
	Styles   []string `json:"styles,omitempty"`
	Scripts  []string `json:"scripts,omitempty"`
	Images   []string `json:"images,omitempty"`
}

ThemeAssets references static files associated with the theme

type ThemeAssetsSummary added in v0.39.0

type ThemeAssetsSummary struct {
	Styles  []string
	Scripts []string
	Images  []string
}

ThemeAssetsSummary lists resolved static assets per theme.

type ThemeConfig

type ThemeConfig struct {
	WidgetAreas   []ThemeWidgetArea   `json:"widget_areas,omitempty"`
	MenuLocations []ThemeMenuLocation `json:"menu_locations,omitempty"`
	Assets        *ThemeAssets        `json:"assets,omitempty"`
	Metadata      map[string]any      `json:"metadata,omitempty"`
}

ThemeConfig records manifest level details parsed from theme descriptors.

type ThemeMenuLocation

type ThemeMenuLocation struct {
	Code        string  `json:"code"`
	Name        string  `json:"name"`
	Description *string `json:"description,omitempty"`
}

ThemeMenuLocation links menus to theme-defined regions

type ThemeSummary added in v0.39.0

type ThemeSummary struct {
	Theme  *Theme
	Assets ThemeAssetsSummary
}

ThemeSummary aggregates a theme with resolved asset paths.

type ThemeWidgetArea

type ThemeWidgetArea struct {
	Code        string  `json:"code"`
	Name        string  `json:"name"`
	Description *string `json:"description,omitempty"`
	Scope       string  `json:"scope,omitempty"` // e.g. "global", "template", "page"
}

ThemeWidgetArea declares widget placements injected by a theme.

type UpdateTemplateInput added in v0.39.0

type UpdateTemplateInput struct {
	TemplateID   uuid.UUID
	Name         *string
	Description  *string
	TemplatePath *string
	Regions      map[string]TemplateRegion
	Metadata     map[string]any
}

Jump to

Keyboard shortcuts

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