Documentation
¶
Overview ¶
Package template parses page templates (index.html) into nodes that write Go code.
Index ¶
- Constants
- func Fix(code string) string
- type Access
- type Call
- type Form
- type FormElement
- type FormElementType
- type NodesStack
- type SsrBindRef
- type Template
- func (t *Template) Access() *Access
- func (t *Template) AnnotateBindings(reactive map[string]bool, keyer func(refs []string, exprSrc string) string, ...) map[string][]string
- func (t *Template) Calls() []Call
- func (t *Template) CollectAllVarRefs(reactive map[string]bool) []string
- func (t *Template) CollectReactiveNodes() map[string]node.Node
- func (t *Template) GetContentNode() *node.SsrContent
- func (t *Template) GetForms() []*Form
- func (t *Template) GetNodes() []node.Node
- func (t *Template) GetSsrBindRefs() []SsrBindRef
- func (t *Template) GetVariables() []Variable
- func (t *Template) HasAssets() bool
- func (t *Template) MarkBoundElements(routeKey string)
- func (t *Template) WriteGoCode(buf *gobuf.GoBuf)
- type Variable
Constants ¶
const AND = 57359
const EQ = 57354
const EXPR_END = 57348
const EXPR_START = 57347
const GE = 57356
const IDENTIFIER = 57350
const IN = 57353
const LE = 57357
const NE = 57355
const NOT = 57360
const NUMBER = 57352
const OR = 57358
const RAW_EXPR_START = 57349
const STRING = 57351
const TEXT = 57346
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Access ¶
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 ¶
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) 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 ¶
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) 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) CollectAllVarRefs ¶
CollectAllVarRefs returns the reactive variables the template refers to anywhere.
func (*Template) CollectReactiveNodes ¶
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) GetSsrBindRefs ¶
func (t *Template) GetSsrBindRefs() []SsrBindRef
GetSsrBindRefs returns the ssr:bind attributes of native inputs.
func (*Template) GetVariables ¶
GetVariables returns the <ssr:var> declarations sorted by name.
func (*Template) MarkBoundElements ¶
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 ¶
WriteGoCode writes the Go code that renders the template.