File: custom.go

package info (click to toggle)
golang-github-dave-jennifer 1.4.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 372 kB
  • sloc: makefile: 4
file content (61 lines) | stat: -rw-r--r-- 2,009 bytes parent folder | download
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
package jen

// Options specifies options for the Custom method
type Options struct {
	Open      string
	Close     string
	Separator string
	Multi     bool
}

// Custom renders a customized statement list. Pass in options to specify multi-line, and tokens for open, close, separator.
func Custom(options Options, statements ...Code) *Statement {
	return newStatement().Custom(options, statements...)
}

// Custom renders a customized statement list. Pass in options to specify multi-line, and tokens for open, close, separator.
func (g *Group) Custom(options Options, statements ...Code) *Statement {
	s := Custom(options, statements...)
	g.items = append(g.items, s)
	return s
}

// Custom renders a customized statement list. Pass in options to specify multi-line, and tokens for open, close, separator.
func (s *Statement) Custom(options Options, statements ...Code) *Statement {
	g := &Group{
		close:     options.Close,
		items:     statements,
		multi:     options.Multi,
		name:      "custom",
		open:      options.Open,
		separator: options.Separator,
	}
	*s = append(*s, g)
	return s
}

// CustomFunc renders a customized statement list. Pass in options to specify multi-line, and tokens for open, close, separator.
func CustomFunc(options Options, f func(*Group)) *Statement {
	return newStatement().CustomFunc(options, f)
}

// CustomFunc renders a customized statement list. Pass in options to specify multi-line, and tokens for open, close, separator.
func (g *Group) CustomFunc(options Options, f func(*Group)) *Statement {
	s := CustomFunc(options, f)
	g.items = append(g.items, s)
	return s
}

// CustomFunc renders a customized statement list. Pass in options to specify multi-line, and tokens for open, close, separator.
func (s *Statement) CustomFunc(options Options, f func(*Group)) *Statement {
	g := &Group{
		close:     options.Close,
		multi:     options.Multi,
		name:      "custom",
		open:      options.Open,
		separator: options.Separator,
	}
	f(g)
	*s = append(*s, g)
	return s
}