-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrender.go
45 lines (36 loc) · 994 Bytes
/
render.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package coco
import (
"html/template"
"io/fs"
"github.com/noelukwa/tempest"
)
// TemplateConfig is a configuration for loading templates from an fs.FS
type TemplateConfig struct {
// The file extension of the templates.
// Defaults to ".html".
Ext string
// The directory where the includes are stored.
// Defaults to "includes".
IncludesDir string
// The name used for layout templates :- templates that wrap other contents.
// Defaults to "layouts".
Layout string
}
// LoadTemplates loads templates from an fs.FS with a given config
func (a *App) LoadTemplates(fs fs.FS, config *TemplateConfig) (err error) {
if a.templates == nil {
a.templates = make(map[string]*template.Template)
}
var tmpst *tempest.Tempest
if config != nil {
tmpst = tempest.WithConfig(&tempest.Config{
Layout: config.Layout,
IncludesDir: config.IncludesDir,
Ext: config.Ext,
})
} else {
tmpst = tempest.New()
}
a.templates, err = tmpst.LoadFS(fs)
return err
}