Mercurial > yakumo_izuru > aya
comparison vendor/github.com/yosssi/gcss/at_rule.go @ 66:787b5ee0289d draft
Use vendored modules
Signed-off-by: Izuru Yakumo <yakumo.izuru@chaotic.ninja>
author | yakumo.izuru |
---|---|
date | Sun, 23 Jul 2023 13:18:53 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
65:6d985efa0f7a | 66:787b5ee0289d |
---|---|
1 package gcss | |
2 | |
3 import ( | |
4 "bytes" | |
5 "io" | |
6 "strings" | |
7 ) | |
8 | |
9 // atRule represents an at-rule of CSS. | |
10 type atRule struct { | |
11 elementBase | |
12 } | |
13 | |
14 // WriteTo writes the at-rule to the writer. | |
15 func (ar *atRule) WriteTo(w io.Writer) (int64, error) { | |
16 bf := new(bytes.Buffer) | |
17 | |
18 bf.WriteString(strings.TrimSpace(ar.ln.s)) | |
19 | |
20 if len(ar.sels) == 0 && len(ar.decs) == 0 && !ar.hasMixinDecs() && !ar.hasMixinSels() { | |
21 bf.WriteString(semicolon) | |
22 n, err := w.Write(bf.Bytes()) | |
23 return int64(n), err | |
24 } | |
25 | |
26 bf.WriteString(openBrace) | |
27 | |
28 // Writing to the bytes.Buffer never returns an error. | |
29 ar.writeDecsTo(bf, nil) | |
30 | |
31 for _, sel := range ar.sels { | |
32 // Writing to the bytes.Buffer never returns an error. | |
33 sel.WriteTo(bf) | |
34 } | |
35 | |
36 // Write the mixin's selectors. | |
37 for _, mi := range ar.mixins { | |
38 sels, prms := mi.selsParams() | |
39 | |
40 for _, sl := range sels { | |
41 sl.parent = ar | |
42 // Writing to the bytes.Buffer never returns an error. | |
43 sl.writeTo(bf, prms) | |
44 } | |
45 } | |
46 | |
47 bf.WriteString(closeBrace) | |
48 | |
49 n, err := w.Write(bf.Bytes()) | |
50 | |
51 return int64(n), err | |
52 } | |
53 | |
54 // newAtRule creates and returns a at-rule. | |
55 func newAtRule(ln *line, parent element) *atRule { | |
56 return &atRule{ | |
57 elementBase: newElementBase(ln, parent), | |
58 } | |
59 } |