view

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2026 License: MPL-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package view parses and renders the first subset of view {} markup.

Index

Constants

View Source
const (
	ContractReferenceCommand = viewanalysis.ContractReferenceCommand
	ContractReferenceQuery   = viewanalysis.ContractReferenceQuery
)

Variables

This section is empty.

Functions

func ActionFormFields

func ActionFormFields(source string) (map[string][]string, error)

ActionFormFields returns direct literal HTML control names grouped by g:post action name. Component-hidden controls are intentionally not inferred in this first decoder slice.

func ActionFormSchema

func ActionFormSchema(source string) (map[string][]ActionFormField, error)

ActionFormSchema returns direct literal HTML controls grouped by g:post action name. Duplicate field names are merged, and Required is true if any matching direct control is required.

func ActionFormSchemaFromNodes added in v0.5.0

func ActionFormSchemaFromNodes(nodes []Node) (map[string][]ActionFormField, error)

ActionFormSchemaFromNodes returns direct literal HTML controls grouped by g:post action name from an already-parsed view fragment.

func Canonical

func Canonical(source string) (string, error)

Canonical returns a deterministic AST-backed representation of a view body.

func ComponentReferences

func ComponentReferences(source string) ([]string, error)

ComponentReferences returns unique component names directly referenced by a view markup fragment.

func ComponentReferencesFromNodes added in v0.5.0

func ComponentReferencesFromNodes(nodes []Node) []string

ComponentReferencesFromNodes returns unique component names directly referenced by an already-parsed view fragment.

func DOMEventSymbols added in v0.1.5

func DOMEventSymbols() map[string]clientlang.ValueType

DOMEventSymbols returns the compiler-owned scalar DOM event scope exposed to g:on:* expressions.

func IslandExpressionFields

func IslandExpressionFields(expr string) []string

IslandExpressionFields returns field references in a supported island event expression.

func IslandRefStatement

func IslandRefStatement(expr string) (string, bool)

IslandRefStatement reports whether expr is a safe DOM ref method call.

func ParamReferences

func ParamReferences(source string) ([]string, error)

func ParamReferencesFromNodes added in v0.5.0

func ParamReferencesFromNodes(nodes []Node) []string

ParamReferencesFromNodes returns unique param("name") route-param references directly referenced by an already-parsed view fragment.

func RenderNodesWithOptions added in v0.5.0

func RenderNodesWithOptions(nodes []Node, components map[string]Component, data map[string]string, options Options) (string, error)

RenderNodesWithOptions renders an already-parsed view fragment with component support, interpolation data, and page-scoped action endpoints.

func RenderSPA added in v0.1.5

func RenderSPA(source string) (string, error)

RenderSPA renders a view markup fragment with escaped text and attrs.

func RenderWithComponents

func RenderWithComponents(source string, components map[string]Component) (string, error)

RenderWithComponents renders a view markup fragment with component support.

func RenderWithData

func RenderWithData(source string, components map[string]Component, data map[string]string) (string, error)

RenderWithData renders a view markup fragment with component support and string interpolation data.

func RenderWithOptions

func RenderWithOptions(source string, components map[string]Component, data map[string]string, options Options) (string, error)

RenderWithOptions renders a view markup fragment with component support, interpolation data, and page-scoped action endpoints.

func SupportedDirectiveNames added in v0.3.0

func SupportedDirectiveNames() []string

SupportedDirectiveNames returns the sorted closed set of exact-name g: directives owned by the current view contract (excluding the g:on:* event family and the g:message:* rules, which are validated separately). It is the source of truth cross-checked against docs/language/stability.md.

func ValidateClassToggleExpressionTyped

func ValidateClassToggleExpressionTyped(name, expr string, symbols map[string]clientlang.ValueType) error

ValidateClassToggleExpressionTyped validates a class:name directive expression.

func ValidateIslandBoolExpression

func ValidateIslandBoolExpression(expr string, fields map[string]bool) error

ValidateIslandBoolExpression validates a g:if-style bool expression.

func ValidateIslandBoolExpressionTyped

func ValidateIslandBoolExpressionTyped(expr string, symbols map[string]clientlang.ValueType) error

ValidateIslandBoolExpressionTyped validates a g:if-style bool expression with scalar type information.

func ValidateIslandClientStatementTyped

