themes

package
v0.60.8 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrTemplateThemeRequired indicates the theme ID is missing.
	ErrTemplateThemeRequired = cmsthemes.ErrTemplateThemeRequired
	// ErrTemplateNameRequired indicates the template name is missing.
	ErrTemplateNameRequired = cmsthemes.ErrTemplateNameRequired
	// ErrTemplateSlugRequired indicates the slug is missing.
	ErrTemplateSlugRequired = cmsthemes.ErrTemplateSlugRequired
	// ErrTemplatePathRequired indicates the file path is missing.
	ErrTemplatePathRequired = cmsthemes.ErrTemplatePathRequired
	// ErrTemplateSlugConflict indicates a duplicate slug within a theme.
	ErrTemplateSlugConflict = cmsthemes.ErrTemplateSlugConflict
	// ErrTemplateRegionsInvalid indicates malformed region metadata.
	ErrTemplateRegionsInvalid = cmsthemes.ErrTemplateRegionsInvalid
)
View Source
var (
	ErrFeatureDisabled            = errors.New("themes: feature disabled")
	ErrThemeRepositoryRequired    = errors.New("themes: theme repository required")
	ErrTemplateRepositoryRequired = errors.New("themes: template repository required")

	ErrThemeNameRequired    = errors.New("themes: name required")
	ErrThemeVersionRequired = errors.New("themes: version required")
	ErrThemePathRequired    = errors.New("themes: theme path required")
	ErrThemeExists          = errors.New("themes: theme already exists")
	ErrThemeNotFound        = errors.New("themes: theme not found")

	ErrThemeActivationMissingTemplates = errors.New("themes: activation requires at least one template")
	ErrThemeActivationPathInvalid      = errors.New("themes: activation requires theme_path")
	ErrThemeWidgetAreaInvalid          = errors.New("themes: widget area missing code or name")

	ErrTemplateNotFound = errors.New("themes: template not found")
)

Functions

func Bootstrap

func Bootstrap(ctx context.Context, svc Service, seeds []ThemeSeed) error

Bootstrap applies seeds to the provided service, tolerating duplicates.

func InspectThemeRegions

func InspectThemeRegions(templates []*Template) map[string][]RegionInfo

InspectThemeRegions aggregates region info across templates.

func NewTemplateRepository

func NewTemplateRepository(db *bun.DB) repository.Repository[*Template]

NewTemplateRepository creates a repository for templates.

func NewThemeRepository

func NewThemeRepository(db *bun.DB) repository.Repository[*Theme]

NewThemeRepository creates a repository for themes.

func ValidateRegisterTemplate

func ValidateRegisterTemplate(ctx context.Context, repo TemplateRepository, input RegisterTemplateInput) error

ValidateRegisterTemplate ensures new template inputs are well formed.

func ValidateUpdateTemplate

func ValidateUpdateTemplate(input UpdateTemplateInput) error

ValidateUpdateTemplate ensures updates preserve invariants.

Types

type AssetResolver

type AssetResolver interface {
	Open(asset string) (io.ReadCloser, error)
	ResolvePath(asset string) (string, error)
}

AssetResolver abstracts theme asset lookups for tests and production.

type BunTemplateRepository

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

BunTemplateRepository implements TemplateRepository with optional caching.

func NewBunTemplateRepository

func NewBunTemplateRepository(db *bun.DB) *BunTemplateRepository

NewBunTemplateRepository creates a template repository without caching.

func NewBunTemplateRepositoryWithCache

func NewBunTemplateRepositoryWithCache(db *bun.DB, cacheService cache.CacheService, serializer cache.KeySerializer) *BunTemplateRepository

NewBunTemplateRepositoryWithCache creates a template repository with caching.

func (*BunTemplateRepository) Create

func (r *BunTemplateRepository) Create(ctx context.Context, template *Template) (*Template, error)

func (*BunTemplateRepository) Delete

func (r *BunTemplateRepository) Delete(ctx context.Context, id uuid.UUID) error

func (*BunTemplateRepository) GetByID

func (r *BunTemplateRepository) GetByID(ctx context.Context, id uuid.UUID) (*Template, error)

func (*BunTemplateRepository) GetBySlug

func (r *BunTemplateRepository) GetBySlug(ctx context.Context, themeID uuid.UUID, slug string) (*Template, error)

func (*BunTemplateRepository) ListAll

func (r *BunTemplateRepository) ListAll(ctx context.Context) ([]*Template, error)

