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: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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
⌂ 换网址