-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathcomponent.go
43 lines (36 loc) · 978 Bytes
/
component.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
package expr
import (
"fmt"
)
type (
// Component represents a component.
Component struct {
*Element
Container *Container
}
// Components is a slice of components that can be easily converted into
// a slice of ElementHolder.
Components []*Component
)
// ComponentTags lists the tags that are added to all components.
var ComponentTags = []string{"Element", "Component"}
// EvalName returns the generic expression name used in error messages.
func (c *Component) EvalName() string {
if c.Name == "" {
return "unnamed component"
}
return fmt.Sprintf("component %q", c.Name)
}
// Finalize adds the 'Component' tag ands finalizes relationships.
func (c *Component) Finalize() {
c.PrefixTags(ComponentTags...)
c.Element.Finalize()
}
// Elements returns a slice of ElementHolder that contains the elements of c.
func (cs Components) Elements() []ElementHolder {
res := make([]ElementHolder, len(cs))
for i, cc := range cs {
res[i] = cc
}
return res
}