-
Notifications
You must be signed in to change notification settings - Fork 0
/
viewengine.go
48 lines (37 loc) · 1.17 KB
/
viewengine.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
46
47
48
package mano
import (
"io"
"github.com/junhwong/mano/otpl"
"github.com/junhwong/mano/otpl/runtime"
)
// ViewEngine 提供用于将特定模板为渲染为相应输出格式的一组方法
type ViewEngine interface {
Render(data map[string]interface{}, path string, out io.Writer) error
//ResolveView(name string, locale string) View
}
//*************** OTPL模板引擎(默认) ***************
type OtplViewEngine struct {
runtime *runtime.Runtime
}
func (engine *OtplViewEngine) Render(data map[string]interface{}, path string, out io.Writer) error {
return engine.runtime.Render(data, path, out)
}
// Otpl 视图引擎
func Otpl(ilpath string) *OtplViewEngine {
engine := &OtplViewEngine{
runtime: otpl.New(ilpath),
}
return engine
}
//*************** 原生模板引擎 ***************
type GoTemplateViewEngine struct {
runtime *runtime.Runtime
}
func (engine *GoTemplateViewEngine) Render(data map[string]interface{}, path string, out io.Writer) error {
return engine.runtime.Render(data, path, out)
}
// GoTemplate 将使用 GO 原生模板技术作为视图引擎
func GoTemplate(ilpath string) *GoTemplateViewEngine {
engine := &GoTemplateViewEngine{}
return engine
}