func ValidateIslandClientStatementTyped(expr string, writeSymbols map[string]clientlang.ValueType, readSymbols map[string]clientlang.ValueType, refs map[string]clientlang.Ref) error

ValidateIslandClientStatementTyped validates a client statement that may mutate state or call a safe DOM ref method.

func ValidateIslandClientStatementTypedWithEvents

func ValidateIslandClientStatementTypedWithEvents(expr string, writeSymbols map[string]clientlang.ValueType, readSymbols map[string]clientlang.ValueType, refs map[string]clientlang.Ref, helpers map[string]clientlang.ExprFunction, emits map[string]clientlang.Emit) error

ValidateIslandClientStatementTypedWithEvents validates a client statement that may mutate state, call a safe DOM ref method, read helper functions, or dispatch declared component events.

func ValidateIslandClientStatementTypedWithFunctions

func ValidateIslandClientStatementTypedWithFunctions(expr string, writeSymbols map[string]clientlang.ValueType, readSymbols map[string]clientlang.ValueType, refs map[string]clientlang.Ref, helpers map[string]clientlang.ExprFunction) error

ValidateIslandClientStatementTypedWithFunctions validates a client statement that may mutate state, call a safe DOM ref method, or read helper functions.

func ValidateIslandClientStatementsTyped

func ValidateIslandClientStatementsTyped(statements []string, writeSymbols map[string]clientlang.ValueType, readSymbols map[string]clientlang.ValueType, refs map[string]clientlang.Ref) (map[string]bool, error)

ValidateIslandClientStatementsTyped validates an ordered client statement block. Local variables declared with let are visible only to later statements in the same block.

func ValidateIslandClientStatementsTypedWithEvents

func ValidateIslandClientStatementsTypedWithEvents(statements []string, writeSymbols map[string]clientlang.ValueType, readSymbols map[string]clientlang.ValueType, refs map[string]clientlang.Ref, helpers map[string]clientlang.ExprFunction, async bool, emits map[string]clientlang.Emit) (map[string]bool, error)

ValidateIslandClientStatementsTypedWithEvents validates an ordered client statement block with optional component event dispatch support.

func ValidateIslandClientStatementsTypedWithFunctions

func ValidateIslandClientStatementsTypedWithFunctions(statements []string, writeSymbols map[string]clientlang.ValueType, readSymbols map[string]clientlang.ValueType, refs map[string]clientlang.Ref, helpers map[string]clientlang.ExprFunction) (map[string]bool, error)

ValidateIslandClientStatementsTypedWithFunctions validates an ordered client statement block. Local variables declared with let are visible only to later statements in the same block.

func ValidateIslandClientStatementsTypedWithOptions

func ValidateIslandClientStatementsTypedWithOptions(statements []string, writeSymbols map[string]clientlang.ValueType, readSymbols map[string]clientlang.ValueType, refs map[string]clientlang.Ref, helpers map[string]clientlang.ExprFunction, async bool) (map[string]bool, error)

ValidateIslandClientStatementsTypedWithOptions validates an ordered client statement block with the same local-variable rules as ValidateIslandClientStatementsTypedWithFunctions. Async blocks may use compiler-owned await expressions.

func ValidateIslandEventExpression

func ValidateIslandEventExpression(expr string, fields map[string]bool, handlers ...map[string]clientlang.Handler) error

ValidateIslandEventExpression validates a client event expression. When fields is non-nil, every referenced field must exist.

func ValidateIslandEventExpressionTyped

func ValidateIslandEventExpressionTyped(expr string, readSymbols map[string]clientlang.ValueType, writeSymbols map[string]clientlang.ValueType, handlers map[string]clientlang.Handler) error

ValidateIslandEventExpressionTyped validates an event expression with scalar type information.

func ValidateIslandEventExpressionTypedWithEvents

func ValidateIslandEventExpressionTypedWithEvents(expr string, readSymbols map[string]clientlang.ValueType, writeSymbols map[string]clientlang.ValueType, handlers map[string]clientlang.Handler, helpers map[string]clientlang.ExprFunction, emits map[string]clientlang.Emit) error

ValidateIslandEventExpressionTypedWithEvents validates an event expression, including component event dispatch statements.

func ValidateIslandEventExpressionTypedWithFunctions

func ValidateIslandEventExpressionTypedWithFunctions(expr string, readSymbols map[string]clientlang.ValueType, writeSymbols map[string]clientlang.ValueType, handlers map[string]clientlang.Handler, helpers map[string]clientlang.ExprFunction) error

