~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.


da0c5a59 Peter John

4 years ago
publish wapp
Files changed (5) hide show
  1. cmd/main.go +147 -0
  2. go.mod +14 -1
  3. go.sum +64 -0
  4. html.go +0 -51
  5. readme.md +3 -61
cmd/main.go ADDED
@@ -0,0 +1,147 @@
1
+ package main
2
+
3
+ import (
4
+ "bytes"
5
+ "fmt"
6
+ "io/ioutil"
7
+ "log"
8
+ "os"
9
+ "path/filepath"
10
+ "strings"
11
+
12
+ "github.com/gobuffalo/velvet"
13
+ "golang.org/x/mod/modfile"
14
+ )
15
+
16
+ type Route struct {
17
+ Method string
18
+ Path string
19
+ }
20
+
21
+ func getMethod(src string) string {
22
+ if strings.HasSuffix(src, "get.go") {
23
+ return "GET"
24
+ } else if strings.HasSuffix(src, "post.go") {
25
+ return "POST"
26
+ } else if strings.HasSuffix(src, "put.go") {
27
+ return "PUT"
28
+ } else if strings.HasSuffix(src, "patch.go") {
29
+ return "PATCH"
30
+ } else if strings.HasSuffix(src, "delete.go") {
31
+ return "DELETE"
32
+ } else if strings.HasSuffix(src, "head.go") {
33
+ return "HEAD"
34
+ } else if strings.HasSuffix(src, "options.go") {
35
+ return "OPTIONS"
36
+ } else if strings.HasSuffix(src, "connect.go") {
37
+ return "CONNECT"
38
+ } else if strings.HasSuffix(src, "trace.go") {
39
+ return "TRACE"
40
+ } else {
41
+ panic(fmt.Sprintf("Uknown route found %s", src))
42
+ }
43
+ }
44
+
45
+ func getRoute(method, src string) string {
46
+ muxRoute := bytes.NewBuffer(nil)
47
+ baseRoute := strings.Replace(src, "/"+strings.ToLower(method)+".go", "", 1)
48
+ foundStart := false
49
+ for _, v := range baseRoute {
50
+ if string(v) == "_" && !foundStart {
51
+ foundStart = true
52
+ muxRoute.WriteString("{")
53
+ } else if string(v) == "_" && foundStart {
54
+ foundStart = false
55
+ muxRoute.WriteString("}")
56
+ } else {
57
+ muxRoute.WriteString(string(v))
58
+ }
59
+ }
60
+ return muxRoute.String()
61
+ }
62
+
63
+ func main() {
64
+ data, err := ioutil.ReadFile("go.mod")
65
+ if err != nil {
66
+ log.Fatalf("go.mod file not found %w", err)
67
+ }
68
+ modTree, err := modfile.Parse("go.mod", data, nil)
69
+ if err != nil {
70
+ log.Fatalf("could not parse go.mod %w", err)
71
+ }
72
+ moduleName := modTree.Module.Mod.Path
73
+ routes := []*Route{}
74
+ err = filepath.Walk("pages",
75
+ func(filesrc string, info os.FileInfo, err error) error {
76
+ if err != nil {
77
+ return err
78
+ }
79
+ if !info.IsDir() {
80
+ route := strings.Replace(filesrc, "pages", "", 1)
81
+ method := getMethod(route)
82
+ path := getRoute(method, route)
83
+ if path == "" { // for index page
84
+ path = "/"
85
+ }
86
+ routes = append(routes, &Route{Method: method, Path: path})
87
+ }
88
+ return nil
89
+ })
90
+ if err != nil {
91
+ log.Fatal(err)
92
+ }
93
+ for _, r := range routes {
94
+ println(r.Method, r.Path)
95
+ }
96
+ ctx := velvet.NewContext()
97
+ ctx.Set("moduleName", moduleName)
98
+ ctx.Set("routes", routes)
99
+ s, err := velvet.Render(`// GENERATED BY WAPP DO NOT EDIT THIS FILE
100
+ package main
101
+
102
+ import (
103
+ "embed"
104
+ "log"
105
+ "net/http"
106
+ "os"
107
+ "time"
108
+
109
+ "github.com/apex/gateway/v2"
110
+ "github.com/gorilla/mux"
111
+ . "{{ moduleName }}/context"
112
+ "{{ moduleName }}/pages"
113
+ "{{ moduleName }}/pages/about"
114
+ "{{ moduleName }}/pages/api/todos/_id_"
115
+ )
116
+
117
+ //go:embed assets/*
118
+ var assetsFS embed.FS
119
+
120
+ func main() {
121
+ isLambda := os.Getenv("_LAMBDA_SERVER_PORT") != ""
122
+ r := mux.NewRouter()
123
+ r.PathPrefix("/assets/").Handler(http.FileServer(http.FS(assetsFS)))
124
+
125
+ {{#each routes as |route| }}r.HandleFunc("{{ route.Path }}", Wrap(pages.GET)).Methods("{{ route.Method }}")
126
+ {{/each}}
127
+ if !isLambda {
128
+ println("http server listening on http://localhost:3000")
129
+ srv := &http.Server{
130
+ Handler: r,
131
+ Addr: "127.0.0.1:3000",
132
+ WriteTimeout: 30 * time.Second,
133
+ ReadTimeout: 30 * time.Second,
134
+ }
135
+ log.Fatal(srv.ListenAndServe())
136
+ } else {
137
+ log.Print("running in lambda mode")
138
+ log.Fatal(gateway.ListenAndServe(":3000", r))
139
+ }
140
+ }
141
+
142
+ `, ctx)
143
+ if err != nil {
144
+ panic(err)
145
+ }
146
+ println(s)
147
+ }
go.mod CHANGED
@@ -3,10 +3,23 @@ module github.com/pyros2097/wapp
3
3
  go 1.16
