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 ¶
- type EditorRenderer
- type FilesystemLoader
- type Loader
- type StaticLoader
- func (l *StaticLoader) Close() error
- func (l *StaticLoader) LoadHtmlTemplate(name string) (*template.Template, error)
- func (l *StaticLoader) LoadResource(name string) (io.ReadCloser, error)
- func (l *StaticLoader) WatchHtmlTemplate(name string) <-chan *template.Template
- func (l *StaticLoader) WriteAllTemplates(targetDir gopath.GoPath) error
- type TemplateDeliverer
- type ViewerRenderer
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) LoadAndWatch ¶
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 NewStaticLoaderFromWorkingDirectory ¶
func NewStaticLoaderFromWorkingDirectory() *StaticLoader
NewStaticLoaderFromWorkingDirectory is to be used for development purposes and loads the templates from the application's source directory.
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