forked from gobuffalo/buffalo
-
Notifications
You must be signed in to change notification settings - Fork 2
/
string.go
46 lines (39 loc) · 884 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
package render
import (
"io"
"github.com/gobuffalo/velvet"
)
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 := velvet.Parse(s.body)
if err != nil {
return err
}
b, err := t.Exec(data.ToVelvet())
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)
}