4
4
 
5
5
  require (
6
+ github.com/PuerkitoBio/goquery v1.7.1 // indirect
6
7
  github.com/apex/gateway/v2 v2.0.0
8
+ github.com/aymerick/raymond v2.0.2+incompatible // indirect
9
+ github.com/gobuffalo/velvet v0.0.0-20170320144106-d97471bf5d8f // indirect
7
10
  github.com/gorilla/mux v1.8.0
8
11
  github.com/kr/pretty v0.1.0 // indirect
12
+ github.com/markbates/inflect v1.0.4 // indirect
13
+ github.com/microcosm-cc/bluemonday v1.0.15 // indirect
14
+ github.com/sergi/go-diff v1.2.0 // indirect
15
+ github.com/shurcooL/github_flavored_markdown v0.0.0-20210228213109-c3a9aa474629 // indirect
16
+ github.com/shurcooL/highlight_diff v0.0.0-20181222201841-111da2e7d480 // indirect
17
+ github.com/shurcooL/highlight_go v0.0.0-20191220051317-782971ddf21b // indirect
18
+ github.com/shurcooL/octicon v0.0.0-20191102190552-cbb32d6a785c // indirect
19
+ github.com/sourcegraph/annotate v0.0.0-20160123013949-f4cad6c6324d // indirect
20
+ github.com/sourcegraph/syntaxhighlight v0.0.0-20170531221838-bd320f5d308e // indirect
9
21
  github.com/stretchr/testify v1.6.1
22
+ golang.org/x/mod v0.5.1 // indirect
10
- gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
23
+ golang.org/x/net v0.0.0-20210917221730-978cfadd31cf // indirect
11
24
  gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776 // indirect
12
25
  )
go.sum CHANGED
@@ -1,36 +1,100 @@
1
1
  github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
2
+ github.com/PuerkitoBio/goquery v1.7.1 h1:oE+T06D+1T7LNrn91B4aERsRIeCLJ/oPSa6xB9FPnz4=
3
+ github.com/PuerkitoBio/goquery v1.7.1/go.mod h1:XY0pP4kfraEmmV1O7Uf6XyjoslwsneBbgeDjLYuN8xY=
4
+ github.com/andybalholm/cascadia v1.2.0 h1:vuRCkM5Ozh/BfmsaTm26kbjm0mIOM3yS5Ek/F5h18aE=
5
+ github.com/andybalholm/cascadia v1.2.0/go.mod h1:YCyR8vOZT9aZ1CHEd8ap0gMVm2aFgxBp0T0eFw1RUQY=
2
6
  github.com/apex/gateway/v2 v2.0.0 h1:tJwKiB7ObbXuF3yoqTf/CfmaZRhHB+GfilTNSCf1Wnc=
3
7
  github.com/apex/gateway/v2 v2.0.0/go.mod h1:y+uuK0JxdvTHZeVns501/7qklBhnDHtGU0hfUQ6QIfI=
8
+ github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d/go.mod h1:WaHUgvxTVq04UNunO+XhnAqY/wQc+bxr74GqbsZ/Jqw=
4
9
  github.com/aws/aws-lambda-go v1.17.0 h1:Ogihmi8BnpmCNktKAGpNwSiILNNING1MiosnKUfU8m0=
