gromer

#golang#htmx#ssr

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

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


ca561af — pyros2097 2020-11-27T09:50:53+05:30
ass css link

Generated files not shown: go.sum

Files changed (5) 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. 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
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
  }