template

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2021 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 interface{}) (string, func() interface{})

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 string) (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 string, filesys fs.FS) func(string, bool) html.HTML

TODO(dlk):

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

Types

type Parse

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

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

func (*Parse) AddFn

func (p *Parse) AddFn(name string, fn interface{})

AddFn includes the named function in the Parse function map.

func (*Parse) Parse

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

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

type Parser

type Parser interface {
	AddFn(name string, fn interface{})
	Parse(fps ...string) (*html.Template, error)
}

Parser is the interface for parsing HTML templates with the functions provided.

func NewParser

func NewParser(fs fs.FS, opts ...ParserOptFn) Parser

NewParser constructs a Parse with the provided fs.FS and functional options.

type ParserOptFn

type ParserOptFn func(*Parse)

The ParserOptFn applies functional options to a *Parse when constructing it.

func WithFn

func WithFn(name string, fn interface{}) ParserOptFn

WithFn encloses a named function so it can be added to a *Parse's function map.

Directories

Path Synopsis
Cribbed from Mark Bates: https://www.gopherguides.com/articles/golang-1.16-io-fs-improve-test-performance
Cribbed from Mark Bates: https://www.gopherguides.com/articles/golang-1.16-io-fs-improve-test-performance

Jump to

Keyboard shortcuts

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