core

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2025 License: AGPL-3.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ComponentRegistry = map[string]func() Component{}

ComponentRegistry holds constructors for components that can be loaded on-demand. Components can register themselves with a unique name and a constructor function returning a new instance of the component. This allows templates to reference components by name using runtime selection attributes like `rt-is`.

View Source
var DevMode bool

DevMode enables additional runtime checks and warnings for development. It is disabled by default.

Functions

func LoadComponentTemplate

func LoadComponentTemplate(templateFs []byte) (string, error)

func RegisterComponent

func RegisterComponent(name string, constructor func() Component)

RegisterComponent registers a component constructor under the provided name. When a template references the name via `rt-is`, the constructor will be invoked to create a new component instance at render time.

func RegisterPlugin

func RegisterPlugin(p Plugin)

RegisterPlugin registers a plugin and allows it to add hooks.

func SetDevMode

func SetDevMode(enabled bool)

SetDevMode toggles development mode features.

func SetLogger

func SetLogger(l Logger)

SetLogger allows applications to replace the default logger.

func TriggerMount

func TriggerMount(c Component)

TriggerMount invokes mount lifecycle hooks.

func TriggerRouter

func TriggerRouter(path string)

TriggerRouter invokes router hooks with the given path.

func TriggerStore

func TriggerStore(module, store, key string, value interface{})

TriggerStore invokes store hooks for a mutation.

func TriggerTemplate

func TriggerTemplate(componentID, html string)

TriggerTemplate invokes template hooks with rendered HTML for a component.

func TriggerUnmount

func TriggerUnmount(c Component)

TriggerUnmount invokes unmount lifecycle hooks.

Types

type App

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

App maintains registered hooks and exposes helper methods for plugins to attach to framework events.

func (*App) RegisterLifecycle

func (a *App) RegisterLifecycle(mount, unmount func(Component))

RegisterLifecycle adds hooks for component mount and unmount.

func (*App) RegisterRouter

func (a *App) RegisterRouter(fn func(string))

RegisterRouter adds a router navigation hook.

func (*App) RegisterStore

func (a *App) RegisterStore(fn func(module, store, key string, value interface{}))

RegisterStore adds a store mutation hook.

func (*App) RegisterTemplate

func (a *App) RegisterTemplate(fn func(componentID, html string))

RegisterTemplate adds a template render hook.

type Component

type Component interface {
	Render() string
	Mount()
	Unmount()
	OnMount()
	OnUnmount()
	GetName() string
	GetID() string
	SetSlots(map[string]string)
}

func LoadComponent

func LoadComponent(name string) Component

LoadComponent retrieves a component by name using the registry. If no component is registered under that name, nil is returned.

type ConditionContent

type ConditionContent struct {
	Branches []ConditionalBranchContent
}

type ConditionDependency

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

type ConditionalBranch

type ConditionalBranch struct {
	Condition string // empty for @else
	Nodes     []Node
}

type ConditionalBranchContent

type ConditionalBranchContent struct {
	Condition string
	Content   string
}

ConditionContent stores rendered content for each branch of a conditional block

type ConditionalNode

type ConditionalNode struct {
	Branches []ConditionalBranch
}

func (*ConditionalNode) Render

func (cn *ConditionalNode) Render(c *HTMLComponent) string

Render evaluates the conditional branches and renders the appropriate content.

type HTMLComponent

type HTMLComponent struct {
	ID           string
	Name         string
	Template     string
	TemplateFS   []byte
	Dependencies map[string]Component

	Store *state.Store
	Props map[string]interface{}
	Slots map[string]string
	// contains filtered or unexported fields
}

func NewHTMLComponent

func NewHTMLComponent(name string, templateFs []byte, props map[string]interface{}) *HTMLComponent

func (*HTMLComponent) AddDependency

func (c *HTMLComponent) AddDependency(placeholderName string, dep Component)

func (*HTMLComponent) GetID

func (c *HTMLComponent) GetID() string

func (*HTMLComponent) GetName

func (c *HTMLComponent) GetName() string

func (*HTMLComponent) Init

func (c *HTMLComponent) Init(store *state.Store)

func (*HTMLComponent) Mount

func (c *HTMLComponent) Mount()

func (*HTMLComponent) OnMount

func (c *HTMLComponent) OnMount()

func (*HTMLComponent) OnUnmount

func (c *HTMLComponent) OnUnmount()

func (*HTMLComponent) Render

func (c *HTMLComponent) Render() (renderedTemplate string)

func (*HTMLComponent) SetComponent

func (c *HTMLComponent) SetComponent(component Component)

func (*HTMLComponent) SetRouteParams

func (c *HTMLComponent) SetRouteParams(params map[string]string)

func (*HTMLComponent) SetSlots

func (c *HTMLComponent) SetSlots(slots map[string]string)

func (*HTMLComponent) Unmount

func (c *HTMLComponent) Unmount()

type Logger

type Logger interface {
	Debug(format string, v ...interface{})
	Info(format string, v ...interface{})
	Warn(format string, v ...interface{})
	Error(format string, v ...interface{})
}

Logger defines logging interface used by the framework.

func Log

func Log() Logger

Log returns the active logger implementation.

type Node

type Node interface {
	Render(c *HTMLComponent) string
}

AST structures for template parsing

type Plugin

type Plugin interface {
	Install(*App)
}

Plugin defines interface for plugins to register hooks on the App.

type TextNode

type TextNode struct {
	Text string
}

func (*TextNode) Render

func (t *TextNode) Render(c *HTMLComponent) string

Jump to

Keyboard shortcuts

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