view

package
v0.23.1 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package view renders html/template files to a buffer before committing an HTTP response. Templates are standard-library templates with no hidden DSL.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GoSource

func GoSource(packageName string, compiled []CompiledTemplate) (string, error)

GoSource emits deterministic, gofmt'd application-owned source containing compiled views and their source maps.

Types

type CompiledTemplate

type CompiledTemplate struct {
	Name     string
	Source   string
	Mappings []SourceMapping
}

CompiledTemplate is canonical html/template source produced from a GoForge template. Component files are expanded into these values at compile time.

func CompileForge

func CompileForge(files fs.FS, patterns ...string) ([]CompiledTemplate, error)

CompileForge resolves GoForge structure into ordinary html/template source. With no patterns it recursively compiles every *.forge.html file.

type Engine

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

func Parse

func Parse(files fs.FS, functions template.FuncMap, patterns ...string) (*Engine, error)

func ParseCompiled

func ParseCompiled(compiled []CompiledTemplate, functions template.FuncMap) (*Engine, error)

ParseCompiled parses compiler output using html/template contextual escaping.

func ParseForge

func ParseForge(files fs.FS, functions template.FuncMap, patterns ...string) (*Engine, error)

ParseForge is a development convenience. Production applications should parse embedded compiler output with ParseCompiled.

func (*Engine) Render

func (engine *Engine) Render(response http.ResponseWriter, status int, name string, data any) error

func (*Engine) Templates

func (engine *Engine) Templates() *template.Template

Templates exposes the underlying templates for configuration before serving requests. Callers must not modify them concurrently with Render.

type Form

type Form struct {
	CSRFToken        string
	OldValues        map[string]string
	ValidationErrors map[string][]string
}

Form is explicit render state for Forge form directives. OldValues records submitted fields, including submitted empty strings. ValidationErrors holds already-safe application messages which html/template still escapes.

func (Form) Errors

func (form Form) Errors(name string) []string

Errors returns all validation messages for a field.

func (Form) Old

func (form Form) Old(name string, fallback ...any) any

Old returns a submitted value when present, including an empty value. The optional fallback is used only when the field was not submitted.

type SourceMapping

type SourceMapping struct {
	Start       int
	End         int
	SourceStart int
	Path        string
	Line        int
	Column      int
	Synthetic   bool
	Context     []string
}

SourceMapping connects generated html/template bytes to application source.

Jump to

Keyboard shortcuts

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