template

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Overview

Package template parses page templates (index.html) into nodes that write Go code.

Index

Constants

View Source
const AND = 57359
View Source
const EQ = 57354
View Source
const EXPR_END = 57348
View Source
const EXPR_START = 57347
View Source
const GE = 57356
View Source
const IDENTIFIER = 57350
View Source
const IN = 57353
View Source
const LE = 57357
View Source
const NE = 57355
View Source
const NOT = 57360
View Source
const NUMBER = 57352
View Source
const OR = 57358
View Source
const RAW_EXPR_START = 57349
View Source
const STRING = 57351
View Source
const TEXT = 57346

Variables

This section is empty.

Functions

func Fix

func Fix(code string) string

Fix returns the fix line of a generator error code, or "" for an unknown code.

Types

type Access

type Access struct {
	Roles  []string
	Guard  bool
	Shared bool
	Line   int
}

Access is a template's <ssr:access> rule: the viewer needs one of Roles, "*" admits every viewer, Guard declares the route's Guard method, and Shared says that every viewer the rules admit may see every record of the route and of the routes below it. Line is the line of the tag.

type Call

type Call struct {
	Name, In, Out string
	Line          int
}

Call is an <ssr:call>: a function of the page that its script may call. In and Out are the Go types of its argument and result. Line is the line of the tag.

type Form

type Form struct {
	Name     string
	Node     *node.SsrForm
	Elements []*FormElement
}

Form is an <ssr:form> and its fields.

type FormElement

type FormElement struct {
	Name       string
	Nodes      []node.Node
	Type       FormElementType
	IsRequired bool
	IsMultiple bool
	GoType     string
}

FormElement is a form field; radio and checkbox inputs sharing a name are one field.

type FormElementType

type FormElementType uint8

FormElementType is the kind of a form field.

const (
	FormElementUnknown FormElementType = iota
	FormElementInput
	FormElementInputFile
	FormElementTextarea
	FormElementSelect
)

Form field kinds.

type NodesStack

type NodesStack []node.WithChildren

NodesStack holds the open elements, the root first.

func (*NodesStack) Push

func (s *NodesStack) Push(n node.WithChildren)

Push opens n.

func (*NodesStack) Top

func (s *NodesStack) Top() node.WithChildren

Top returns the innermost open element.

type SsrBindRef

type SsrBindRef struct {
	File    string
	Line    int
	VarName string
	Element *node.HtmlElement
}

SsrBindRef is an ssr:bind attribute on a native input. File is the display path.

type Template

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

Template is a parsed page template.

func Parse

func Parse(path, display string, image func(src string) (string, error)) (*Template, error)

Parse reads the template at path. display is the path shown in error positions, relative to the app root, such as pages/notes/index.html; node positions keep the base name of path. image maps the src of an <img> to its served URL; nil keeps src as it is. Parse returns nil and no error when the file does not exist.

func (*Template) Access

func (t *Template) Access() *Access

Access returns the template's <ssr:access> rule, or nil when it has none.

func (*Template) AnnotateBindings

func (t *Template) AnnotateBindings(reactive map[string]bool, keyer func(refs []string, exprSrc string) string, routeKeyPrefix string) map[string][]string

AnnotateBindings marks the live sites of the template: a {{ }} or {{$ }} that refers to a reactive variable gets a BindingKey; a condition, a loop or an element with a live attribute gets a BlockKey. A site inside a live block is not marked, because the block re-renders it. keyer returns the local key of a value from the variables it refers to and its source; the source of a {{$ }} value starts with "$", so it never shares the key of a {{ }} value. Keys are prefixed with routeKeyPrefix and a dot unless the prefix is empty. AnnotateBindings returns the variables of every key.

func (*Template) Calls

func (t *Template) Calls() []Call

Calls returns the template's <ssr:call> declarations sorted by name.

func (*Template) CollectAllVarRefs

func (t *Template) CollectAllVarRefs(reactive map[string]bool) []string

CollectAllVarRefs returns the reactive variables the template refers to anywhere.

func (*Template) CollectReactiveNodes

func (t *Template) CollectReactiveNodes() map[string]node.Node

CollectReactiveNodes returns every live site by its binding or block key. It needs AnnotateBindings to have run.

func (*Template) GetContentNode

func (t *Template) GetContentNode() *node.SsrContent

GetContentNode returns the <ssr:content/> node, or nil.

func (*Template) GetForms

func (t *Template) GetForms() []*Form

GetForms returns the forms sorted by name.

func (*Template) GetNodes

func (t *Template) GetNodes() []node.Node

GetNodes returns the top-level nodes.

func (*Template) GetSsrBindRefs

func (t *Template) GetSsrBindRefs() []SsrBindRef

GetSsrBindRefs returns the ssr:bind attributes of native inputs.

func (*Template) GetVariables

func (t *Template) GetVariables() []Variable

GetVariables returns the <ssr:var> declarations sorted by name.

func (*Template) HasAssets

func (t *Template) HasAssets() bool

HasAssets reports whether the template has <ssr:assets/>.

func (*Template) MarkBoundElements

func (t *Template) MarkBoundElements(routeKey string)

MarkBoundElements gives every input with ssr:bind the markers the browser runtime reads: data-ssr-bind="<routeKey>.<variable>" and data-ssr-write.

func (*Template) WriteGoCode

func (t *Template) WriteGoCode(buf *gobuf.GoBuf)

WriteGoCode writes the Go code that renders the template.

type Variable

type Variable struct {
	File           string
	Line           int
	Name           string
	Type           string
	Reactive       bool
	ClientWritable bool
}

Variable is an <ssr:var> declaration.

func (*Variable) FilePos

func (v *Variable) FilePos() string

FilePos returns the //line directive of the declaration.

Directories

Path Synopsis
Package htmlutils holds element sets of the HTML syntax.
Package htmlutils holds element sets of the HTML syntax.

Jump to

Keyboard shortcuts

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