func (*BunTemplateRepository) ListByTheme

func (r *BunTemplateRepository) ListByTheme(ctx context.Context, themeID uuid.UUID) ([]*Template, error)

func (*BunTemplateRepository) Update

func (r *BunTemplateRepository) Update(ctx context.Context, template *Template) (*Template, error)

type BunThemeRepository

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

BunThemeRepository implements ThemeRepository with optional caching.

func NewBunThemeRepository

func NewBunThemeRepository(db *bun.DB) *BunThemeRepository

NewBunThemeRepository creates a theme repository without caching.

func NewBunThemeRepositoryWithCache

func NewBunThemeRepositoryWithCache(db *bun.DB, cacheService cache.CacheService, serializer cache.KeySerializer) *BunThemeRepository

NewBunThemeRepositoryWithCache creates a theme repository with caching support.

func (*BunThemeRepository) Create

func (r *BunThemeRepository) Create(ctx context.Context, theme *Theme) (*Theme, error)

func (*BunThemeRepository) GetByID

func (r *BunThemeRepository) GetByID(ctx context.Context, id uuid.UUID) (*Theme, error)

func (*BunThemeRepository) GetByName

func (r *BunThemeRepository) GetByName(ctx context.Context, name string) (*Theme, error)

func (*BunThemeRepository) List

func (r *BunThemeRepository) List(ctx context.Context) ([]*Theme, error)

func (*BunThemeRepository) ListActive

func (r *BunThemeRepository) ListActive(ctx context.Context) ([]*Theme, error)

func (*BunThemeRepository) Update

func (r *BunThemeRepository) Update(ctx context.Context, theme *Theme) (*Theme, error)

type FileSystemAssetResolver

type FileSystemAssetResolver struct {
	FS       fs.FS
	BasePath string
}

FileSystemAssetResolver resolves assets from an fs.FS implementation.

func (FileSystemAssetResolver) Open

Open returns a reader for the requested asset relative to BasePath.

func (FileSystemAssetResolver) ResolvePath

func (r FileSystemAssetResolver) ResolvePath(asset string) (string, error)

ResolvePath returns the on-disk path suitable for HTTP serving.

type IDGenerator

type IDGenerator func() uuid.UUID

IDGenerator produces unique identifiers.

type Manifest

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

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

LoadManifest reads and parses a manifest from disk.

func ParseManifest

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

ParseManifest decodes manifest JSON from a reader.

type MemoryTemplateRepository

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

MemoryTemplateRepository provides an in-memory implementation of TemplateRepository.

func NewMemoryTemplateRepository

func NewMemoryTemplateRepository() *MemoryTemplateRepository

NewMemoryTemplateRepository constructs an empty memory-backed template repository.

func (*MemoryTemplateRepository) Create

func (r *MemoryTemplateRepository) Create(_ context.Context, template *Template) (*Template, error)

func (*MemoryTemplateRepository) Delete

func (*MemoryTemplateRepository) GetByID

func (*MemoryTemplateRepository) GetBySlug

func (r *MemoryTemplateRepository) GetBySlug(_ context.Context, themeID uuid.UUID, slug string) (*Template, error)

func (*MemoryTemplateRepository) ListAll

func (*MemoryTemplateRepository) ListByTheme

func (r *MemoryTemplateRepository) ListByTheme(_ context.Context, themeID uuid.UUID) ([]*Template, error)

func (*MemoryTemplateRepository) Update

func (r *MemoryTemplateRepository) Update(_ context.Context, template *Template) (*Template, error)

type MemoryThemeRepository

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

MemoryThemeRepository provides an in-memory implementation of ThemeRepository.

func NewMemoryThemeRepository

func NewMemoryThemeRepository() *MemoryThemeRepository

NewMemoryThemeRepository constructs an empty memory-backed theme repository.

func (*MemoryThemeRepository) Create

func (r *MemoryThemeRepository) Create(_ context.Context, theme *Theme) (*Theme, error)

func (*MemoryThemeRepository) GetByID

func (r *MemoryThemeRepository) GetByID(_ context.Context, id uuid.UUID) (*Theme, error)

func (*MemoryThemeRepository) GetByName

func (r *MemoryThemeRepository) GetByName(_ context.Context, name string) (*Theme, error)

func (*MemoryThemeRepository) List

func (r *MemoryThemeRepository) List(_ context.Context) ([]*Theme, error)

func (*MemoryThemeRepository) ListActive

