view

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var OnRendered func(name string, duration time.Duration, data any)

OnRendered is called after a successful template render.

Functions

func RegisterFunc

func RegisterFunc(name string, fn any)

RegisterFunc registers a global template function.

func RegisterFuncs

func RegisterFuncs(funcs template.FuncMap)

RegisterFuncs registers multiple global template functions.

func RegisterPluginViews

func RegisterPluginViews(prefix string, filesystem fs.FS)

RegisterPluginViews registers an embedded FS for views.

func Render

func Render(name string, data any) (string, error)

Render is a shortcut for Default.Render.

func SetRoot

func SetRoot(root string)

SetRoot sets the default engine root and clears cache.

Types

type Context

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

Context represents the provide/inject context store.

func NewContext

func NewContext() *Context

NewContext creates a new Provide/Inject Context store.

func (*Context) Inject

func (c *Context) Inject(key string) any

Inject accesses the state shared by parent components.

func (*Context) Provide

func (c *Context) Provide(key string, val any) string

Provide shares state with child component trees.

type Engine

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

Engine renders .nimbus templates (Edge-style: {{ variable }}, {{{ raw }}}, @if, @each, @layout, @component).

var Default *Engine

Default engine.

func New

func New(root string, funcs template.FuncMap) *Engine

New creates a view engine with views loaded from root (e.g. "views"). Templates use .nimbus extension.

func (*Engine) Render

func (e *Engine) Render(name string, data any) (string, error)

Render renders the named view (e.g. "home" -> views/home.nimbus) with data. Supports @layout('layout') like Edge.

func (*Engine) RenderWriter

func (e *Engine) RenderWriter(name string, data any, w io.Writer) error

RenderWriter writes the rendered view to w.

type Props

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

Props represents HTML element attributes and helper APIs.

func NewProps

func NewProps(data map[string]any) *Props

NewProps creates a new Props instance.

func (*Props) Except

func (p *Props) Except(keys []any) *Props

Except returns a new Props instance without the specified keys.

func (*Props) Get

func (p *Props) Get(key string, fallback ...any) any

Get retrieves a prop value, with optional default fallback.

func (*Props) Has

func (p *Props) Has(key string) bool

Has checks if a prop was provided.

func (*Props) Merge

func (p *Props) Merge(defaults map[string]any) *Props

Merge merges custom properties with props values.

func (*Props) MergeIf

func (p *Props) MergeIf(cond bool, defaults map[string]any) *Props

MergeIf merges defaults if condition is true.

func (*Props) MergeUnless

func (p *Props) MergeUnless(cond bool, defaults map[string]any) *Props

MergeUnless merges defaults if condition is false.

func (*Props) Only

func (p *Props) Only(keys []any) *Props

Only returns a new Props instance with only the specified keys.

func (*Props) ToAttrs

func (p *Props) ToAttrs() template.HTMLAttr

ToAttrs serializes all props into HTML attribute string.

Jump to

Keyboard shortcuts

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