Skip to content

Commit 81e6ac5

Browse files
Merge pull request #1 from johnsiilver/README
Readme and examples
2 parents b49744d + da8f044 commit 81e6ac5

46 files changed

Lines changed: 1894 additions & 150 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 561 additions & 0 deletions
Large diffs are not rendered by default.

component/component.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,6 @@ var scriptTemplateTxt = `
148148
document.body.replaceChild(newcomp, old);
149149
}
150150
}
151-
console.log("hello world");
152151
{{.Self.LoaderName}}();
153152
</script>
154153
{{ end }}
@@ -231,7 +230,7 @@ func New(name string, doc *html.Doc, options ...Option) (*Gear, error) {
231230
for walked := range html.Walker(walkCtx, doc.Body) {
232231
if g, ok := walked.Element.(*Gear); ok {
233232
cancel()
234-
return nil, fmt.Errorf("WebGear Component(%s) had another component(%s) added directly to the passed *html.Doc," +
233+
return nil, fmt.Errorf("WebGear Component(%s) had another component(%s) added directly to the passed *html.Doc,"+
235234
"this can only be added using the component.AddGear() option to allow correct rendered ordering", name, g.name)
236235
}
237236
}
@@ -263,7 +262,7 @@ func (g *Gear) TagType() template.HTMLAttr {
263262
// to HTML with this name (output with TemplateName() and LoaderName()), but we still need a way
264263
// to reference them in our Doc tree. This is that ID.
265264
func (g *Gear) GearID() string {
266-
return "gear-"+ g.name
265+
return "gear-" + g.name
267266
}
268267

269268
// LoaderName is the name of the JS function that defines the HTML custom element and causes the custom element to render.

component/viewer/viewer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,4 +160,4 @@ func (v *Viewer) Run() {
160160
log.Printf("http server serving on :%d", v.port)
161161

162162
log.Fatal(server.ListenAndServe())
163-
}
163+
}

component/viewer/wasm/wasm.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ import (
44
"fmt"
55
"log"
66
"net/http"
7-
"time"
7+
"net/url"
88
"os"
99
"os/exec"
1010
"path/filepath"
11-
"net/url"
1211
"sync"
12+
"time"
1313

1414
"github.com/johnsiilver/webgear/handlers"
1515
wasmHTTP "github.com/johnsiilver/webgear/wasm/http"
@@ -18,8 +18,8 @@ import (
1818
// Viewer provides an HTTP server that will run to view an individual component that
1919
// is inside a wasm binary.
2020
type Viewer struct {
21-
port int
22-
binName string
21+
port int
22+
binName string
2323
useModules bool
2424

2525
mu sync.Mutex
@@ -56,9 +56,9 @@ func UseModules() Option {
5656
// relaunched by simply hitting 'r' in the terminal.
5757
func New(port int, binName string, options ...Option) *Viewer {
5858
v := &Viewer{
59-
port: port,
59+
port: port,
6060
binName: binName,
61-
h: handlers.New(handlers.DoNotCache()),
61+
h: handlers.New(handlers.DoNotCache()),
6262
}
6363

6464
for _, o := range options {
@@ -69,7 +69,7 @@ func New(port int, binName string, options ...Option) *Viewer {
6969
panic(err)
7070
}
7171

72-
u, err := url.Parse("/static/viewer/main/"+binName)
72+
u, err := url.Parse("/static/viewer/main/" + binName)
7373
if err != nil {
7474
panic(err)
7575
}
@@ -94,7 +94,7 @@ func (v *Viewer) build() error {
9494

9595
if v.useModules {
9696
os.Setenv("GO111MODULE", "on")
97-
}else{
97+
} else {
9898
os.Setenv("GO111MODULE", "off")
9999
}
100100
os.Setenv("GOOS", "js")
@@ -114,18 +114,18 @@ func (v *Viewer) build() error {
114114
// Run runs the viewer and will block forever.
115115
func (v *Viewer) Run() {
116116
// disable input buffering
117-
exec.Command("stty", "-F", "/dev/tty", "cbreak", "min", "1").Run()
117+
exec.Command("stty", "-F", "/dev/tty", "cbreak", "min", "1").Run()
118118
go func() {
119119
var b []byte = make([]byte, 1)
120120
for {
121121
os.Stdin.Read(b)
122122
if string(b) == "r" {
123123
if err := v.build(); err == nil {
124124
fmt.Println("wasm rebuild SUCCEEDED, reload web browser")
125-
}else{
125+
} else {
126126
fmt.Println("wasm rebuild FAILED: ", err)
127127
}
128-
}else{
128+
} else {
129129
fmt.Printf("I don't know what %q is\n", string(b))
130130
}
131131
}
@@ -142,4 +142,4 @@ func (v *Viewer) Run() {
142142
log.Printf("http server serving on :%d", v.port)
143143

144144
log.Fatal(server.ListenAndServe())
145-
}
145+
}

go.mod

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ require (
77
github.com/grpc-ecosystem/grpc-gateway v1.14.8
88
github.com/johnsiilver/go_basics v0.0.0-20200612183708-9254a13bbede
99
github.com/kylelemons/godebug v1.1.0
10-
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826
11-
github.com/ulule/deepcopier v0.0.0-20200430083143-45decc6639b6
12-
golang.org/x/net v0.0.0-20200602114024-627f9648deb9
1310
google.golang.org/genproto v0.0.0-20200513103714-09dca8ec2884
1411
google.golang.org/grpc v1.31.1
1512
google.golang.org/protobuf v1.23.0

go.sum

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw
2727
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
2828
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
2929
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
30+
github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4=
3031
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
3132
github.com/grpc-ecosystem/grpc-gateway v1.14.8 h1:hXClj+iFpmLM8i3lkO6i4Psli4P2qObQuQReiII26U8=
3233
github.com/grpc-ecosystem/grpc-gateway v1.14.8/go.mod h1:NZE8t6vs6TnwLL/ITkaK8W3ecMLGAbh2jXTclvpiwYo=
@@ -36,17 +37,14 @@ github.com/johnsiilver/go_basics v0.0.0-20200612183708-9254a13bbede/go.mod h1:ro
3637
github.com/johnsiilver/webgear v0.0.0-20200612182948-28632aac6009/go.mod h1:cMq7KURJVuft5RBIFcKdgbFiB74D4JXL6PDD5kZNHZ0=
3738
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
3839
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
39-
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9M+97sNutRR1RKhG96O6jWumTTnw=
40-
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8=
40+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
4141
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
4242
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
4343
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
4444
github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q=
4545
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
4646
github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo=
4747
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
48-
github.com/ulule/deepcopier v0.0.0-20200430083143-45decc6639b6 h1:TtyC78WMafNW8QFfv3TeP3yWNDG+uxNkk9vOrnDu6JA=
49-
github.com/ulule/deepcopier v0.0.0-20200430083143-45decc6639b6/go.mod h1:h8272+G2omSmi30fBXiZDMkmHuOgonplfKIKjQWzlfs=
5048
github.com/yosssi/gohtml v0.0.0-20200519115854-476f5b4b8047/go.mod h1:+ccdNT0xMY1dtc5XBxumbYfOUhmduiGudqaDgD2rVRE=
5149
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
5250
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
@@ -70,13 +68,15 @@ golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJ
7068
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
7169
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
7270
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
71+
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd h1:xhmwyvizuTgC2qz7ZlMluP20uW+C3Rm0FD/WLDX8884=
7372
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
7473
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
7574
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
7675
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
7776
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
7877
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
7978
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
79+
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
8080
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
8181
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
8282
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
@@ -97,6 +97,7 @@ google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miE
9797
google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
9898
google.golang.org/protobuf v1.23.0 h1:4MY060fB1DLGMB/7MBTLnwQUY6+F09GEiz6SsrNqyzM=
9999
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
100+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
100101
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
101102
gopkg.in/yaml.v2 v2.2.3 h1:fvjTMHxHEw/mxHbtzPi3JCcKXQRAnQTBRo6YCJSVHKI=
102103
gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

html/a.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ var aTmpl = template.Must(template.New("a").Parse(strings.TrimSpace(`
6666
// A defines a hyperlink, which is used to link from one page to another.
6767
type A struct {
6868
// Href specifies the URL of the page the link goes to.
69-
Href string
69+
Href *url.URL
7070
// Download specifies that the target will be downloaded when a user clicks on the hyperlink.
7171
Download bool `html:"attr"`
7272
// HrefLang specifies the language of the linked document.

html/a_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func TestA(t *testing.T) {
2727
GlobalAttrs: GlobalAttrs{
2828
AccessKey: "key",
2929
},
30-
Href: "/subpage",
30+
Href: URLParse("/subpage"),
3131
Download: true,
3232
HrefLang: "english",
3333
Media: "query",

html/body.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,13 @@ func (b *Body) validate() error {
5151
if b == nil {
5252
return fmt.Errorf("Body element is not defined")
5353
}
54+
for _, e := range b.Elements {
55+
v, ok := e.(validator)
56+
if ok {
57+
if err := v.validate(); err != nil {
58+
return err
59+
}
60+
}
61+
}
5462
return nil
5563
}

html/body_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func TestBody(t *testing.T) {
2727
Elements: []Element{
2828
&Div{
2929
Elements: []Element{
30-
&A{Href: "/subpage", Elements: []Element{TextElement("hello")}},
30+
&A{Href: URLParse("/subpage"), Elements: []Element{TextElement("hello")}},
3131
},
3232
},
3333
},

0 commit comments

Comments
 (0)