-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathmain.go
98 lines (91 loc) · 1.85 KB
/
main.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package main
import (
"github.com/AccentDesign/gcss"
"github.com/AccentDesign/gcss/props"
"io"
"os"
)
type (
Styles []gcss.Style
Media struct {
Query string
Styles Styles
}
Stylesheet struct {
Styles Styles
Medias []Media
}
)
// WriteCSS writes the CSS for the media query to the writer
func (m Media) WriteCSS(w io.Writer) error {
if _, err := io.WriteString(w, m.Query); err != nil {
return err
}
if _, err := io.WriteString(w, "{"); err != nil {
return err
}
for _, style := range m.Styles {
if err := style.CSS(w); err != nil {
return err
}
}
if _, err := io.WriteString(w, "}"); err != nil {
return err
}
return nil
}
// WriteCSS writes the CSS for the stylesheet to the writer
func (ss Stylesheet) WriteCSS(w io.Writer) error {
// Write the base styles first
for _, style := range ss.Styles {
if err := style.CSS(w); err != nil {
return err
}
}
// Write the media queries next
for _, media := range ss.Medias {
if err := media.WriteCSS(w); err != nil {
return err
}
}
return nil
}
var (
base = Styles{
{
Selector: "body",
Props: gcss.Props{
Margin: props.UnitRaw(0),
},
},
}
screen736 = Media{
Query: "@media only screen and (max-device-width: 736px)",
Styles: Styles{
{
Selector: "main",
Props: gcss.Props{
Padding: props.UnitRaw(0),
},
},
},
}
stylesheet = Stylesheet{
Styles: base,
Medias: []Media{screen736},
}
)
// This is just a basic idea of how you could structure your CSS
// the goal hear is just to wrap the css how you wish with what ever you wish
// construct your stylesheet to suit your needs.
// The end goal is just to call CSS on each style with the object to write to.
func main() {
file, err := os.Create("media.css")
if err != nil {
panic(err)
}
defer file.Close()
if err := stylesheet.WriteCSS(file); err != nil {
panic(err)
}
}