Documentation
¶
Index ¶
- Variables
- func Bootstrap(ctx context.Context, svc Service, seeds []ThemeSeed) error
- func InspectThemeRegions(templates []*Template) map[string][]RegionInfo
- func NewTemplateRepository(db *bun.DB) repository.Repository[*Template]
- func NewThemeRepository(db *bun.DB) repository.Repository[*Theme]
- func ValidateRegisterTemplate(ctx context.Context, repo TemplateRepository, input RegisterTemplateInput) error
- func ValidateUpdateTemplate(input UpdateTemplateInput) error
- type AssetResolver
- type BunTemplateRepository
- func (r *BunTemplateRepository) Create(ctx context.Context, template *Template) (*Template, error)
- func (r *BunTemplateRepository) Delete(ctx context.Context, id uuid.UUID) error
- func (r *BunTemplateRepository) GetByID(ctx context.Context, id uuid.UUID) (*Template, error)
- func (r *BunTemplateRepository) GetBySlug(ctx context.Context, themeID uuid.UUID, slug string) (*Template, error)
- func (r *BunTemplateRepository) ListAll(ctx context.Context) ([]*Template, error)
- func (r *BunTemplateRepository) ListByTheme(ctx context.Context, themeID uuid.UUID) ([]*Template, error)
- func (r *BunTemplateRepository) Update(ctx context.Context, template *Template) (*Template, error)
- type BunThemeRepository
- func (r *BunThemeRepository) Create(ctx context.Context, theme *Theme) (*Theme, error)
- func (r *BunThemeRepository) GetByID(ctx context.Context, id uuid.UUID) (*Theme, error)
- func (r *BunThemeRepository) GetByName(ctx context.Context, name string) (*Theme, error)
- func (r *BunThemeRepository) List(ctx context.Context) ([]*Theme, error)
- func (r *BunThemeRepository) ListActive(ctx context.Context) ([]*Theme, error)
- func (r *BunThemeRepository) Update(ctx context.Context, theme *Theme) (*Theme, error)
- type FileSystemAssetResolver
- type IDGenerator
- type Manifest
- type MemoryTemplateRepository
- func (r *MemoryTemplateRepository) Create(_ context.Context, template *Template) (*Template, error)
- func (r *MemoryTemplateRepository) Delete(_ context.Context, id uuid.UUID) error
- func (r *MemoryTemplateRepository) GetByID(_ context.Context, id uuid.UUID) (*Template, error)
- func (r *MemoryTemplateRepository) GetBySlug(_ context.Context, themeID uuid.UUID, slug string) (*Template, error)
- func (r *MemoryTemplateRepository) ListAll(_ context.Context) ([]*Template, error)
- func (r *MemoryTemplateRepository) ListByTheme(_ context.Context, themeID uuid.UUID) ([]*Template, error)
- func (r *MemoryTemplateRepository) Update(_ context.Context, template *Template) (*Template, error)
- type MemoryThemeRepository
- func (r *MemoryThemeRepository) Create(_ context.Context, theme *Theme) (*Theme, error)
- func (r *MemoryThemeRepository) GetByID(_ context.Context, id uuid.UUID) (*Theme, error)
- func (r *MemoryThemeRepository) GetByName(_ context.Context, name string) (*Theme, error)
- func (r *MemoryThemeRepository) List(_ context.Context) ([]*Theme, error)
- func (r *MemoryThemeRepository) ListActive(_ context.Context) ([]*Theme, error)
- func (r *MemoryThemeRepository) Update(_ context.Context, theme *Theme) (*Theme, error)
- type NotFoundError
- type RegionInfo
- type RegisterTemplateInput
- type RegisterThemeInput
- type Registry
- type Service
- type ServiceOption
- type Template
- type TemplateRegion
- type TemplateRepository
- type Theme
- type ThemeAssets
- type ThemeAssetsSummary
- type ThemeConfig
- type ThemeMenuLocation
- type ThemeRepository
- type ThemeSeed
- type ThemeSummary
- type ThemeWidgetArea
- type UpdateTemplateInput
Constants ¶
This section is empty.
Variables ¶
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 )
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 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) ListAll ¶
func (r *BunTemplateRepository) ListAll(ctx context.Context) ([]*Template, error)
func (*BunTemplateRepository) ListByTheme ¶
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) List ¶
func (r *BunThemeRepository) List(ctx context.Context) ([]*Theme, error)
func (*BunThemeRepository) ListActive ¶
func (r *BunThemeRepository) ListActive(ctx context.Context) ([]*Theme, error)
type FileSystemAssetResolver ¶
FileSystemAssetResolver resolves assets from an fs.FS implementation.
func (FileSystemAssetResolver) Open ¶
func (r FileSystemAssetResolver) Open(asset string) (io.ReadCloser, error)
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 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 ¶
LoadManifest reads and parses a manifest from disk.
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) ListAll ¶
func (r *MemoryTemplateRepository) ListAll(_ context.Context) ([]*Template, error)
func (*MemoryTemplateRepository) ListByTheme ¶
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) List ¶
func (r *MemoryThemeRepository) List(_ context.Context) ([]*Theme, error)
func (*MemoryThemeRepository) ListActive ¶
func (r *MemoryThemeRepository) ListActive(_ context.Context) ([]*Theme, error)
type NotFoundError ¶
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.
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 ¶
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 ThemeAssets ¶
type ThemeAssets = cmsthemes.ThemeAssets
type ThemeAssetsSummary ¶
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