component

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package component provides the ComponentRegistry for component overrides.

Index

Constants

View Source
const (
	SlotHead                  = "Head"
	SlotScripts               = "Scripts"
	SlotHeader                = "Header"
	SlotSiteTitle             = "SiteTitle"
	SlotGlobalNav             = "GlobalNav"
	SlotSearch                = "Search"
	SlotThemeToggle           = "ThemeToggle"
	SlotSidebar               = "Sidebar"
	SlotTableOfContents       = "TableOfContents"
	SlotMobileTableOfContents = "MobileTableOfContents"
	SlotBreadcrumbs           = "Breadcrumbs"
	SlotPagination            = "Pagination"
	SlotPageTitle             = "PageTitle"
	SlotContentPanel          = "ContentPanel"
	SlotFooter                = "Footer"
	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

func AllSlots

func AllSlots() []string

AllSlots returns all built-in component slot names.

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

func NewRegistry(embeddedFS fs.FS, funcMap htmltemplate.FuncMap) (*Registry, error)

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

func (r *Registry) LoadOverridesFromDir(dir string) error

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

func (r *Registry) Register(name string, content []byte) error

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

func (r *Registry) RenderComponent(name string, data any) (htmltemplate.HTML, error)

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.

func (*Registry) Resolve

func (r *Registry) Resolve(name string) *htmltemplate.Template

Resolve returns the template for a named component slot, or nil if not registered.

func (*Registry) SlotNames

func (r *Registry) SlotNames() []string

SlotNames returns the names of all registered component slots.

Jump to

Keyboard shortcuts

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