-
Notifications
You must be signed in to change notification settings - Fork 0
/
handler_simple.go
53 lines (43 loc) · 997 Bytes
/
handler_simple.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
package interpol
import (
"fmt"
)
// the text handler is a handler for static text
type textHandler struct {
text string
}
func newTextHandler(ctx *Interpol, text string, data *Parameters) (Handler, error) {
return &textHandler{text: text}, nil
}
func (t *textHandler) String() string {
return t.text
}
func (t *textHandler) Next() bool {
return false
}
func (t *textHandler) Reset() {
// empty
}
// the copy handler will just copy another handlers value
type copyHandler struct {
from Handler
}
func newCopyHandler(ctx *Interpol, text string, data *Parameters) (Handler, error) {
from := ctx.tryImport(data.GetString("from", ""))
if from == nil {
return nil, fmt.Errorf("copy could not find target")
}
return ©Handler{from: from}, nil
}
func (ch *copyHandler) String() string {
return ch.from.String()
}
func (ch *copyHandler) Next() bool {
return false
}
func (ch *copyHandler) Reset() {
// empty
}
func init() {
addDefaultHandlerFactory("copy", newCopyHandler)
}