Documentation ¶
Index ¶
- Variables
- func ServiceProvider(loader Loader, funcs ...OptionFunc) service.Provider
- func WithFlashes(w http.ResponseWriter, r *http.Request, container *service.Container) template.DataExtFunc
- type DirectoryLoader
- type Loader
- type OptionFunc
- type Options
- type TemplateService
- func (t *TemplateService) AddBlock(name string, blockContent string)
- func (t *TemplateService) Load() error
- func (t *TemplateService) LoadLayout(name string, layoutContent string) error
- func (t *TemplateService) Render(w io.Writer, layoutName string, data interface{}) error
- func (t *TemplateService) RenderPage(w http.ResponseWriter, templateName string, data interface{}) error
Constants ¶
This section is empty.
Variables ¶
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 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