-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
MediaGroup.go
59 lines (45 loc) · 991 Bytes
/
MediaGroup.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 scarlet
import "strings"
// Force interface implementation
var _ Renderable = (*MediaGroup)(nil)
// MediaGroup ...
type MediaGroup struct {
Operator string
Size string
Property string
Rules []*CSSRule
}
// Render renders the media group to the output stream.
func (media *MediaGroup) Render(output *strings.Builder, pretty bool) {
output.WriteString("@media all and (")
switch media.Operator {
case "<":
output.WriteString("max")
case ">":
output.WriteString("min")
default:
panic("Invalid screen size operator in media query")
}
output.WriteByte('-')
output.WriteString(media.Property)
output.WriteByte(':')
if pretty {
output.WriteByte(' ')
}
output.WriteString(media.Size)
output.WriteByte(')')
if pretty {
output.WriteByte(' ')
}
output.WriteByte('{')
if pretty {
output.WriteByte('\n')
}
for _, rule := range media.Rules {
rule.Render(output, pretty)
}
output.WriteByte('}')
if pretty {
output.WriteByte('\n')
}
}