template

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package template defines a generic interface for template parsers and implementations of that interface.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type IdentityParser

type IdentityParser struct{}

IdentityParser is an Parser that does no parsing and returns tempalte string unchanged.

func (IdentityParser) Cacheable

func (IdentityParser) Cacheable() bool

func (IdentityParser) Parse

func (IdentityParser) Parse(src, leftDelim, rightDelim string) (ParsedTemplate, error)

type ParsedTemplate

type ParsedTemplate interface {
	// Execute applies a parsed template to the specified data.
	Execute(data any) (string, error)
}

ParsedTemplate is an executable template.

type Parser

type Parser interface {
	// Parse parses src and returns a ParsedTemplate.
	Parse(src, leftDelim, rightDelim string) (ParsedTemplate, error)

	// Cacheable returns true if Parse returns ParsedTemplates that are always safe to cache.
	Cacheable() bool
}

Parser parses strings into executable templates.

type TextParser

type TextParser struct {
	LeftDelim  string
	RightDelim string
	Funcs      template.FuncMap
	Option     string
}

TextParser is a Parser that uses text/template.

func (*TextParser) Cacheable

func (te *TextParser) Cacheable() bool

func (*TextParser) Parse

func (te *TextParser) Parse(src, leftDelim, rightDelim string) (ParsedTemplate, error)

Jump to

Keyboard shortcuts

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