templates

package
v0.0.0-...-3a5708c Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2019 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package templates builds the link between Go's standard template logic and the application logic by providing an interface specialized to each template's use case.

Also, it implements a generic structures for how to load, watch and render templates from different sources.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EditorRenderer

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

EditorRenderer renders the edit UI from a go HTML template. Always check the Err() result!

func NewEditorRenderer

func NewEditorRenderer() *EditorRenderer

func (EditorRenderer) Load

func (r EditorRenderer) Load(l Loader) error

func (EditorRenderer) LoadAndWatch

func (r EditorRenderer) LoadAndWatch(l Loader) error

func (EditorRenderer) Render

func (r EditorRenderer) Render(writer io.Writer, url *url.URL, content string,
	mimeType string, edit bool) error

type FilesystemLoader

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

FilesystemLoader is a Loader that loads templates from the filesystem. It supports watching the filesystem for changes in template files.

func NewFilesystemLoader

func NewFilesystemLoader(root gopath.GoPath) *FilesystemLoader

NewFilesystemLoader creates a new instance with templates located in the given root path.

func (*FilesystemLoader) Close

func (l *FilesystemLoader) Close() error

func (*FilesystemLoader) LoadHtmlTemplate

func (l *FilesystemLoader) LoadHtmlTemplate(name string) (*template.Template, error)

func (*FilesystemLoader) LoadResource

func (l *FilesystemLoader) LoadResource(name string) (io.ReadCloser, error)

func (*FilesystemLoader) WatchHtmlTemplate

func (l *FilesystemLoader) WatchHtmlTemplate(name string) <-chan *template.Template

type Loader

type Loader interface {
	// LoadResource loads a resource from the template source as ReadCloser.
	LoadResource(name string) (io.ReadCloser, error)

	// LoadHtmlTemplate loads the template with the given name.
	LoadHtmlTemplate(name string) (*template.Template, error)

	// WatchHtmlTemplate returns a chan over which changed Templates might be
	// received, if supported by this loader.
	// Any errors during loading the new templates will be logged.
	WatchHtmlTemplate(name string) <-chan *template.Template

	// Close frees resources bound by this loader, esp. in case of watching.
	Close() error
}

Loader encapsulates how to retrieve a template by its name. Concrete implementations could load data packaged with the binary, files from filesystem or even network resources. Caching is not the duty of a Loader.

type StaticLoader

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

StaticLoader is a Loader that loads templates from data packaged with the application binary.

func NewStaticLoader

func NewStaticLoader() *StaticLoader

NewStaticLoader creates a new instance

func NewStaticLoaderFromWorkingDirectory

func NewStaticLoaderFromWorkingDirectory() *StaticLoader

NewStaticLoaderFromWorkingDirectory is to be used for development purposes and loads the templates from the application's source directory.

func (*StaticLoader) Close

func (l *StaticLoader) Close() error

Close does nothing.

func (*StaticLoader) LoadHtmlTemplate

func (l *StaticLoader) LoadHtmlTemplate(name string) (*template.Template, error)

func (*StaticLoader) LoadResource

func (l *StaticLoader) LoadResource(name string) (io.ReadCloser, error)

func (*StaticLoader) WatchHtmlTemplate

func (l *StaticLoader) WatchHtmlTemplate(name string) <-chan *template.Template

WatchHtmlTemplate returns a channel that will never receive anything.

func (*StaticLoader) WriteAllTemplates

func (l *StaticLoader) WriteAllTemplates(targetDir gopath.GoPath) error

type TemplateDeliverer

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

func NewTemplateDeliverer

func NewTemplateDeliverer(l Loader) *TemplateDeliverer

func (*TemplateDeliverer) ServeHTTP

func (e *TemplateDeliverer) ServeHTTP(writer http.ResponseWriter, request *http.Request)

type ViewerRenderer

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

func NewViewerRenderer

func NewViewerRenderer() *ViewerRenderer

func (ViewerRenderer) Load

func (r ViewerRenderer) Load(l Loader) error

func (ViewerRenderer) LoadAndWatch

func (r ViewerRenderer) LoadAndWatch(l Loader) error

func (ViewerRenderer) Render

func (r ViewerRenderer) Render(writer io.Writer, url *url.URL, htmlContent string) error

Jump to

Keyboard shortcuts

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