/css/selectors/selectors.go
Go | 85 lines | 64 code | 21 blank | 0 comment | 4 complexity | 78bbefeb3bc43d29b60c9959c33082c0 MD5 | raw file
1package selectors 2 3import () 4 5type selector interface { 6 String() string 7} 8 9type SimpleSelector struct { 10 type_val string 11 extra_val string 12 sealed bool 13} 14 15func (s *SimpleSelector) String() string { 16 if s.extra_val == "" { 17 return s.type_val 18 } 19 if s.type_val == "*" { 20 return s.extra_val 21 } 22 23 return s.type_val + s.extra_val 24} 25 26func (s *SimpleSelector) Sealed() bool { 27 return s.sealed 28} 29 30func Universal() *SimpleSelector { 31 return &SimpleSelector{type_val:"*"} 32} 33 34func Type(s string) *SimpleSelector { 35 return &SimpleSelector{type_val:s} 36} 37 38func Attribute(s string) *SimpleSelector { 39 return &SimpleSelector{type_val:"*", extra_val:"[" + s + "]"} 40} 41 42func AttributeSpaceList(s, b string) *SimpleSelector { 43 return Attribute(s + "~=\"" + b + "\"") 44} 45 46func AttributeEquals(s, b string) *SimpleSelector { 47 return Attribute(s + "=\"" + b + "\"") 48} 49 50func AttributeBegins(s, b string) *SimpleSelector { 51 return Attribute(s + "^=\"" + b + "\"") 52} 53 54func AttributeEnds(s, b string) *SimpleSelector { 55 return Attribute(s + "$=\"" + b + "\"") 56} 57 58func AttributeSubstring(s, b string) *SimpleSelector { 59 return Attribute(s + "*=\"" + b + "\"") 60} 61 62func AttributeHyphenList(s, b string) *SimpleSelector { 63 return Attribute(s + "|=\"" + b + "\"") 64} 65 66func PseudoClass(s string) *SimpleSelector { 67 return &SimpleSelector{type_val:"*", extra_val: ":" + s} 68} 69 70func PseudoElement(s string) *SimpleSelector { 71 return &SimpleSelector{type_val:"*", extra_val: "::" + s} 72} 73 74func Id(id string) *SimpleSelector { 75 return &SimpleSelector{type_val:"", extra_val: "#" + id} 76} 77 78func Not(s *SimpleSelector) *SimpleSelector { 79 s.sealed = true 80 return &SimpleSelector{} 81} 82 83type GroupSelector struct { 84 85}