Skip to content

Commit a00f081

Browse files
committed
maint: ensure testdata is commited
1 parent 404e515 commit a00f081

File tree

9 files changed

+383
-0
lines changed

9 files changed

+383
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
**/*_gwirl.go
2+
!**/testdata/**/*_gwirl.go

gwirl/testdata/expected/base_gwirl.go

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package html
2+
3+
import "github.com/gamebox/gwirl/gwirl-example/flash"
4+
import (
5+
"strings"
6+
7+
"github.com/gamebox/gwirl"
8+
)
9+
10+
11+
func Base(flash *flash.Flash, title string, path string, embed string) string {
12+
sb_ := strings.Builder{}
13+
14+
sb_.WriteString(`
15+
<html lang="en" class="min-h-full">
16+
<head>
17+
<meta charset="UTF-8" />
18+
<meta name="description" content="Astro description" />
19+
<meta name="viewport" content="width=device-width" />
20+
<link rel="icon" type="image/svg+xml" href="/logo.svg" />
21+
<title>`)
22+
23+
gwirl.WriteEscapedHTML(&sb_, title)
24+
25+
sb_.WriteString(`</title>
26+
<link rel="stylesheet" href="/assets/timebox.css">
27+
<link rel="stylesheet" href="https://rsms.me/inter/inter.css">
28+
<style>
29+
html {
30+
--accent: 22, 163, 74;
31+
--tb-logo-stroke-color: rgb(var(--accent));
32+
`)
33+
34+
return sb_.String()
35+
}
+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package html
2+
3+
import (
4+
"strings"
5+
6+
"github.com/gamebox/gwirl"
7+
)
8+
9+
10+
func Layout(content string) string {
11+
sb_ := strings.Builder{}
12+
13+
if content == "" {
14+
sb_.WriteString(`
15+
<html></html>
16+
`)
17+
18+
}
19+
20+
sb_.WriteString(`
21+
<html>
22+
<head>
23+
`)
24+
25+
26+
27+
28+
sb_.WriteString(`
29+
<title>`)
30+
31+
gwirl.WriteEscapedHTML(&sb_, content)
32+
33+
sb_.WriteString(`!</title>
34+
</head>
35+
<body>
36+
<nav class="nav"></nav>
37+
<main>`)
38+
39+
gwirl.WriteEscapedHTML(&sb_, content)
40+
41+
sb_.WriteString(`</main>
42+
<footer></footer>
43+
</body>
44+
</html>
45+
`)
46+
47+
return sb_.String()
48+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
package html
2+
3+
import "github.com/gamebox/gwirl/gwirl-example/model"
4+
import (
5+
"strings"
6+
7+
"github.com/gamebox/gwirl"
8+
)
9+
10+
11+
func ManageParticipants(participants []model.Participant) string {
12+
sb_ := strings.Builder{}
13+
14+
sb_.WriteString(`
15+
<div class="title-container">
16+
<h1>Participant Manager</h1>
17+
<a class="action" target="_blank" href="/cpc/">New</a>
18+
</div>
19+
20+
<table class="list" cellspacing="0" cellpadding="0">
21+
<thead>
22+
<tr>
23+
<th>First Name</th>
24+
<th>Last Name</th>
25+
<th>Email</th>
26+
<th>Actions</th>
27+
</tr>
28+
</thead>
29+
<tbody>
30+
`)
31+
32+
if len(participants) == 0 {
33+
sb_.WriteString(`
34+
<tr>
35+
<td colspan="4">No participants</td>
36+
</tr>
37+
`)
38+
39+
}
40+
41+
sb_.WriteString(`
42+
`)
43+
44+
for _, participant := range participants {
45+
sb_.WriteString(`
46+
<tr>
47+
<td>`)
48+
49+
gwirl.WriteEscapedHTML(&sb_, participant.FirstName)
50+
51+
sb_.WriteString(`</td>
52+
<td>`)
53+
54+
gwirl.WriteEscapedHTML(&sb_, participant.LastName)
55+
56+
sb_.WriteString(`</td>
57+
<td>`)
58+
59+
gwirl.WriteEscapedHTML(&sb_, participant.Email)
60+
61+
sb_.WriteString(`</td>
62+
<td>
63+
<a href="#" class="action">Delete</a>
64+
<a href="/client/participant/`)
65+
66+
gwirl.WriteEscapedHTML(&sb_, participant.Id)
67+
68+
sb_.WriteString(`" class="action">Edit</a>
69+
</td>
70+
</tr>
71+
`)
72+
73+
}
74+
75+
sb_.WriteString(`
76+
</tbody>
77+
</table>
78+
`)
79+
80+
return sb_.String()
81+
}

gwirl/testdata/expected/nav_gwirl.go

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package html
2+
3+
import (
4+
"strings"
5+
6+
"github.com/gamebox/gwirl"
7+
)
8+
9+
10+
func Nav(path string) string {
11+
sb_ := strings.Builder{}
12+
13+
routes := []struct {
14+
label string
15+
path string
16+
}{}
17+
18+
19+
20+
sb_.WriteString(`
21+
<nav class="navbar">
22+
<ul>
23+
`)
24+
25+
for _, route := range routes {
26+
sb_.WriteString(`
27+
<li `)
28+
29+
if route.path == path {
30+
sb_.WriteString(` class="selected" `)
31+
32+
}
33+
34+
sb_.WriteString(`>`)
35+
36+
gwirl.WriteEscapedHTML(&sb_, route.label)
37+
38+
sb_.WriteString(`</li>
39+
`)
40+
41+
}
42+
43+
sb_.WriteString(`
44+
</ul>
45+
</nav>
46+
`)
47+
48+
return sb_.String()
49+
}
+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package html
2+
3+
import (
4+
"strings"
5+
6+
"github.com/gamebox/gwirl"
7+
)
8+
9+
10+
func TestAll(name string, index int) string {
11+
sb_ := strings.Builder{}
12+
13+
sb_.WriteString(`<div `)
14+
15+
if index == 0 {
16+
sb_.WriteString(` class="first" `)
17+
18+
}
19+
20+
sb_.WriteString(`>
21+
`)
22+
23+
if index > 0 {
24+
sb_.WriteString(`
25+
<hr />
26+
`)
27+
28+
}
29+
30+
sb_.WriteString(`
31+
<h2>`)
32+
33+
gwirl.WriteEscapedHTML(&sb_, name)
34+
35+
sb_.WriteString(`</h2>
36+
</div>
37+
`)
38+
39+
return sb_.String()
40+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package html
2+
3+
import (
4+
"strings"
5+
6+
"github.com/gamebox/gwirl"
7+
)
8+
9+
10+
func Transcluded(name string, index int) string {
11+
sb_ := strings.Builder{}
12+
13+
var foo string
14+
if index % 2 == 0 {
15+
foo = "even"
16+
} else {
17+
foo = "odd"
18+
}
19+
20+
21+
22+
sb_.WriteString(`
23+
24+
`)
25+
26+
var transclusion__12__1 string
27+
{
28+
sb_ := strings.Builder{}
29+
sb_.WriteString(`
30+
<div>
31+
`)
32+
33+
if index > 0 {
34+
sb_.WriteString(`
35+
<hr />
36+
`)
37+
38+
}
39+
40+
sb_.WriteString(`
41+
<h2>`)
42+
43+
gwirl.WriteEscapedHTML(&sb_, name)
44+
45+
sb_.WriteString(`</h2>
46+
<h3>`)
47+
48+
gwirl.WriteEscapedHTML(&sb_, foo)
49+
50+
sb_.WriteString(`</h3>
51+
<script>
52+
document.body.addEventListener("load", () => {`)
53+
54+
transclusion__12__1 = sb_.String()
55+
}
56+
gwirl.WriteEscapedHTML(&sb_, Layout(transclusion__12__1))
57+
58+
59+
sb_.WriteString(`)
60+
</script>
61+
</div>
62+
`)
63+
64+
return sb_.String()
65+
}
+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package html
2+
3+
import (
4+
"strings"
5+
6+
"github.com/gamebox/gwirl"
7+
)
8+
9+
10+
func UseOther(names []string) string {
11+
sb_ := strings.Builder{}
12+
13+
sb_.WriteString(`<div>
14+
`)
15+
16+
for i, name := range names {
17+
sb_.WriteString(`
18+
`)
19+
20+
gwirl.WriteEscapedHTML(&sb_, TestAll(name, i))
21+
22+
sb_.WriteString(`
23+
`)
24+
25+
}
26+
27+
sb_.WriteString(`
28+
</div>
29+
`)
30+
31+
return sb_.String()
32+
}

internal/gen/testdata/simple_gwirl.go

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package views
2+
3+
import (
4+
"strings"
5+
6+
"github.com/gamebox/gwirl"
7+
)
8+
9+
10+
func Testing(name string, index int) string {
11+
sb_ := strings.Builder{}
12+
13+
sb_.WriteString(`<div>
14+
`)
15+
16+
if if index > 0 {
17+
sb_.WriteString(`
18+
<hr />
19+
`)
20+
21+
}
22+
23+
sb_.WriteString(`
24+
<h2>`)
25+
26+
gwirl.WriteEscapedHTML(&sb_, name)
27+
28+
sb_.WriteString(`</h2>
29+
`)
30+
31+
return sb_.String()
32+
}

0 commit comments

Comments
 (0)