serve templates from disk
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
package web
|
||||
|
||||
import (
|
||||
"html/template"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
// TemplateGetter defines what needs to be implemented to be able to fetch
|
||||
// templates for use by a Site.
|
||||
type TemplateGetter interface {
|
||||
Get(name string) (*template.Template, error)
|
||||
}
|
||||
|
||||
// Disk keeps track of the location of the root directory of the template
|
||||
// directory.
|
||||
type Disk struct {
|
||||
Root string
|
||||
}
|
||||
|
||||
// Get attempts to merge the requested name+.html with base.html found at root.
|
||||
func (d Disk) Get(name string) (*template.Template, error) {
|
||||
p := filepath.Join(d.Root, name+".html")
|
||||
return template.New("").ParseFiles(p, filepath.Join(d.Root, "base.html"))
|
||||
}
|
||||
Reference in New Issue
Block a user