~repos /gromer

#golang#htmx#ssr

git clone https://pyrossh.dev/repos/gromer.git

gromer is a framework and cli to build multipage web apps in golang using htmx and alpinejs.


ca561af3 pyros2097

tag: v0.0.8

v0.0.8

5 years ago
ass css link
Files changed (6) hide show
  1. cli/main.go +1 -0
  2. css.go +2 -1
  3. css_test.go +8 -2
  4. go.mod +2 -1
  5. go.sum +21 -0
  6. html.go +15 -11
cli/main.go CHANGED
@@ -247,6 +247,7 @@ func createPage(ui app.UI, wasmPath string) *bytes.Buffer {
247
247
  app.Meta("viewport", "width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0, viewport-fit=cover"),
248
248
  app.Link("icon", "/assets/icon.png"),
249
249
  app.Link("apple-touch-icon", "/assets/icon.png"),
250
+ app.Link("stylesheet", "/assets/styles.css"),
250
251
  app.Link("manifest", "manifest"),
251
252
  app.Script(wasmExecJs(wasmPath)),
252
253
  ),
css.go CHANGED
@@ -7,10 +7,11 @@ import (
7
7
  )
8
8
 
9
9
  type CSSClass struct {
10
+ UI
10
11
  classes string
11
12
  }
12
13
 
13
- func Css(d string) CSSClass {
14
+ func Css(d string) UI {
14
15
  return CSSClass{classes: d}
15
16
  }
16
17
 
css_test.go CHANGED
@@ -1,11 +1,17 @@
1
1
  package app
2
2
 
3
3
  import (
4
+ "bytes"
4
5
  "testing"
5
6
 
6
7
  "github.com/stretchr/testify/assert"
7
8
  )
8
9
 
9
- func TestCss(t *testing.T) {
10
+ func TestCreatePage(t *testing.T) {
11
+ page := bytes.NewBuffer(nil)
12
+ page.WriteString("<!DOCTYPE html>\n")
13
+ Html(
10
- assert.Equal(t, "123", Css("123").classes)
14
+ Body(Div(Css("abc"), Text("About Me"))),
15
+ ).Html(page)
16
+ assert.Equal(t, "<!DOCTYPE html>\n<html>\n <head>\n <div class=\"abc\"></div>\n </head>\n</html>", page.String())
11
17
  }
go.mod CHANGED
@@ -5,7 +5,8 @@ go 1.15
5
5
  require (
6
6
  github.com/fsnotify/fsnotify v1.4.7 // indirect
7
7
  github.com/markbates/pkger v0.17.1
8
+ github.com/maxence-charriere/go-app/v7 v7.0.6
8
- github.com/stretchr/testify v1.5.1
9
+ github.com/stretchr/testify v1.6.1
9
10
  golang.org/x/sys v0.0.0-20201112073958-5cba982894dd // indirect
10
11
  gopkg.in/fsnotify.v1 v1.4.7
11
12
  gopkg.in/yaml.v2 v2.2.8 // indirect
go.sum CHANGED
@@ -5,6 +5,9 @@ github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV
5
5
  github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
6
6
  github.com/gobuffalo/here v0.6.0 h1:hYrd0a6gDmWxBM4TnrGw8mQg24iSVoIkHEk7FodQcBI=
7
7
  github.com/gobuffalo/here v0.6.0/go.mod h1:wAG085dHOYqUpf+Ap+WOdrPTp5IYcDAs/x7PLa8Y5fM=
8
+ github.com/gomarkdown/markdown v0.0.0-20201030010234-8ba61b39d0e4/go.mod h1:aii0r/K0ZnHv7G0KF7xy1v0A7s2Ljrb5byB7MO5p6TU=
9
+ github.com/google/uuid v1.1.2 h1:EVhdT+1Kseyi1/pUmXKaFxYsDNy9RQYkMWRH68J/W7Y=
10
+ github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
8
11
  github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
9
12
  github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
10
13
  github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
@@ -12,14 +15,30 @@ github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
12
15
  github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
13
16
  github.com/markbates/pkger v0.17.1 h1:/MKEtWqtc0mZvu9OinB9UzVN9iYCwLWuyUv4Bw+PCno=
14
17
  github.com/markbates/pkger v0.17.1/go.mod h1:0JoVlrol20BSywW79rN3kdFFsE5xYM+rSCQDXbLhiuI=
18
+ github.com/maxence-charriere/go-app v1.3.6 h1:ivoXYI+Wf11vrmgoew5hcFDw4djFin2HzwBGjs8yV+4=
19
+ github.com/maxence-charriere/go-app/v7 v7.0.6 h1:u8Hl1aq2TNqOaTEqUAOgVsRc0vMKkn6nzMZS3vQPpSE=
20
+ github.com/maxence-charriere/go-app/v7 v7.0.6/go.mod h1:3S3cKNiz6/ib081vPTkM+WOuIIK7qtq+7wtHFX9/Svw=
15
21
  github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
16
22
  github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
17
23
  github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
18
24
  github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
19
25
  github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4=
20
26
  github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
27
+ github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
28
+ github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
29
+ golang.org/dl v0.0.0-20190829154251-82a15e2f2ead/go.mod h1:IUMfjQLJQd4UTqG1Z90tenwKoCX93Gn3MAQJMOSBsDQ=
30
+ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
31
+ golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
32
+ golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
33
+ golang.org/x/net v0.0.0-20201031054903-ff519b6c9102/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
34
+ golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
35
+ golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
36
+ golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
21
37
  golang.org/x/sys v0.0.0-20201112073958-5cba982894dd h1:5CtCZbICpIOFdgO940moixOPjc0178IU44m4EjOO5IY=
22
38
  golang.org/x/sys v0.0.0-20201112073958-5cba982894dd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
39
+ golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
40
+ golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
41
+ golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
23
42
  gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
24
43
  gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
25
44
  gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
@@ -29,3 +48,5 @@ gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
29
48
  gopkg.in/yaml.v2 v2.2.7/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
30
49
  gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
31
50
  gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
51
+ gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
52
+ gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
html.go CHANGED
@@ -48,18 +48,22 @@ func Script(str string) *elem {
48
48
  }
49
49
  }
50
50
 
51
- func Div(elems ...UI) *elem {
51
+ func RemoveAttributes(uis ...UI) ([]UI, string) {
52
+ elems := make([]UI, 0, len(uis))
52
- return &elem{tag: "div", body: elems}
53
+ classes := ""
54
+ for _, v := range uis {
55
+ if v.Kind() == Attribute {
56
+ cc, _ := v.(CSSClass)
57
+ classes = classes + cc.classes
53
- }
58
+ }
54
59
 
55
- func Row(elems ...UI) *elem {
56
- return &elem{tag: "div", body: elems, attrs: map[string]string{
57
- "style": "display: flex;flex: 1;flex-direction: row;align-items: center;justify-content: center;",
58
- }}
60
+ }
61
+ return elems, classes
59
62
  }
60
63
 
61
- func Col(elems ...UI) *elem {
64
+ func Div(uis ...UI) *elem {
65
+ elems, classes := RemoveAttributes(uis...)
62
- return &elem{tag: "div", body: elems, attrs: map[string]string{
66
+ e := &elem{tag: "div", body: elems}
63
- "style": "display: flex;flex: 1;flex-direction: column;align-items: center;justify-content: center;",
67
+ e.setAttr("class", classes)
64
- }}
68
+ return e
65
69
  }