forked from foolin/echo-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gorice.go
31 lines (27 loc) · 894 Bytes
/
gorice.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
package gorice
import (
"github.com/foolin/echo-template"
"github.com/GeertJohan/go.rice"
)
/**
New echo template engine, default views root.
*/
func New(viewsRootBox *rice.Box) *echotemplate.TemplateEngine {
return NewWithConfig(viewsRootBox, echotemplate.DefaultConfig)
}
/**
New echo template engine
Important!!! The viewsRootBox's name and config.Root must be consistent.
*/
func NewWithConfig(viewsRootBox *rice.Box, config echotemplate.TemplateConfig) *echotemplate.TemplateEngine {
config.Root = viewsRootBox.Name()
engine := echotemplate.New(config)
engine.SetFileHandler(FileHandler(viewsRootBox))
return engine
}
func FileHandler(viewsRootBox *rice.Box) echotemplate.FileHandler {
return func(config echotemplate.TemplateConfig, tplFile string) (content string, err error) {
// get file contents as string
return viewsRootBox.String(tplFile + config.Extension)
}
}