func (r *MemoryThemeRepository) ListActive(_ context.Context) ([]*Theme, error)

func (*MemoryThemeRepository) Update

func (r *MemoryThemeRepository) Update(_ context.Context, theme *Theme) (*Theme, error)

type NotFoundError

type NotFoundError struct {
	Resource string
	Key      string
}

NotFoundError is returned when a theme resource cannot be located.

func (*NotFoundError) Error

func (e *NotFoundError) Error() string

type RegionInfo

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

RegionInfo summarises region capabilities for consumers.

func InspectTemplateRegions

func InspectTemplateRegions(template *Template) []RegionInfo

InspectTemplateRegions flattens region metadata for a template.

type RegisterTemplateInput

type RegisterTemplateInput = cmsthemes.RegisterTemplateInput

type RegisterThemeInput

type RegisterThemeInput = cmsthemes.RegisterThemeInput

func ManifestToThemeInput

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

ManifestToThemeInput converts a manifest into a registration payload.

type Registry

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

Registry stores built-in or host-defined theme seeds.

func NewRegistry

func NewRegistry() *Registry

NewRegistry constructs an empty theme registry.

func (*Registry) List

func (r *Registry) List() []ThemeSeed

List returns all registered seeds.

func (*Registry) Register

func (r *Registry) Register(seed ThemeSeed)

Register adds a theme seed to the registry, overriding existing keys.

type Service

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.

func NewNoOpService

func NewNoOpService() Service

func NewService

func NewService(themeRepo ThemeRepository, templateRepo TemplateRepository, opts ...ServiceOption) Service

NewService constructs a theme service instance.

type ServiceOption

type ServiceOption func(*service)

ServiceOption configures service behaviour.

func WithNow

func WithNow(now func() time.Time) ServiceOption

WithNow overrides the time source (primarily for tests).

func WithThemeIDGenerator

func WithThemeIDGenerator(generator IDGenerator) ServiceOption

WithThemeIDGenerator overrides the default ID generator.

type Template

type Template = cmsthemes.Template

func PrepareTemplateRecord

func PrepareTemplateRecord(input RegisterTemplateInput, idGenerator func() uuid.UUID) *Template

PrepareTemplateRecord normalises register template input for persistence.

type TemplateRegion

type TemplateRegion = cmsthemes.TemplateRegion

type TemplateRepository

type TemplateRepository interface {
	Create(ctx context.Context, template *Template) (*Template, error)
	Update(ctx context.Context, template *Template) (*Template, error)
	GetByID(ctx context.Context, id uuid.UUID) (*Template, error)
	GetBySlug(ctx context.Context, themeID uuid.UUID, slug string) (*Template, error)
	ListByTheme(ctx context.Context, themeID uuid.UUID) ([]*Template, error)
	ListAll(ctx context.Context) ([]*Template, error)
	Delete(ctx context.Context, id uuid.UUID) error
}

TemplateRepository exposes persistence operations for templates.

type Theme

type Theme = cmsthemes.Theme

type ThemeAssets

type ThemeAssets = cmsthemes.ThemeAssets

type ThemeAssetsSummary

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

ThemeAssetsSummary lists resolved static assets per theme.

type ThemeConfig

type ThemeConfig = cmsthemes.ThemeConfig

type ThemeMenuLocation

type ThemeMenuLocation = cmsthemes.ThemeMenuLocation

type ThemeRepository

type ThemeRepository interface {
	Create(ctx context.Context, theme *Theme) (*Theme, error)
	Update(ctx context.Context, theme *Theme) (*Theme, error)
	GetByID(ctx context.Context, id uuid.UUID) (*Theme, error)
	GetByName(ctx context.Context, name string) (*Theme, error)
	List(ctx context.Context) ([]*Theme, error)
	ListActive(ctx context.Context) ([]*Theme, error)
}

ThemeRepository exposes persistence operations for themes.

type ThemeSeed

type ThemeSeed struct {
	Theme     RegisterThemeInput
	Templates []RegisterTemplateInput
}

ThemeSeed describes a theme and its templates for bootstrapping.

type ThemeSummary

type ThemeSummary struct {
	Theme  *Theme
	Assets ThemeAssetsSummary
}

ThemeSummary aggregates a theme with resolved asset paths.

type ThemeWidgetArea

type ThemeWidgetArea = cmsthemes.ThemeWidgetArea

type UpdateTemplateInput

type UpdateTemplateInput = cmsthemes.UpdateTemplateInput

Jump to

Keyboard shortcuts

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