lazyview

package module
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2024 License: BSD-3-Clause Imports: 10 Imported by: 2

Documentation

Overview

Package lazyview provides a simple view rendering engine.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Engine

type Engine interface {
	Render(ctx context.Context, views *Views, w io.Writer, vars map[string]any, file string) error
}

type Options

type Options struct {
	Ctx    context.Context
	Writer io.Writer

	Variables map[string]any

	// Content represents the view content. If defined, Action and Partial are ignored as only the layout is rendred
	Content string

	// Action to render
	Action string

	// Partial to render. If Action is defined, this is ignored.
	Partial string

	Controller string
	Namespace  string

	// Variants allows to specified a variant preference for the view.
	// For example, a mobile variant will expect the view to be named as "index.html+mobile.tpl"
	// If empty, no variants are used.
	// To allow the default variant, use an empty string.
	Variants []string

	// Formats is the list of formats to search for. Eachone is represented as a file extension.
	// If empty, and Accept is not defined, it will default to ["html", "json"]
	Formats []string
	// Acept is the Accept header value. It is only read is Format is empty.
	// Each mime type is converted to the common file extension as defined by the mime package.
	Accept string

	// UseLayout determines if the layout should be used.
	UseLayout bool

	// Layout defines which layout should be used.
	// If empty the default layout will be used.
	Layout string
}

Options is the set of options to render a view. In case there are several views that match the search criteria, this is the list of priorities: SearchPaths > Variants > Namespace/Controller|Namespace|application > Formats

type Views

type Views struct {
	FS      fs.FS
	Engines map[string]Engine

	Helpers     map[string]any
	SearchPaths []string
}

func (*Views) Render

func (v *Views) Render(opts Options) error

func (*Views) RenderTemplate

func (v *Views) RenderTemplate(ctx context.Context, w io.Writer, vars map[string]any, file string) error

Directories

Path Synopsis
engines
raw
tpl

Jump to

Keyboard shortcuts

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