views

package module
v0.0.0-...-0a0ce4c Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultOptions = Options{
	RootDir:     "web/templates",
	GlobPattern: "*.gotmpl",
	FuncMaps:    []template.FuncMap{},
	FuncMapper:  defaultFuncMapper,
}

DefaultOptions provides the base options when creating a new Renderer.

Functions

This section is empty.

Types

type FuncMapper

type FuncMapper func(echo.Context) template.FuncMap

FuncMapper provides a template.FuncMap from an echo.Context.

type M

type M map[string]any

M provides a simple key-value mapping type

type Options

type Options struct {
	// The root directory of the templates.
	RootDir string
	// The glob pattern to match when initializing.
	GlobPattern string
	// Optional list of [template.FuncMap] objects.
	FuncMaps []template.FuncMap
	// Optional [FuncMapper]
	FuncMapper FuncMapper
}

Options configure the Renderer.

type Renderer

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

Renderer provides a custom implementation of echo.Renderer using template.Template.

func New

func New(opts *Options) (*Renderer, error)

New creates a new Renderer.

func (*Renderer) Render

func (r *Renderer) Render(w io.Writer, name string, data any, c echo.Context) error

Render implements echo.Renderer.

type Responder

type Responder struct{}

Responder responds to the request by rendering the template specified by view to the response body as HTML.

func (Responder) Respond

func (Responder) Respond(c echo.Context, view View) error

Respond implements Responder.

type View

type View struct {
	// The name of the template to render.
	Name string
	// The data to pass to the template.
	Data M

	// An optional status code. Defaults to [http.StatusOK].
	StatusCode int
}

View provides the response type for view resolvers.

Jump to

Keyboard shortcuts

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