render

package
v0.0.0-...-5ac63d6 Latest Latest
Warning

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

Go to latest
Published: May 22, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ViewSubdirectoryName = "views"
)

ViewSubdirectoryName is the standard subdirectory to be used when adding namespaced templates to the renderer.

Variables

This section is empty.

Functions

This section is empty.

Types

type NamespaceFS

type NamespaceFS map[string]fs.FS

NamespaceFS is an implementation of the `fs.FS`, `fs.GlobFS` and `fs.ReadFileFS` interfaces that makes a map of namespaced filesystems look as if they were a single filesystem. This is used to keep the templates from different sub-paths separate, while still being able to access them from a single component.

func (NamespaceFS) AddNamespace

func (t NamespaceFS) AddNamespace(namespace, subdir string, files fs.FS) error

AddNamespace adds the subdir of the passed files under the namespace. Subdir must exist.

func (NamespaceFS) Glob

func (t NamespaceFS) Glob(pattern string) ([]string, error)

Glob implements the fs.GlobFS interface for the namespaced subdirectories.

func (NamespaceFS) Open

func (t NamespaceFS) Open(path string) (fs.File, error)

Open implements the fs.FS interface for the namespaced subdirectories.

func (NamespaceFS) ReadFile

func (t NamespaceFS) ReadFile(path string) ([]byte, error)

ReadFile implements the fs.ReadFileFS interface for the namespaced subdirectories.

type Renderer

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

Renderer implements the necessary magic to render Hotwire Turbo frames and streams. Implements the `echo.Renderer` interface.

func New

func New(rootPage, rootPath string) (*Renderer, error)

New setups a new template renderer. rootPage is the Hotwire wrapping page that should be rendered,

func (*Renderer) AddFS

func (r *Renderer) AddFS(namespace string, fsys fs.FS, isGlobal bool) error

AddFS adds the templates from the passed filesystem to the template map. The key is the namespace, which is generally the name of the domain providing the views. If isGlobal is true, the namespace is added to the global paths and is accessible from any request for rendering. Global template files should have distinct names, as otherwise it can not be guaranteed which template is chosen.

func (*Renderer) AddGlobal

func (r *Renderer) AddGlobal(placeholder string, value any)

AddGlobal allows you to add a specific string replacement to the template renderer that will return a string only known at setup-time for a specific placeholder template, i.e. {{ global "basepath" }}

func (*Renderer) AddNotFound

func (r *Renderer) AddNotFound(notfoundPath string)

func (*Renderer) BasePath

func (r *Renderer) BasePath() string

func (*Renderer) BasePathHandler

func (r *Renderer) BasePathHandler() http.HandlerFunc

func (*Renderer) Render

func (r *Renderer) Render(_ context.Context, w http.ResponseWriter, name string, data any) error

Render finds the correct template in the template map based on name and namespace. It also automagically renders the correct template based on the passed template name and request or template name settings.

Jump to

Keyboard shortcuts

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