serve templates from disk

This commit is contained in:
sm
2017-01-26 20:16:12 -08:00
parent 85296b4e1b
commit 09f4fef613
6 changed files with 92 additions and 36 deletions
+24
View File
@@ -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"))
}