-
Notifications
You must be signed in to change notification settings - Fork 0
/
css.go
53 lines (45 loc) · 837 Bytes
/
css.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
package web
import (
"io"
"github.com/gregoryv/nexus"
)
func NewCSS() *CSS {
return &CSS{
rules: make([]*rule, 0),
}
}
type CSS struct {
Media string
rules []*rule
}
func (r *CSS) WriteTo(w io.Writer) (int64, error) {
p, err := nexus.NewPrinter(w)
if r.Media != "" {
p.Print(r.Media)
p.Println("{")
}
for _, rule := range r.rules {
rule.WriteTo(p)
}
if r.Media != "" {
p.Println("}")
}
return p.Written, *err
}
func (c *CSS) Style(selector string, propvals ...string) {
c.rules = append(c.rules, &rule{selector, propvals})
}
type rule struct {
selector string
propvals []string
}
func (r *rule) WriteTo(w io.Writer) (int64, error) {
p, err := nexus.NewPrinter(w)
p.Print(r.selector)
p.Println(" {")
for _, pv := range r.propvals {
p.Println(pv + ";")
}
p.Println("}")
return p.Written, *err
}