ValidateIslandEventExpressionTypedWithFunctions validates an event expression with scalar type information and return-valued helper functions.

func ValidateIslandStateStatement

func ValidateIslandStateStatement(expr string, writeFields map[string]bool, readFields map[string]bool) error

ValidateIslandStateStatement validates a client statement that may write only writeFields and may read readFields plus scalar literals.

func ValidateIslandStateStatementTyped

func ValidateIslandStateStatementTyped(expr string, writeSymbols map[string]clientlang.ValueType, readSymbols map[string]clientlang.ValueType) error

ValidateIslandStateStatementTyped validates a state statement with scalar type information.

func ValidateIslandStateStatementTypedWithFunctions

func ValidateIslandStateStatementTypedWithFunctions(expr string, writeSymbols map[string]clientlang.ValueType, readSymbols map[string]clientlang.ValueType, helpers map[string]clientlang.ExprFunction) error

ValidateIslandStateStatementTypedWithFunctions validates a state statement with scalar type information and return-valued helper functions.

func ValidateReactiveAttrExpressionTyped

func ValidateReactiveAttrExpressionTyped(name, expr string, symbols map[string]clientlang.ValueType) error

ValidateReactiveAttrExpressionTyped validates a first-slice reactive attribute expression.

func ValidateStyleBindingExpressionTyped

func ValidateStyleBindingExpressionTyped(name, expr string, symbols map[string]clientlang.ValueType) error

ValidateStyleBindingExpressionTyped validates a style:name directive expression.

Types

type ActionFormField

type ActionFormField struct {
	Name             string
	Required         bool
	RequiredMessage  string
	MinLength        int
	MinLengthMessage string
	MaxLength        int
	MaxLengthMessage string
	Pattern          string
	PatternMessage   string
}

ActionFormField describes one direct literal form field for a g:post action.

type ActionInputField added in v0.5.0

type ActionInputField struct {
	FormName string
	Type     string
}

ActionInputField describes Go action input metadata available while rendering literal controls inside a g:post form.

type Attr

type Attr = viewmodel.Attr

type CommandReference added in v0.1.5

type CommandReference = viewanalysis.CommandReference

func CommandReferences added in v0.1.5

func CommandReferences(source string) ([]CommandReference, error)

CommandReferences returns package-qualified command references declared by g:command on direct form elements in a view fragment.

func CommandReferencesFromNodes added in v0.5.0

func CommandReferencesFromNodes(nodes []Node) ([]CommandReference, error)

CommandReferencesFromNodes returns package-qualified command references declared by g:command on direct form elements in an already-parsed view fragment.

type Component

type Component = viewmodel.Component

type ComponentCall

type ComponentCall = viewmodel.ComponentCall

type ComponentCallUsage

type ComponentCallUsage = viewanalysis.ComponentCallUsage

func ComponentCallUsages

func ComponentCallUsages(source string) ([]ComponentCallUsage, error)

ComponentCallUsages returns component calls with optional g:island metadata.

func ComponentCallUsagesFromNodes added in v0.5.0

func ComponentCallUsagesFromNodes(nodes []Node) ([]ComponentCallUsage, error)

ComponentCallUsagesFromNodes returns component calls with optional g:island metadata from an already-parsed view fragment.

type ComponentIslandUsage

type ComponentIslandUsage = viewanalysis.ComponentIslandUsage

func ComponentIslandUsages

func ComponentIslandUsages(source string) ([]ComponentIslandUsage, error)

ComponentIslandUsages returns component calls that explicitly set g:island.

func ComponentIslandUsagesFromNodes added in v0.5.0

func ComponentIslandUsagesFromNodes(nodes []Node) ([]ComponentIslandUsage, error)

ComponentIslandUsagesFromNodes returns component calls that explicitly set g:island in an already-parsed view fragment.

type ComponentReference added in v0.3.0

type ComponentReference = viewanalysis.ComponentReference

func ComponentReferenceSpans added in v0.3.0

func ComponentReferenceSpans(source string) ([]ComponentReference, error)

ComponentReferenceSpans returns component calls directly referenced by a view markup fragment, preserving source offsets for diagnostics.

func ComponentReferenceSpansFromNodes added in v0.5.0