5
10
  github.com/aws/aws-lambda-go v1.17.0/go.mod h1:FEwgPLE6+8wcGBTe5cJN3JWurd1Ztm9zN4jsXsjzKKw=
11
+ github.com/aymerick/douceur v0.2.0 h1:Mv+mAeH1Q+n9Fr+oyamOlAkUNPWPlA8PPGR0QAaYuPk=
12
+ github.com/aymerick/douceur v0.2.0/go.mod h1:wlT5vV2O3h55X9m7iVYN0TBM0NH/MmbLnd30/FjWUq4=
13
+ github.com/aymerick/raymond v2.0.2+incompatible h1:VEp3GpgdAnv9B2GFyTvqgcKvY+mfKMjPOA3SbKLtnU0=
14
+ github.com/aymerick/raymond v2.0.2+incompatible/go.mod h1:osfaiScAUVup+UC9Nfq76eWqDhXlp+4UYaA8uhTBO6g=
6
15
  github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
7
16
  github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
8
17
  github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
9
18
  github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
19
+ github.com/gobuffalo/envy v1.6.5 h1:X3is06x7v0nW2xiy2yFbbIjwHz57CD6z6MkvqULTCm8=
20
+ github.com/gobuffalo/envy v1.6.5/go.mod h1:N+GkhhZ/93bGZc6ZKhJLP6+m+tCNPKwgSpH9kaifseQ=
21
+ github.com/gobuffalo/velvet v0.0.0-20170320144106-d97471bf5d8f h1:ddIdPdlkAgKMB0mbkft2LT3oxN1h3MN1fopCFrOgkhY=
22
+ github.com/gobuffalo/velvet v0.0.0-20170320144106-d97471bf5d8f/go.mod h1:m9x1vDSQYrGiEhEiu0c4XuE0SZzw31Ms8ULjGdhaA54=
23
+ github.com/gorilla/css v1.0.0 h1:BQqNyPTi50JCFMTw/b67hByjMVXZRwGha6wxVGkeihY=
24
+ github.com/gorilla/css v1.0.0/go.mod h1:Dn721qIggHpt4+EFCcTLTU/vk5ySda2ReITrtgBl60c=
10
25
  github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI=
11
26
  github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
27
+ github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc=
28
+ github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg=
12
29
  github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
13
30
  github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
14
31
  github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
15
32
  github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
16
33
  github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
34
+ github.com/markbates/inflect v1.0.4 h1:5fh1gzTFhfae06u3hzHYO9xe3l3v3nW5Pwt3naLTP5g=
35
+ github.com/markbates/inflect v1.0.4/go.mod h1:1fR9+pO2KHEO9ZRtto13gDwwZaAKstQzferVeWqbgNs=
36
+ github.com/microcosm-cc/bluemonday v1.0.15 h1:J4uN+qPng9rvkBZBoBb8YGR+ijuklIMpSOZZLjYpbeY=
37
+ github.com/microcosm-cc/bluemonday v1.0.15/go.mod h1:ZLvAzeakRwrGnzQEvstVzVt3ZpqOF2+sdFr0Om+ce30=
17
38
  github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
18
39
  github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
19
40
  github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
20
41
  github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
42
+ github.com/russross/blackfriday v1.5.2 h1:HyvC0ARfnZBqnXwABFeSZHpKvJHJJfPz81GNueLj0oo=
43
+ github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
21
44
  github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
45
+ github.com/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ=
46
+ github.com/sergi/go-diff v1.2.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
47
+ github.com/shurcooL/github_flavored_markdown v0.0.0-20210228213109-c3a9aa474629 h1:86e54L0i3pH3dAIA8OxBbfLrVyhoGpnNk1iJCigAWYs=
48
+ github.com/shurcooL/github_flavored_markdown v0.0.0-20210228213109-c3a9aa474629/go.mod h1:2dOwnU2uBioM+SGy2aZoq1f/Sd1l9OkAeAUvjSyvgU0=
49
+ github.com/shurcooL/highlight_diff v0.0.0-20181222201841-111da2e7d480 h1:KaKXZldeYH73dpQL+Nr38j1r5BgpAYQjYvENOUpIZDQ=
50
+ github.com/shurcooL/highlight_diff v0.0.0-20181222201841-111da2e7d480/go.mod h1:ZpfEhSmds4ytuByIcDnOLkTHGUI6KNqRNPDLHDk+mUU=
51
+ github.com/shurcooL/highlight_go v0.0.0-20191220051317-782971ddf21b h1:rBIwpb5ggtqf0uZZY5BPs1sL7njUMM7I8qD2jiou70E=
52
+ github.com/shurcooL/highlight_go v0.0.0-20191220051317-782971ddf21b/go.mod h1:UDKB5a1T23gOMUJrI+uSuH0VRDStOiUVSjBTRDVBVag=
53
+ github.com/shurcooL/octicon v0.0.0-20191102190552-cbb32d6a785c h1:p3w+lTqXulfa3aDeycxmcLJDNxyUB89gf2/XqqK3eO0=
54
+ github.com/shurcooL/octicon v0.0.0-20191102190552-cbb32d6a785c/go.mod h1:eWdoE5JD4R5UVWDucdOPg1g2fqQRq78IQa9zlOV1vpQ=
55
+ github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo=
22
56
  github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
