-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimport.go
More file actions
63 lines (53 loc) · 1.39 KB
/
import.go
File metadata and controls
63 lines (53 loc) · 1.39 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
51
52
53
54
55
56
57
58
59
60
61
62
63
package gg
import "io"
type iimport struct {
items *Group
}
// Import will start a new import Group.
func Import() *iimport {
i := &iimport{
items: newGroup("(", ")", "\n"),
}
i.items.omitWrapIf = func() bool {
return i.items.length() <= 1
}
return i
}
func (i *iimport) render(w io.Writer) {
// Don't need to render anything if import is empty
if i.items.length() == 0 {
return
}
writeString(w, "import ")
i.items.render(w)
}
// AddPath will import a new path, like `"context"`
func (i *iimport) AddPath(name string) *iimport {
i.items.append(Lit(name))
return i
}
// AddDot will import a new path with dot, like `. "context"`
func (i *iimport) AddDot(name string) *iimport {
i.items.append(String(`. "%s"`, name))
return i
}
// AddBlank will import a new path with black, like `_ "context"`
func (i *iimport) AddBlank(name string) *iimport {
i.items.append(String(`_ "%s"`, name))
return i
}
// AddAlias will import a new path with alias, like `ctx "context"`
func (i *iimport) AddAlias(name, alias string) *iimport {
i.items.append(String(`%s "%s"`, alias, name))
return i
}
// AddLine will insert a new line here.
func (i *iimport) AddLine() *iimport {
i.items.append(Line())
return i
}
// AddLineComment will insert a new line comment here.
func (i *iimport) AddLineComment(content string, args ...interface{}) *iimport {
i.items.append(LineComment(content, args...))
return i
}