Skip to content

Commit b65a913

Browse files
committed
test more examples
1 parent 349d07c commit b65a913

File tree

9 files changed

+88
-26
lines changed

9 files changed

+88
-26
lines changed

framework/h/tag.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,8 +372,8 @@ func Label(children ...Ren) *Element {
372372
return Tag("label", children...)
373373
}
374374

375-
func IFrame(src string) *Element {
376-
return Tag("iframe", Src(src))
375+
func IFrame(src string, children ...Ren) *Element {
376+
return Tag("iframe", children...).AppendChildren(Src(src))
377377
}
378378

379379
func Address(children ...Ren) *Element {

htmgo-site/pages/snippets/chat.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package snippets
2+
3+
import (
4+
"github.com/maddalax/htmgo/framework/h"
5+
)
6+
7+
func ChatExample(ctx *h.RequestContext) *h.Page {
8+
SetSnippet(ctx, &ChatSnippet)
9+
return Index(ctx)
10+
}

htmgo-site/pages/snippets/code.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func getFunctionFilePath(fn interface{}) string {
2222
}
2323

2424
func GetGithubPath(path string) string {
25-
return fmt.Sprintf("https://github.com/maddalax/htmgo/blob/master%s", path)
25+
return fmt.Sprintf("https://github.com/maddalax/htmgo/tree/master/htmgo-site/partials%s.go", path)
2626
}
2727

2828
func RenderCodeToString(partial h.PartialFunc) *h.Element {

htmgo-site/pages/snippets/data.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ package snippets
33
import "github.com/maddalax/htmgo/framework/h"
44

55
type Snippet struct {
6-
name string
7-
description string
8-
sidebarName string
9-
path string
10-
partial h.PartialFunc
6+
name string
7+
description string
8+
sidebarName string
9+
path string
10+
partial h.PartialFunc
11+
externalRoute string
12+
sourceCodePath string
1113
}
1214

1315
func SetSnippet(ctx *h.RequestContext, snippet *Snippet) {

htmgo-site/pages/snippets/form.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ import (
55
)
66

77
func FormExample(ctx *h.RequestContext) *h.Page {
8-
SetSnippet(ctx, &FormWithLoadingState)
8+
SetSnippet(ctx, &FormWithLoadingStateSnippet)
99
return Index(ctx)
1010
}

htmgo-site/pages/snippets/index.go

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -65,29 +65,49 @@ func snippetView(snippet *Snippet) *h.Element {
6565
),
6666
),
6767
h.Div(
68-
h.Class("border px-8 py-4 rounded-md shadow-sm border-slate-200 w-full"),
69-
h.Div(
70-
h.Get(
71-
h.GetPartialPath(snippet.partial),
72-
"load",
68+
h.ClassX("border px-8 py-4 rounded-md shadow-sm border-slate-200 w-full", map[string]bool{
69+
"mb-6": snippet.externalRoute == "",
70+
}),
71+
h.IfElse(
72+
snippet.externalRoute != "",
73+
h.IFrame(
74+
snippet.externalRoute,
75+
h.Class("h-full min-h-[800px] w-[50vw]"),
76+
),
77+
h.Div(
78+
h.Get(
79+
h.GetPartialPath(snippet.partial),
80+
"load",
81+
),
7382
),
7483
),
7584
),
7685
h.Div(
77-
h.Class("mt-8 flex flex-col gap-2 justify-center"),
86+
h.Class("flex flex-col gap-2 justify-center"),
7887
h.Div(
7988
h.Class("flex gap-2 items-center"),
8089
h.A(
81-
githubLogo(),
82-
h.Href(GetGithubPath(snippet.path)),
83-
h.Class("font-sm text-blue-500 hover:text-blue-400"),
90+
h.Fragment(
91+
githubLogo(),
92+
h.If(
93+
snippet.externalRoute != "",
94+
h.Text("View source"),
95+
),
96+
),
97+
h.Href(
98+
h.Ternary(snippet.sourceCodePath == "", GetGithubPath(snippet.path), snippet.sourceCodePath),
99+
),
100+
h.Class("flex gap-1 items-center font-sm text-blue-500 hover:text-blue-400"),
84101
),
85-
h.H3(
86-
h.Text("Source Code"),
87-
h.Class("text-lg font-bold"),
102+
h.If(
103+
snippet.externalRoute == "",
104+
h.H3(
105+
h.Text("Source Code"),
106+
h.Class("text-lg font-bold"),
107+
),
88108
),
89109
),
90-
RenderCodeToString(snippet.partial),
110+
h.If(snippet.externalRoute == "", RenderCodeToString(snippet.partial)),
91111
),
92112
)
93113
}
@@ -98,7 +118,7 @@ func emptyState() *h.Element {
98118
h.Div(
99119
h.Class("flex gap-2 items-center"),
100120
h.H3(
101-
h.Text("Choose a snippet on the sidebar to view"),
121+
h.Text("Choose an example on the sidebar to view"),
102122
h.Class("text-lg"),
103123
),
104124
),

htmgo-site/pages/snippets/sidebar.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ func SnippetSidebar() *h.Element {
1212
h.Class("mb-3"),
1313
h.A(
1414
h.Href("#"),
15-
h.Text("Snippets"),
15+
h.Text("Examples"),
1616
h.Class("md:mt-4 text-xl text-slate-900 font-bold"),
1717
),
1818
),

htmgo-site/pages/snippets/snippets.go

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,34 @@ import (
44
"htmgo-site/partials/snippets"
55
)
66

7-
var FormWithLoadingState = Snippet{
7+
var FormWithLoadingStateSnippet = Snippet{
88
name: "Form",
99
description: "A simple form submission example with a loading state",
1010
sidebarName: "Form with loading state",
1111
path: "/snippets/form",
1212
partial: snippets.FormExample,
1313
}
1414

15+
var UserAuthSnippet = Snippet{
16+
name: "User Authentication",
17+
description: "An example showing basic user registration and login with htmgo",
18+
sidebarName: "User Authentication",
19+
path: "/snippets/user-auth",
20+
externalRoute: "https://auth-example.htmgo.dev",
21+
sourceCodePath: "https://github.com/maddalax/htmgo/tree/master/examples/simple-auth",
22+
}
23+
24+
var ChatSnippet = Snippet{
25+
name: "Chat App",
26+
description: "A simple chat application built with htmgo",
27+
sidebarName: "Chat App",
28+
path: "/snippets/chat",
29+
externalRoute: "https://chat-example.htmgo.dev",
30+
sourceCodePath: "https://github.com/maddalax/htmgo/tree/master/examples/chat",
31+
}
32+
1533
var Snippets = []Snippet{
16-
FormWithLoadingState,
34+
FormWithLoadingStateSnippet,
35+
UserAuthSnippet,
36+
ChatSnippet,
1737
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package snippets
2+
3+
import (
4+
"github.com/maddalax/htmgo/framework/h"
5+
)
6+
7+
func UserAuthExample(ctx *h.RequestContext) *h.Page {
8+
SetSnippet(ctx, &UserAuthSnippet)
9+
return Index(ctx)
10+
}

0 commit comments

Comments
 (0)