57
+ github.com/sourcegraph/annotate v0.0.0-20160123013949-f4cad6c6324d h1:yKm7XZV6j9Ev6lojP2XaIshpT4ymkqhMeSghO5Ps00E=
58
+ github.com/sourcegraph/annotate v0.0.0-20160123013949-f4cad6c6324d/go.mod h1:UdhH50NIW0fCiwBSr0co2m7BnFLdv4fQTgdqdJTHFeE=
59
+ github.com/sourcegraph/syntaxhighlight v0.0.0-20170531221838-bd320f5d308e h1:qpG93cPwA5f7s/ZPBJnGOYQNK/vKsaDaseuKT5Asee8=
60
+ github.com/sourcegraph/syntaxhighlight v0.0.0-20170531221838-bd320f5d308e/go.mod h1:HuIsMU8RRBOtsCgI77wP899iHVBQpCmg4ErYMZB+2IA=
23
61
  github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
62
+ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
24
63
  github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
25
64
  github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
26
65
  github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
27
66
  github.com/tj/assert v0.0.3 h1:Df/BlaZ20mq6kuai7f5z2TvPFiwC3xaWJSDQNiIS3Rk=
28
67
  github.com/tj/assert v0.0.3/go.mod h1:Ne6X72Q+TB1AteidzQncjw9PabbMp4PBMZ1k+vd1Pvk=
29
68
  github.com/urfave/cli/v2 v2.1.1/go.mod h1:SE9GqnLQmjVa0iPEY0f1w3ygNIYcIJ0OKPMoW2caLfQ=
69
+ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
70
+ golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
71
+ golang.org/x/mod v0.5.1 h1:OJxoQ/rynoF0dcCdI7cLPktw/hR2cueqYfjm43oqK38=
72
+ golang.org/x/mod v0.5.1/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro=
73
+ golang.org/x/net v0.0.0-20180218175443-cbe0f9307d01/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
74
+ golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
75
+ golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
76
+ golang.org/x/net v0.0.0-20210614182718-04defd469f4e/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
77
+ golang.org/x/net v0.0.0-20210917221730-978cfadd31cf h1:R150MpwJIv1MpS0N/pc+NhTM8ajzvlmxlY5OYsrevXQ=
78
+ golang.org/x/net v0.0.0-20210917221730-978cfadd31cf/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
79
+ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
80
+ golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
81
+ golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
82
+ golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
83
+ golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
84
+ golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
85
+ golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
86
+ golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
87
+ golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
88
+ golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
89
+ golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
90
+ golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898 h1:/atklqdjdhuosWIl6AIbOeHJjicWYPqR9bpxqxYG2pA=
91
+ golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
30
92
  gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
31
93
  gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
32
94
  gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
95
+ gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
33
96
  gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
97
+ gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
34
98
  gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
35
99
  gopkg.in/yaml.v3 v3.0.0-20200605160147-a5ece683394c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
36
100
  gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776 h1:tQIYjPdBoyREyB9XMu+nnTclpTYkz2zFM+lzLJFO4gQ=
html.go CHANGED
@@ -389,54 +389,3 @@ func MergeAttributes(parent *Element, uis ...interface{}) *Element {
389
389
  }
390
390
  return parent
391
391
  }
