-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathat_rule.go
59 lines (45 loc) · 1.15 KB
/
at_rule.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
package gcss
import (
"bytes"
"io"
"strings"
)
// atRule represents an at-rule of CSS.
type atRule struct {
elementBase
}
// WriteTo writes the at-rule to the writer.
func (ar *atRule) WriteTo(w io.Writer) (int64, error) {
bf := new(bytes.Buffer)
bf.WriteString(strings.TrimSpace(ar.ln.s))
if len(ar.sels) == 0 && len(ar.decs) == 0 && !ar.hasMixinDecs() && !ar.hasMixinSels() {
bf.WriteString(semicolon)
n, err := w.Write(bf.Bytes())
return int64(n), err
}
bf.WriteString(openBrace)
// Writing to the bytes.Buffer never returns an error.
ar.writeDecsTo(bf, nil)
for _, sel := range ar.sels {
// Writing to the bytes.Buffer never returns an error.
sel.WriteTo(bf)
}
// Write the mixin's selectors.
for _, mi := range ar.mixins {
sels, prms := mi.selsParams()
for _, sl := range sels {
sl.parent = ar
// Writing to the bytes.Buffer never returns an error.
sl.writeTo(bf, prms)
}
}
bf.WriteString(closeBrace)
n, err := w.Write(bf.Bytes())
return int64(n), err
}
// newAtRule creates and returns a at-rule.
func newAtRule(ln *line, parent element) *atRule {
return &atRule{
elementBase: newElementBase(ln, parent),
}
}