mirror of
https://github.com/mickael-menu/zk
synced 2024-11-07 15:20:21 +00:00
29 lines
733 B
Go
29 lines
733 B
Go
package core
|
|
|
|
// TemplateLoader parses a given string template.
|
|
type TemplateLoader interface {
|
|
Load(template string) (Template, error)
|
|
LoadFile(path string) (Template, error)
|
|
}
|
|
|
|
// Template renders strings using a given context.
|
|
type Template interface {
|
|
Render(context interface{}) (string, error)
|
|
}
|
|
|
|
// TemplateFunc is an adapter to use a function as a Template.
|
|
type TemplateFunc func(context interface{}) (string, error)
|
|
|
|
func (f TemplateFunc) Render(context interface{}) (string, error) {
|
|
return f(context)
|
|
}
|
|
|
|
// NullTemplate is a Template returning always an empty string.
|
|
var NullTemplate = nullTemplate{}
|
|
|
|
type nullTemplate struct{}
|
|
|
|
func (t nullTemplate) Render(context interface{}) (string, error) {
|
|
return "", nil
|
|
}
|