392
-
393
- // func UseData(name, data string) *Element {
394
- // return Script(Text(fmt.Sprintf(`
395
- // document.addEventListener('alpine:init', () => {
396
- // Alpine.data('%s', () => {
397
- // return %s;
398
- // });
399
- // });
400
- // `, name, data)))
401
- // }
402
-
403
- // func HTML(html string, data map[string]interface{}) string {
404
- // return fmt.Sprintf("")
405
- // }
406
-
407
- // func Counter2(start int) string {
408
- // data := map[string]interface{}{
409
- // "count": 1,
410
- // "names": []string{"123", "123"},
411
- // "increment": func() string {
412
- // return "this.count += 1;"
413
- // },
414
- // "decrement": func() string {
415
- // return "this.count -= 1;"
416
- // },
417
- // }
418
- // return HTML(`
419
- // <div class="flex flex-col justify-center items-center text-3xl text-gray-700">
420
- // <div class="flex flex-row justify-center items-center">
421
- // <div class="flex flex-row justify-center items-center underline">
422
- // Counter
423
- // </div>
424
- // </div>
425
- // <div class="flex flex-row justify-center items-center" x-data="counter">
426
- // <button @click="decrement" class="btn m-20">-</button>
427
- // <div class="flex flex-row justify-center items-center m-20">{{ count }}</div>
428
- // <button @click="increment" class="btn m-20">+</button>
429
- // </div>
430
- // <div>
431
- // {{#if true }}
432
- // render this
433
- // {{/if}}
434
- // </div>
435
- // <div>
436
- // {{#each names}}
437
- // <li>{{ @index }} - {{ @value }}</li>
438
- // {{/each}}
439
- // </div>
440
- // </div>
441
- // `, data)
442
- // }
readme.md CHANGED
@@ -7,72 +7,14 @@
7
7
  # wapp
8
8
 
9
9
  **wapp** is a framework to build web apps in golang.
10
- It uses a declarative syntax using funcs that allows creating and dealing with HTML elements only by using Go, and without writing any HTML markup.ZZZIt is highly opioninated and integrates uses tailwind css and alpinejs.
10
+ It uses a declarative syntax using funcs that allows creating and dealing with HTML elements only by using Go, and without writing any HTML markup. It is highly opioninated and integrates uses tailwind css and alpinejs.
11
11
 
12
12
  # Install
13
13
 
14
- **wapp** requirements:
15
-
16
- - [Go 1.16](https://golang.org/doc/go1.16)
17
-
18
14
  ```sh
19
15
  go mod init
20
16
  go get -u -v github.com/pyros2097/wapp
21
17
  ```
18
+ # Example
22
19
 
23
- [Demo](https://github.com/pyros2097/wapp-example)
20
+ https://github.com/pyros2097/wapp-example
24
-
25
- **Example**
26
-
27
- ```go
28
- package main
29
-
30
- import (
31
- . "github.com/pyros2097/wapp"
32
- )
33
-
34
- func Header() *Element {
35
- return Row(Css("w-full mb-20 font-bold text-xl text-gray-700 p-4"),
36
- Div(Css("text-blue-700"),
37
- A(Href("https://wapp.pyros2097.dev"), Text("wapp.pyros2097.dev")),
38
- ),
39
- Div(Css("flex flex-row flex-1 justify-end items-end p-2"),
40
- Div(Css("border-b-2 border-white text-lg text-blue-700 mr-4"), Text("Examples: ")),
41
- Div(Css("link mr-4"), A(Href("/"), Text("Home"))),
42
- Div(Css("link mr-4"), A(Href("/clock"), Text("Clock"))),
43
- Div(Css("link mr-4"), A(Href("/about"), Text("About"))),
44
- Div(Css("link mr-4"), A(Href("/container"), Text("Container"))),
45
- Div(Css("link mr-4"), A(Href("/panic"), Text("Panic"))),
46
- ),
47
- )
48
- }
49
-
50
- func Index(w http.ResponseWriter, r *http.Request) *Element {
51
- return Page(
52
- Col(
53
- Header(),
54
- H1(Text("Hello this is a h1")),
55
- H2(Text("Hello this is a h2")),
56
- H2(XData("{ message: 'I ❤️ Alpine' }"), XText("message"), Text("")),
57
- Col(Css("text-3xl text-gray-700"),
58
- Row(
59
- Row(Css("underline"),
60
- Text("Counter"),
61
- ),
62
- ),
63
- Row(
64
- Button(Css("btn m-20"),
65
- Text("-"),
66
- ),
67
- Row(Css("m-20"),
68
- Text(strconv.Itoa(1)),
69
- ),
70
- Button(Css("btn m-20"),
71
- Text("+"),
72
- ),
73
- ),
74
- ),
75
- ),
76
- )
77
- }
78
- ```