node

package
v0.12.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	FormEncTypeMultipart = "multipart/form-data"
	FormEncUrlEncoded    = "application/x-www-form-urlencoded"
)

Form encodings.

Variables

This section is empty.

Functions

func UnionRefs

func UnionRefs(sets ...[]string) []string

UnionRefs merges CollectVarRefs results in order, without duplicates. It never returns nil.

Types

type BaseNode

type BaseNode struct {
	File string
	Line int
}

BaseNode is a node's position: the template's base name and the line.

func (*BaseNode) FilePos

func (n *BaseNode) FilePos() string

type Content

type Content struct {
	BaseNode
	Children []Node
}

Content is a run of text and values.

func (*Content) CollectVarRefs

func (n *Content) CollectVarRefs(reactive map[string]bool) []string

func (*Content) WriteGoCode

func (n *Content) WriteGoCode(buf *gobuf.GoBuf)

type Esc

type Esc uint8

Esc names the escaper generated code uses for an expression's value.

const (
	EscText Esc = iota
	EscAttr
	EscURL
	EscURLPart
	EscURLPathStart
	EscURLQuery
)

Escapers, one per HTML context.

func (Esc) Func

func (e Esc) Func() string

Func returns the render function for e.

type Expression

type Expression struct {
	BaseNode
	Value Node
	Esc   Esc
	// RCDATA is set for the text of <title> and <textarea>, which cannot hold a live value.
	RCDATA bool
	// Source is the trimmed text between {{ and }}.
	Source string
	// BindingKey is set for a live value; the value is then wrapped in <span data-ssr-bind="KEY">.
	BindingKey string
}

Expression is a {{ }} value, written through the escaper Esc.

func (*Expression) CollectVarRefs

func (n *Expression) CollectVarRefs(reactive map[string]bool) []string

func (*Expression) WriteGoCode

func (n *Expression) WriteGoCode(buf *gobuf.GoBuf)

func (*Expression) WriteInnerGoCode

func (n *Expression) WriteInnerGoCode(buf *gobuf.GoBuf)

WriteInnerGoCode writes the value without the live-value wrapper.

type ExpressionsList

type ExpressionsList struct {
	BaseNode
	Values []Node
}

ExpressionsList is the arguments of a call.

func (*ExpressionsList) CollectVarRefs

func (n *ExpressionsList) CollectVarRefs(reactive map[string]bool) []string

func (*ExpressionsList) WriteGoCode

func (n *ExpressionsList) WriteGoCode(buf *gobuf.GoBuf)

type Function

type Function struct {
	BaseNode
	Expr      Node
	Arguments *ExpressionsList
}

Function is a call.

func (*Function) CollectVarRefs

func (n *Function) CollectVarRefs(reactive map[string]bool) []string

func (*Function) WriteGoCode

func (n *Function) WriteGoCode(buf *gobuf.GoBuf)

type HtmlAttribute

type HtmlAttribute struct {
	Key    string
	Values []Node
}

HtmlAttribute is an attribute and its value as text and expressions.

type HtmlElement

type HtmlElement struct {
	BaseNode
	TagName    string
	Attributes []HtmlAttribute
	SelfClosed bool
	Children   []Node
	// BlockKey is set when an attribute value is live; the element is then wrapped in
	// <ssr-block data-ssr-bind="KEY"> and re-rendered whole.
	BlockKey string
}

HtmlElement is an HTML element of the template.

func (*HtmlElement) AddChildren

func (n *HtmlElement) AddChildren(children ...Node)

func (*HtmlElement) CollectAttributeVarRefs

func (n *HtmlElement) CollectAttributeVarRefs(reactive map[string]bool) []string

CollectAttributeVarRefs returns the reactive variables the attribute values refer to, without the children.

func (*HtmlElement) CollectVarRefs

func (n *HtmlElement) CollectVarRefs(reactive map[string]bool) []string

func (*HtmlElement) LastChild

func (n *HtmlElement) LastChild() Node

func (*HtmlElement) PopChild

func (n *HtmlElement) PopChild()

func (*HtmlElement) WriteGoCode

func (n *HtmlElement) WriteGoCode(buf *gobuf.GoBuf)

func (*HtmlElement) WriteInnerGoCode

func (n *HtmlElement) WriteInnerGoCode(buf *gobuf.GoBuf)

WriteInnerGoCode writes the element without the live-block wrapper.

type HtmlRaw

type HtmlRaw struct {
	BaseNode
	Data string
}

HtmlRaw is markup written as it is, such as the doctype.

func (*HtmlRaw) CollectVarRefs

func (n *HtmlRaw) CollectVarRefs(_ map[string]bool) []string

func (*HtmlRaw) WriteGoCode

func (n *HtmlRaw) WriteGoCode(buf *gobuf.GoBuf)

type Indexed

type Indexed struct {
	BaseNode
	Expr  Node
	Index Node
}

Indexed is an index expression, a[i].

func (*Indexed) CollectVarRefs

func (n *Indexed) CollectVarRefs(reactive map[string]bool) []string

func (*Indexed) WriteGoCode

