html

package
v0.0.0-...-4a8add1 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2023 License: AGPL-3.0 Imports: 15 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrLayoutNotFound = errors.New("layout not found")
)

Functions

func ServiceProvider

func ServiceProvider(loader Loader, funcs ...OptionFunc) service.Provider

ServiceProvider returns a service.Provider for the the HTML template service implementation

func WithFlashes

func WithFlashes(w http.ResponseWriter, r *http.Request, container *service.Container) template.DataExtFunc

WithFlashes extends the template's data with session's flash messages

Types

type DirectoryLoader

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

func NewDirectoryLoader

func NewDirectoryLoader(rootDir string) *DirectoryLoader

func (*DirectoryLoader) Load

func (l *DirectoryLoader) Load(srv *TemplateService) error

type Loader

type Loader interface {
	Load(*TemplateService) error
}

type OptionFunc

type OptionFunc func(*Options)

OptionFunc configures options for the template service

func WithDefaultHelpers

func WithDefaultHelpers() OptionFunc

WithDefaultHelpers configures the template service to expose the default helpers

func WithDevMode

func WithDevMode(enabled bool) OptionFunc

WithDevMode configures the template service to use the development mode (auto reload of templates).

func WithHelper

func WithHelper(name string, fn interface{}) OptionFunc

WithHelper configures the template service to expose the default helpers

func WithPoolSize

func WithPoolSize(size int) OptionFunc

WithPoolSize configures the template service to use the given pool size

type Options

type Options struct {
	Helpers  template.FuncMap
	PoolSize int
	DevMode  bool
}

Options are configuration options for the template service

type TemplateService

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

TemplateService is a template/html based templating service

func NewTemplateService

func NewTemplateService(loader Loader, funcs ...OptionFunc) *TemplateService

NewTemplateService returns a new Service

func (*TemplateService) AddBlock

func (t *TemplateService) AddBlock(name string, blockContent string)

func (*TemplateService) Load

func (t *TemplateService) Load() error

Load parses templates via the configured template loader.

func (*TemplateService) LoadLayout

func (t *TemplateService) LoadLayout(name string, layoutContent string) error

func (*TemplateService) Render

func (t *TemplateService) Render(w io.Writer, layoutName string, data interface{}) error

Render renders a layout to the given io.Writer.

func (*TemplateService) RenderPage

func (t *TemplateService) RenderPage(w http.ResponseWriter, templateName string, data interface{}) error

RenderPage renders a template to the given http.ResponseWriter

Jump to

Keyboard shortcuts

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