Documentation
¶
Overview ¶
Package component provides the ComponentRegistry for component overrides.
Index ¶
- Constants
- func AllSlots() []string
- type Registry
- func (r *Registry) LoadOverridesFromDir(dir string) error
- func (r *Registry) Register(name string, content []byte) error
- func (r *Registry) RegisterTemplate(name string, tmpl *htmltemplate.Template)
- func (r *Registry) RenderComponent(name string, data any) (htmltemplate.HTML, error)
- func (r *Registry) RenderComponentWithFuncs(name string, data any, funcs htmltemplate.FuncMap) (htmltemplate.HTML, error)
- func (r *Registry) Resolve(name string) *htmltemplate.Template
- func (r *Registry) SlotNames() []string
Constants ¶
const ( SlotHead = "Head" SlotScripts = "Scripts" SlotHeader = "Header" SlotSiteTitle = "SiteTitle" SlotSearch = "Search" SlotThemeToggle = "ThemeToggle" SlotSidebar = "Sidebar" SlotTableOfContents = "TableOfContents" SlotMobileTableOfContents = "MobileTableOfContents" SlotBreadcrumbs = "Breadcrumbs" SlotPagination = "Pagination" SlotPageTitle = "PageTitle" SlotContentPanel = "ContentPanel" SlotEditLink = "EditLink" SlotLastUpdated = "LastUpdated" SlotFallbackNotice = "FallbackNotice" SlotDocsTabSwitcher = "DocsTabSwitcher" SlotVersionSwitcher = "VersionSwitcher" SlotVersionBanner = "VersionBanner" SlotLabBadge = "LabBadge" SlotLearningObjectives = "LearningObjectives" SlotLabProgress = "LabProgress" )
Built-in component slot names. Each slot has a default template compiled into the binary and can be overridden by themes or users.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry manages component templates with override support. Components are engine-owned UI slots with safe defaults that can be overridden by themes and users.
func NewRegistry ¶
NewRegistry creates a Registry and loads default component templates from the embedded FS. funcMap is shared with the template engine so components can use the same functions.
func (*Registry) LoadOverridesFromDir ¶
LoadOverridesFromDir loads component overrides from a filesystem directory. Each .html file in the directory overrides the component named after the file (without extension). For example, Header.html overrides the "Header" component.
func (*Registry) Register ¶
Register parses raw template bytes and registers the result for a named slot.
func (*Registry) RegisterTemplate ¶
func (r *Registry) RegisterTemplate(name string, tmpl *htmltemplate.Template)
RegisterTemplate directly registers a pre-parsed template for a named slot.
func (*Registry) RenderComponent ¶
RenderComponent executes a component template and returns the rendered HTML. Returns empty HTML (no error) for unknown slots to allow graceful degradation.
func (*Registry) RenderComponentWithFuncs ¶
func (r *Registry) RenderComponentWithFuncs(name string, data any, funcs htmltemplate.FuncMap) (htmltemplate.HTML, error)
RenderComponentWithFuncs executes a component with a per-render FuncMap.