func ComponentReferenceSpansFromNodes(nodes []Node) []ComponentReference

ComponentReferenceSpansFromNodes returns component calls from an already- parsed view fragment, preserving source offsets for diagnostics.

type ContractReference added in v0.1.5

type ContractReference = viewanalysis.ContractReference

func ContractReferences added in v0.1.5

func ContractReferences(source string) ([]ContractReference, error)

ContractReferences returns package-qualified command and query references declared by GOWDK view directives.

func ContractReferencesFromNodes added in v0.5.0

func ContractReferencesFromNodes(nodes []Node) ([]ContractReference, error)

ContractReferencesFromNodes returns package-qualified command and query references declared by GOWDK view directives in an already-parsed view fragment.

type ContractReferenceKind added in v0.1.5

type ContractReferenceKind = viewanalysis.ContractReferenceKind

type Dependencies

type Dependencies = viewanalysis.Dependencies

func ViewDependencies

func ViewDependencies(source string) (Dependencies, error)

ViewDependencies returns direct literal asset and style references from a view markup fragment. Interpolated and external URLs are not reported.

func ViewDependenciesFromNodes added in v0.5.0

func ViewDependenciesFromNodes(nodes []Node) Dependencies

ViewDependenciesFromNodes returns direct literal asset and style references from an already-parsed view fragment.

type Element

type Element = viewmodel.Element

type EventDirective

type EventDirective struct {
	Event      string
	Prevent    bool
	Stop       bool
	Once       bool
	Capture    bool
	DebounceMS int
	ThrottleMS int
}

EventDirective is a parsed g:on:<event>[.<modifier>] directive.

func ParseEventDirective

func ParseEventDirective(name string) (EventDirective, error)

ParseEventDirective validates and splits a g:on directive name.

func (EventDirective) RuntimeOptions

func (directive EventDirective) RuntimeOptions() string

RuntimeOptions returns the compact modifier string emitted into HTML.

type ForDirective

type ForDirective = viewparse.ForDirective

func ParseForDirective

func ParseForDirective(source string) (ForDirective, error)

ParseForDirective parses a g:for value such as "item in Items" or "item, i in Items".

type InlineScript added in v0.2.3

type InlineScript = viewmodel.InlineScript

type Node

type Node = viewmodel.Node

func Parse

func Parse(source string) ([]Node, error)

Parse parses a view markup fragment.

type Options

type Options struct {
	Actions           map[string]string
	ActionInputFields map[string][]ActionInputField
	Package           string
	Uses              map[string]string
	// Tainted names interpolation values that carry request-time,
	// attacker-influenceable data (e.g. SSR load {} fields). Tainted values are
	// rejected in URL-bearing, event-handler, style, and srcdoc attributes the
	// same way route params are, so they cannot smuggle a javascript:/data: URL
	// past HTML-text escaping.
	Tainted                map[string]bool
	RealtimeEventTypeNames map[string]string
	QueryTypeNames         map[string]string
}

Options configures view rendering.

type QueryReference added in v0.1.5

type QueryReference = viewanalysis.QueryReference

func QueryReferences added in v0.1.5

func QueryReferences(source string) ([]QueryReference, error)

QueryReferences returns package-qualified query references declared by g:query on direct HTML elements in a view fragment.

func QueryReferencesFromNodes added in v0.5.0

func QueryReferencesFromNodes(nodes []Node) ([]QueryReference, error)

QueryReferencesFromNodes returns package-qualified query references declared by g:query on direct HTML elements in an already-parsed view fragment.

type StatementValidationError

type StatementValidationError = clientlang.StatementValidationError

StatementValidationError identifies the statement index that failed within a client statement block.

type SubscriptionReference added in v0.5.0

type SubscriptionReference = viewanalysis.SubscriptionReference

func SubscriptionReferences added in v0.5.0

func SubscriptionReferences(source string) ([]SubscriptionReference, error)

SubscriptionReferences returns package-qualified presentation-event references declared by g:subscribe on query-owned elements.

func SubscriptionReferencesFromNodes added in v0.5.0

func SubscriptionReferencesFromNodes(nodes []Node) ([]SubscriptionReference, error)

SubscriptionReferencesFromNodes returns package-qualified presentation-event references declared by g:subscribe on query-owned elements in an already-parsed view fragment.

type Text

type Text = viewmodel.Text

Jump to

Keyboard shortcuts

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