forked from gobuffalo/buffalo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
string.go
47 lines (40 loc) · 904 Bytes
/
string.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
package render
import (
"io"
"github.com/aymerick/raymond"
)
type stringRenderer struct {
*Engine
body string
}
func (s stringRenderer) ContentType() string {
return "text/plain"
}
func (s stringRenderer) Render(w io.Writer, data Data) error {
t, err := raymond.Parse(s.body)
if err != nil {
return err
}
t.RegisterHelpers(s.Helpers)
b, err := t.Exec(data)
if err != nil {
return err
}
_, err = w.Write([]byte(b))
return err
}
// String renderer that will run the string through
// the github.com/aymerick/raymond package and return
// "text/plain" as the content type.
func String(s string) Renderer {
return stringRenderer{
Engine: New(Options{}),
body: s,
}
}
// String renderer that will run the string through
// the github.com/aymerick/raymond package and return
// "text/plain" as the content type.
func (e *Engine) String(s string) Renderer {
return String(s)
}