forked from nissy/ace
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelper_method_include.go
More file actions
50 lines (39 loc) · 1.17 KB
/
helper_method_include.go
File metadata and controls
50 lines (39 loc) · 1.17 KB
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
package ace
import (
"fmt"
"io"
"strings"
)
// helperMethodInclude represents a helper method include.
type helperMethodInclude struct {
elementBase
templateName string
pipeline string
}
// WriteTo writes data to w.
func (e *helperMethodInclude) WriteTo(w io.Writer) (int64, error) {
var s string
if e.pipeline == "" {
s = fmt.Sprintf(actionTemplate, e.opts.DelimLeft, e.templateName, e.opts.DelimRight)
} else {
s = fmt.Sprintf(actionTemplateWithPipeline, e.opts.DelimLeft, e.templateName, e.pipeline, e.opts.DelimRight)
}
i, err := w.Write([]byte(s))
return int64(i), err
}
// newHelperMethodInclude creates and returns a helper method include.
func newHelperMethodInclude(ln *line, rslt *result, src *source, parent element, opts *Options) (*helperMethodInclude, error) {
if len(ln.tokens) < 3 {
return nil, fmt.Errorf("no template name is specified [file: %s][line: %d]", ln.fileName(), ln.no)
}
var pipeline string
if len(ln.tokens) > 3 {
pipeline = strings.Join(ln.tokens[3:], space)
}
e := &helperMethodInclude{
elementBase: newElementBase(ln, rslt, src, parent, opts),
templateName: ln.tokens[2],
pipeline: pipeline,
}
return e, nil
}