template

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2023 License: MIT Imports: 9 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoFiles = errors.New("no files provided")
)

Functions

func CurrentUser

func CurrentUser(u any) (string, func() any)

CurrentUser encloses some value representing a user. It returns "currentUser" as the name of the function for convenient passing to a template.FuncMap and returns a function returning the enclosed value when called.

func Env

func Env(e trails.Environment) (string, func() string)

Env encloses some string representing an environment. It returns "env" as the name of the function for convenient passing to a template.FuncMap and returns a function returning the enclosed value when called.

func Nonce

func Nonce() (string, func() string)

Nonce returns "nonce" as the name of the function for convenient passing to a template.FuncMap and returns a function generating a uuid.

func RootUrl

func RootUrl(u *url.URL) (string, func() string)

RootUrl encloses the *url.URL representing the base URL of the web app. It returns "rootUrl" as the name of the function for convenient passing to a template.FuncMap and returns a function returning its *url.URL.String(). If u is nil, that function will always return an empty string.

func TagPacker

func TagPacker(env trails.Environment, filesys fs.FS) func(string, bool) html.HTML

TagPacker encloses the environment and filesystem so when called executing a template, emits valid paths to JS and CSS assets.

TODO(dlk):

- configurable asset paths? - represent error states; ship files in trails generate?

Types

type Parser

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

Parse implements Parser with a focus on utilizing embedded HTML templates through fs.FS.

func NewParser

func NewParser(fses []fs.FS) *Parser

NewParser constructs a Parse with the fses and opts. The order of fs.FS in fses matters. The first reference to a filepath, starting at the beginning of fses, is cached.

func (*Parser) AddFn

func (p *Parser) AddFn(name string, fn any) *Parser

AddFn includes the named function in the Parse function map.

func (*Parser) Parse

func (p *Parser) Parse(fps ...string) (*html.Template, error)

Parse parses files found in the *Parse.fs with those functions provided previously.

Directories

Path Synopsis
Package templatetest exposes a mock fs.FS that implements basic file operations.
Package templatetest exposes a mock fs.FS that implements basic file operations.

Jump to

Keyboard shortcuts

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