func (n *Indexed) WriteGoCode(buf *gobuf.GoBuf)

type Loop

type Loop struct {
	BaseNode
	Index    string
	Variable string
	Array    Node
	Children []Node
	// BlockKey is set when the list or the body is live; the whole loop output is then
	// wrapped and re-rendered.
	BlockKey string
}

Loop is an element with ssr:for.

func (*Loop) CollectVarRefs

func (n *Loop) CollectVarRefs(reactive map[string]bool) []string

CollectVarRefs returns the reactive variables of the list and of the body.

func (*Loop) WriteGoCode

func (n *Loop) WriteGoCode(buf *gobuf.GoBuf)

func (*Loop) WriteInnerGoCode

func (n *Loop) WriteInnerGoCode(buf *gobuf.GoBuf)

WriteInnerGoCode writes the loop without the live-block wrapper.

type Node

type Node interface {
	WriteGoCode(buf *gobuf.GoBuf)
	// FilePos returns the //line directive of the node's template position.
	FilePos() string
	// CollectVarRefs returns the variables of reactive that the node's subtree refers to,
	// never nil.
	CollectVarRefs(reactive map[string]bool) []string
}

Node is a part of a parsed template that writes Go code.

type Number

type Number struct {
	BaseNode
	Text string
}

Number is a number literal. A negative one is written in parentheses, so it stays one operand after an operator, as in a-(-1).

func (*Number) CollectVarRefs

func (n *Number) CollectVarRefs(_ map[string]bool) []string

func (*Number) WriteGoCode

func (n *Number) WriteGoCode(buf *gobuf.GoBuf)

type Operator

type Operator struct {
	BaseNode
	Op    string
	Left  Node
	Right Node
}

Operator is a unary or binary operator; Left is nil for "!".

func (*Operator) CollectVarRefs

func (n *Operator) CollectVarRefs(reactive map[string]bool) []string

func (*Operator) WriteGoCode

func (n *Operator) WriteGoCode(buf *gobuf.GoBuf)

type Parentheses

type Parentheses struct {
	BaseNode
	Value Node
}

Parentheses is an expression in parentheses.

func (*Parentheses) CollectVarRefs

func (n *Parentheses) CollectVarRefs(reactive map[string]bool) []string

func (*Parentheses) WriteGoCode

func (n *Parentheses) WriteGoCode(buf *gobuf.GoBuf)

type RawExpression

type RawExpression struct {
	BaseNode
	Value Node
	// Source is the trimmed text between {{$ and }}.
	Source string
	// BindingKey is set for a live value; the value is then wrapped in <span data-ssr-bind="KEY">.
	BindingKey string
}

RawExpression is a {{$ }} value. Its value must be a web.SafeHTML.

func (*RawExpression) CollectVarRefs

func (n *RawExpression) CollectVarRefs(reactive map[string]bool) []string

func (*RawExpression) WriteGoCode

func (n *RawExpression) WriteGoCode(buf *gobuf.GoBuf)

func (*RawExpression) WriteInnerGoCode

func (n *RawExpression) WriteInnerGoCode(buf *gobuf.GoBuf)

WriteInnerGoCode writes the value without the live-value wrapper.

type SsrAssets

type SsrAssets struct {
	BaseNode
}

SsrAssets is <ssr:assets/>, where the page's script and style tags are written.

func (*SsrAssets) CollectVarRefs

func (n *SsrAssets) CollectVarRefs(_ map[string]bool) []string

func (*SsrAssets) WriteGoCode

func (n *SsrAssets) WriteGoCode(buf *gobuf.GoBuf)

type SsrCondition

type SsrCondition struct {
	BaseNode
	Conditions []SsrConditionData
	ElseBody   Node
	// BlockKey is set when a condition or a branch is live; the output is then wrapped in
	// <ssr-block data-ssr-bind="KEY"> and re-rendered whole.
	BlockKey string
}

SsrCondition is a chain of elements with ssr:if, ssr:else-if and ssr:else.

func (*SsrCondition) CollectVarRefs

func (n *SsrCondition) CollectVarRefs(reactive map[string]bool) []string

func (*SsrCondition) WriteGoCode

func (n *SsrCondition) WriteGoCode(buf *gobuf.GoBuf)

func (*SsrCondition) WriteInnerGoCode

func (n *SsrCondition) WriteInnerGoCode(buf *gobuf.GoBuf)

WriteInnerGoCode writes the branches without the live-block wrapper.

type SsrConditionData

type SsrConditionData struct {
	BaseNode
	Condition Node
	Body      Node
}

SsrConditionData is one ssr:if or ssr:else-if branch.

type SsrContent

type SsrContent struct {
	BaseNode
	Default string
}

SsrContent is <ssr:content/>, where the child page is written.

func (*SsrContent) CollectVarRefs

func (n *SsrContent) CollectVarRefs(_ map[string]bool) []string

func (*SsrContent) WriteGoCode

func (n *SsrContent) WriteGoCode(buf *gobuf.GoBuf)

type SsrForm

