ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/aya/vendor/github.com/yosssi/gcss/at_rule.go
Revision: 1.1
Committed: Mon Sep 30 00:42:06 2024 UTC (6 weeks, 4 days ago) by yakumo_izuru
Branch: MAIN
CVS Tags: HEAD
Log Message:
Mirrored from https://git.chaotic.ninja/git/yakumo_izuru/aya

File Contents

# User Rev Content
1 yakumo_izuru 1.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     }