├── .gitignore
├── example
├── components
│ ├── App.css
│ └── App.go
├── favicon.ico
├── main.wasm
├── build_from_go.sh
├── index.go
├── build_from_tinygo.sh
├── master.css
├── index.html
└── .air.toml
├── assets
└── logo.png
├── go.mod
├── go.sum
├── LICENSE
├── utils
└── utils.go
├── gooroo_test.go
├── dom
└── dom.go
├── README.md
└── gooroo.go
/.gitignore:
--------------------------------------------------------------------------------
1 | /**/tmp
2 | /**/*.js
3 | /**/.vscode
--------------------------------------------------------------------------------
/example/components/App.css:
--------------------------------------------------------------------------------
1 | .title {
2 | color: cornflowerblue;
3 | }
--------------------------------------------------------------------------------
/assets/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Matbabs/Gooroo/HEAD/assets/logo.png
--------------------------------------------------------------------------------
/example/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Matbabs/Gooroo/HEAD/example/favicon.ico
--------------------------------------------------------------------------------
/example/main.wasm:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Matbabs/Gooroo/HEAD/example/main.wasm
--------------------------------------------------------------------------------
/example/build_from_go.sh:
--------------------------------------------------------------------------------
1 | cp "$(go env GOROOT)/misc/wasm/wasm_exec.js" . && GOOS=js GOARCH=wasm go build -o ./main.wasm
--------------------------------------------------------------------------------
/go.mod:
--------------------------------------------------------------------------------
1 | module github.com/Matbabs/Gooroo
2 |
3 | go 1.18
4 |
5 | require github.com/lithammer/shortuuid v3.0.0+incompatible
6 |
7 | require github.com/google/uuid v1.3.0 // indirect
8 |
--------------------------------------------------------------------------------
/example/index.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | o "github.com/Matbabs/Gooroo"
5 | "github.com/Matbabs/Gooroo/example/components"
6 | )
7 |
8 | func main() {
9 | o.Render(func() {
10 | o.Html(
11 | components.App(),
12 | )
13 | })
14 | }
15 |
--------------------------------------------------------------------------------
/example/build_from_tinygo.sh:
--------------------------------------------------------------------------------
1 | cp $(tinygo env TINYGOROOT)/targets/wasm_exec.js . && tinygo build -o main.wasm -target wasm --no-debug index.go
2 | file_to_modify="wasm_exec.js"
3 | string_to_replace="console.error('syscall/js.finalizeRef not implemented');"
4 | sed -i "s@$string_to_replace@@" "$file_to_modify"
--------------------------------------------------------------------------------
/go.sum:
--------------------------------------------------------------------------------
1 | github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
2 | github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
3 | github.com/lithammer/shortuuid v3.0.0+incompatible h1:NcD0xWW/MZYXEHa6ITy6kaXN5nwm/V115vj2YXfhS0w=
4 | github.com/lithammer/shortuuid v3.0.0+incompatible/go.mod h1:FR74pbAuElzOUuenUHTK2Tciko1/vKuIKS9dSkDrA4w=
5 |
--------------------------------------------------------------------------------
/example/master.css:
--------------------------------------------------------------------------------
1 | @import url("https://fonts.googleapis.com/css2?family=JetBrains+Mono&display=swap");
2 |
3 | *,
4 | ::before,
5 | ::after {
6 | box-sizing: border-box;
7 | font-family: "JetBrains Mono", monospace;
8 | }
9 |
10 | html,
11 | body {
12 | margin: 0;
13 | padding: 0;
14 | overflow: hidden;
15 | }
16 |
17 | input,
18 | button,
19 | select {
20 | padding: 8px;
21 | }
22 |
--------------------------------------------------------------------------------
/example/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | Example Gooroo
4 |
5 |
6 |
7 |
8 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/example/.air.toml:
--------------------------------------------------------------------------------
1 | root = "."
2 | testdata_dir = "testdata"
3 | tmp_dir = "tmp"
4 |
5 | [build]
6 | args_bin = []
7 | bin = "/bin/echo 'Gooroo ready !'"
8 | cmd = "cp "$(go env GOROOT)/misc/wasm/wasm_exec.js" . && GOOS=js GOARCH=wasm go build -o ./main.wasm"
9 | delay = 0
10 | exclude_dir = ["assets", "tmp", "vendor", "testdata"]
11 | exclude_file = []
12 | exclude_regex = ["_test.go"]
13 | exclude_unchanged = false
14 | follow_symlink = false
15 | full_bin = ""
16 | include_dir = []
17 | include_ext = ["go", "tpl", "tmpl", "html"]
18 | kill_delay = "0s"
19 | log = "build-errors.log"
20 | send_interrupt = false
21 | stop_on_error = true
22 |
23 | [color]
24 | app = ""
25 | build = "blue"
26 | main = "magenta"
27 | runner = "cyan"
28 | watcher = "yellow"
29 |
30 | [log]
31 | time = false
32 |
33 | [misc]
34 | clean_on_exit = false
35 |
36 | [screen]
37 | clear_on_rebuild = false
38 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright 2022 BABONNEAU Matisse
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4 |
5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6 |
7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
8 |
--------------------------------------------------------------------------------
/utils/utils.go:
--------------------------------------------------------------------------------
1 | // This package describes the private utility and generic functions to the other methods of the main gooroo package.
2 | package utils
3 |
4 | import (
5 | "fmt"
6 | "strings"
7 | )
8 |
9 | // Check for the presence of a 'string' in a '[]string'.
10 | func Contains(s []string, str string) bool {
11 | for _, v := range s {
12 | if v == str {
13 | return true
14 | }
15 | }
16 | return false
17 | }
18 |
19 | // Initializes a value in a map if and only if it does not exist.
20 | func MapInit[T any](key string, _map map[string]T, value T) {
21 | _, isPresent := _map[key]
22 | if !isPresent {
23 | _map[key] = value
24 | }
25 | }
26 |
27 | // Initializes a function (value) in a map if and only if it does not exist.
28 | func MapInitCallback[T any](key string, _map map[string]T, callback func() T) {
29 | _, isPresent := _map[key]
30 | if !isPresent {
31 | _map[key] = callback()
32 | }
33 | }
34 |
35 | // Formatting a string for key management
36 | func CallerToKey(file string, no int) string {
37 | splitFile := strings.Split(file, "/")
38 | return fmt.Sprintf("%s#%d", splitFile[len(splitFile)-1], no)
39 | }
40 |
41 | // Convert 'any' type to 'string'.
42 | func AnyStr(v any) string {
43 | return fmt.Sprintf("%v", v)
44 | }
45 |
--------------------------------------------------------------------------------
/example/components/App.go:
--------------------------------------------------------------------------------
1 | package components
2 |
3 | import (
4 | "fmt"
5 | "syscall/js"
6 |
7 | o "github.com/Matbabs/Gooroo"
8 | )
9 |
10 | type Person struct {
11 | name string
12 | age string
13 | }
14 |
15 | func App() o.DomComponent {
16 |
17 | o.Css("components/App.css")
18 |
19 | name, _ := o.UseState("Paul")
20 | age, _ := o.UseState("42")
21 | p, setP := o.UseState(Person{(*name).(string), (*age).(string)})
22 |
23 | o.UseEffect(func() {
24 | fmt.Println("When person changed !")
25 | }, p)
26 |
27 | handleChange := func(_ js.Value) {
28 | fmt.Println("OnChange callback")
29 | fmt.Println(*name)
30 | }
31 |
32 | handleSubmit := func(_ js.Value) {
33 | setP(Person{(*name).(string), (*age).(string)})
34 | }
35 |
36 | return o.Div(o.Style("margin: auto; padding: 100px; width: 800px"),
37 | o.H1(
38 | "Tuto Gooroo web front Go ! v0.1.8",
39 | o.ClassName("title"),
40 | ),
41 | o.H2("Form"),
42 | o.Div(o.GridLayout(3, 0, "20px"),
43 | o.Span("Name"),
44 | o.Span("Age"),
45 | o.Span(""),
46 | o.Input(o.OnChange(name, handleChange)),
47 | o.Input(o.OnChange(age), o.Type("number")),
48 | o.Button("Click", o.OnClick(handleSubmit), o.Title("")),
49 | ),
50 | o.H2("From Store"),
51 | o.Div(o.FlexLayout("row", "left", "center", "20px"),
52 | o.P((*name).(string)),
53 | o.P((*age).(string)),
54 | ),
55 | o.H2("From State"),
56 | o.Div(o.FlexLayout("row", "left", "center", "20px"),
57 | o.P((*p).(Person).name),
58 | o.P((*p).(Person).age),
59 | ),
60 | )
61 | }
62 |
--------------------------------------------------------------------------------
/gooroo_test.go:
--------------------------------------------------------------------------------
1 | // GOOS=js GOARCH=wasm go test -cover -o example/main.wasm
2 |
3 | package gooroo
4 |
5 | import (
6 | "fmt"
7 | "strings"
8 | "syscall/js"
9 | "testing"
10 |
11 | "github.com/Matbabs/Gooroo/dom"
12 | )
13 |
14 | type test struct {
15 | name string
16 | function func(t *testing.T)
17 | }
18 |
19 | var head js.Value
20 | var body js.Value
21 |
22 | var tests = []test{
23 | {
24 | "Css",
25 | func(t *testing.T) {
26 | path := "./master.css"
27 | Css(path)
28 | href := head.Get(dom.JS_CHILDREN).Get("4").Get(dom.JS_HREF).String()
29 | if !strings.Contains(href, "master.css") {
30 | t.Error("master.css not exist in href")
31 | }
32 | },
33 | },
34 | {
35 | "Html void",
36 | func(t *testing.T) {
37 | Html()
38 | length := body.Get(dom.JS_CHILDREN).Get(dom.JS_LENGTH).String()
39 | if !strings.Contains(length, "number: 1") {
40 | t.Error("Body has different number of child than expected")
41 | }
42 | },
43 | },
44 | {
45 | "Html children",
46 | func(t *testing.T) {
47 | title := "Test title !"
48 | paragraph := "Paragraph test"
49 | Html(
50 | Div(
51 | H1(title),
52 | P(paragraph),
53 | ),
54 | )
55 | div := body.Get(dom.JS_CHILDREN).Get("1").Get(dom.JS_CHILDREN).Get("0")
56 | h1 := div.Get(dom.JS_CHILDREN).Get("0").Get(dom.JS_INNER_HTML)
57 | p := div.Get(dom.JS_CHILDREN).Get("1").Get(dom.JS_INNER_HTML)
58 | if title != h1.String() || paragraph != p.String() {
59 | t.Error("Innerhtml does not contain expected value")
60 | }
61 | },
62 | },
63 | {
64 | "sanitizeHtml",
65 | func(t *testing.T) {
66 | str := ""
67 | sanitizeHtml(&str)
68 | if strings.Contains(str, "
427 |
436 |
437 |
438 |