templite

package module
v0.0.0-...-15424b0 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package templite provides a simple caching mechanism for rendering text templates.

Index

Constants

This section is empty.

Variables

View Source
var ErrUncachedTemplate = errors.New("tr: template not found in cache")

ErrUncachedTemplate is returned when a requested template isn't found in the cache.

Functions

This section is empty.

Types

type Renderer

type Renderer struct {
	FS fs.FS
	// contains filtered or unexported fields
}

Renderer manages cached templates for rendering. FS is the file system used to load templates, and c is the template cache.

func NewRenderer

func NewRenderer(fs fs.FS) Renderer

NewRenderer creates a new Renderer instance.

func (Renderer) Cache

func (r Renderer) Cache(name string, patterns ...string) error

Cache parses templates from patterns and stores them under the given name. Returns an error if parsing fails.

func (Renderer) Render

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

Render writes the output of a cached template to w using the provided data. Returns ErrUncachedTemplate if the template is not found, or any execution error.

Jump to

Keyboard shortcuts

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