type SsrForm struct {
	BaseNode
	Name           string
	DPCtxFieldName string
	EncType        string
	Attributes     []HtmlAttribute
	Children       []Node
}

SsrForm is an <ssr:form>. It posts to its own page with the form ID and the CSRF token in hidden fields.

func (*SsrForm) AddChildren

func (n *SsrForm) AddChildren(children ...Node)

func (*SsrForm) CollectVarRefs

func (n *SsrForm) CollectVarRefs(_ map[string]bool) []string

CollectVarRefs returns [] — form fields are not reactive.

func (*SsrForm) LastChild

func (n *SsrForm) LastChild() Node

func (*SsrForm) PopChild

func (n *SsrForm) PopChild()

func (*SsrForm) WriteGoCode

func (n *SsrForm) WriteGoCode(buf *gobuf.GoBuf)

type SsrInput

type SsrInput struct {
	BaseNode
	Name          string
	FormFieldName string
	Type          string
	// Value is the fixed value of a radio or checkbox input; GoValue is the same value as a
	// Go literal of the field's gotype.
	Value      string
	GoValue    string
	Multiple   bool
	Attributes []HtmlAttribute
}

SsrInput is an <ssr:input> form field.

func (*SsrInput) CollectVarRefs

func (n *SsrInput) CollectVarRefs(_ map[string]bool) []string

CollectVarRefs returns [] — form fields are not reactive.

func (*SsrInput) WriteGoCode

func (n *SsrInput) WriteGoCode(buf *gobuf.GoBuf)

type SsrJSON

type SsrJSON struct {
	BaseNode
	Name  string
	Value Node
}

SsrJSON renders a value as JSON in a <script type="application/json"> element with id Name, so page scripts can read it without inline code.

func (*SsrJSON) CollectVarRefs

func (n *SsrJSON) CollectVarRefs(reactive map[string]bool) []string

func (*SsrJSON) WriteGoCode

func (n *SsrJSON) WriteGoCode(buf *gobuf.GoBuf)

type SsrSelect

type SsrSelect struct {
	BaseNode
	Name          string
	GoType        string
	FormFieldName string
	Attributes    []HtmlAttribute
	Multiple      bool
}

SsrSelect is an <ssr:select> form field; its options are set by the page's code.

func (*SsrSelect) CollectVarRefs

func (n *SsrSelect) CollectVarRefs(_ map[string]bool) []string

CollectVarRefs returns [] — form fields are not reactive.

func (*SsrSelect) WriteGoCode

func (n *SsrSelect) WriteGoCode(buf *gobuf.GoBuf)

type SsrTextarea

type SsrTextarea struct {
	BaseNode
	Name          string
	FormFieldName string
	Attributes    []HtmlAttribute
}

SsrTextarea is an <ssr:textarea> form field.

func (*SsrTextarea) CollectVarRefs

func (n *SsrTextarea) CollectVarRefs(_ map[string]bool) []string

CollectVarRefs returns [] — form fields are not reactive.

func (*SsrTextarea) WriteGoCode

func (n *SsrTextarea) WriteGoCode(buf *gobuf.GoBuf)

type String

type String struct {
	BaseNode
	Text string
}

String is a string literal. Text is the literal as Go source.

func (*String) CollectVarRefs

func (n *String) CollectVarRefs(_ map[string]bool) []string

func (*String) WriteGoCode

func (n *String) WriteGoCode(buf *gobuf.GoBuf)

type StructField

type StructField struct {
	BaseNode
	Expr      Node
	FieldName string
}

StructField is a selector, a.B.

func (*StructField) CollectVarRefs

func (n *StructField) CollectVarRefs(reactive map[string]bool) []string

CollectVarRefs returns the variables of the expression the field is read from.

func (*StructField) WriteGoCode

func (n *StructField) WriteGoCode(buf *gobuf.GoBuf)

type TernaryIf

type TernaryIf struct {
	BaseNode
	Cond Node
	T    Node
	F    Node
}

TernaryIf is "cond ? a : b".

func (*TernaryIf) CollectVarRefs

func (n *TernaryIf) CollectVarRefs(reactive map[string]bool) []string

func (*TernaryIf) WriteGoCode

func (n *TernaryIf) WriteGoCode(buf *gobuf.GoBuf)

type Text

type Text struct {
	BaseNode
	Text string
}

Text is literal text, written HTML-escaped.

func (*Text) CollectVarRefs

func (n *Text) CollectVarRefs(_ map[string]bool) []string

func (*Text) WriteGoCode

func (n *Text) WriteGoCode(buf *gobuf.GoBuf)

type Variable

type Variable struct {
	BaseNode
	Name string
}

Variable is a name.

func (*Variable) CollectVarRefs

func (n *Variable) CollectVarRefs(reactive map[string]bool) []string

func (*Variable) WriteGoCode

func (n *Variable) WriteGoCode(buf *gobuf.GoBuf)

type WithChildren

type WithChildren interface {
	Node
	AddChildren(children ...Node)
	LastChild() Node
	PopChild()
}

WithChildren is a node that holds child nodes.

Jump to

Keyboard shortcuts

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