-
Notifications
You must be signed in to change notification settings - Fork 0
/
dom_selector.go
63 lines (50 loc) · 1.23 KB
/
dom_selector.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
54
55
56
57
58
59
60
61
62
63
package diff
import "strings"
type domSelector struct {
query []*domElemSelector
}
func newDomSelector() *domSelector {
return &domSelector{
query: make([]*domElemSelector, 0),
}
}
func (ds *domSelector) addChild() *domElemSelector {
de := newDOMElementSelector()
ds.addChildSelector(de)
return de
}
func (ds *domSelector) addParentSelector(d *domElemSelector) {
ds.query = append([]*domElemSelector{d}, ds.query...)
}
func (ds *domSelector) addChildSelector(d *domElemSelector) {
ds.query = append(ds.query, d)
}
func (ds *domSelector) addParent() *domElemSelector {
de := newDOMElementSelector()
ds.addParentSelector(de)
return de
}
func (ds *domSelector) toString() string {
var e []string
for _, q := range ds.query {
e = append(e, q.toString())
}
return strings.Join(e, " ")
}
type domElemSelector struct {
query []string
}
func newDOMElementSelector() *domElemSelector {
return &domElemSelector{
query: []string{},
}
}
func (de *domElemSelector) setElemen(elemn string) {
de.query = append(de.query, elemn)
}
func (de *domElemSelector) addAttr(key, value string) {
de.query = append(de.query, "[", key, "=\"", value, "\"]")
}
func (de *domElemSelector) toString() string {
return strings.Join(de.query, "")
}