This repository has been archived by the owner on Feb 24, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 577
/
render.go
70 lines (62 loc) · 1.73 KB
/
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package render
import (
"github.com/gobuffalo/helpers"
"github.com/gobuffalo/helpers/forms"
"github.com/gobuffalo/helpers/forms/bootstrap"
"github.com/gobuffalo/plush"
)
// Engine used to power all defined renderers.
// This allows you to configure the system to your
// preferred 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 {
if opts.Helpers == nil {
opts.Helpers = Helpers{}
}
if len(opts.Helpers) == 0 {
opts.Helpers = defaultHelpers()
}
if opts.TemplateEngines == nil {
opts.TemplateEngines = map[string]TemplateEngine{}
}
if _, ok := opts.TemplateEngines["html"]; !ok {
opts.TemplateEngines["html"] = plush.BuffaloRenderer
}
if _, ok := opts.TemplateEngines["plush"]; !ok {
opts.TemplateEngines["html"] = plush.BuffaloRenderer
}
if _, ok := opts.TemplateEngines["text"]; !ok {
opts.TemplateEngines["text"] = plush.BuffaloRenderer
}
if _, ok := opts.TemplateEngines["txt"]; !ok {
opts.TemplateEngines["txt"] = plush.BuffaloRenderer
}
if _, ok := opts.TemplateEngines["js"]; !ok {
opts.TemplateEngines["js"] = plush.BuffaloRenderer
}
if _, ok := opts.TemplateEngines["md"]; !ok {
opts.TemplateEngines["md"] = MDTemplateEngine
}
if _, ok := opts.TemplateEngines["tmpl"]; !ok {
opts.TemplateEngines["tmpl"] = GoTemplateEngine
}
if opts.DefaultContentType == "" {
opts.DefaultContentType = "text/html; charset=utf-8"
}
e := &Engine{
Options: opts,
}
return e
}
func defaultHelpers() Helpers {
h := Helpers(helpers.ALL())
h[forms.FormKey] = bootstrap.Form
h[forms.FormForKey] = bootstrap.FormFor
h["form_for"] = bootstrap.FormFor
return h
}