forked from gobuffalo/buffalo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
render.go
41 lines (36 loc) · 1009 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
package render
import (
"github.com/aymerick/raymond"
"github.com/markbates/buffalo/render/helpers"
)
// Engine used to power all defined renderers.
// This allows you to configure the system to your
// prefered settings, instead of just getting
// the defaults.
type Engine struct {
Options
}
// New render.Engine ready to go with your Options
// and some defaults we think you might like.
func New(opts Options) *Engine {
e := &Engine{
Options: opts,
}
e.RegisterHelpers(helpers.Helpers)
return e
}
// See github.com/aymerick/raymond for more details on helpers.
func (e *Engine) RegisterHelper(name string, helper interface{}) {
e.RegisterHelpers(map[string]interface{}{
name: helper,
})
}
// See github.com/aymerick/raymond for more details on helpers.
func (e *Engine) RegisterHelpers(helpers map[string]interface{}) {
defer func() {
// Since raymond panics(!!) when a helper is already registered
// let's recover and move on.
recover()
}()
raymond.RegisterHelpers(helpers)
}