test more examples
This commit is contained in:
parent
349d07c691
commit
b65a913d4e
9 changed files with 89 additions and 27 deletions
|
|
@ -372,8 +372,8 @@ func Label(children ...Ren) *Element {
|
||||||
return Tag("label", children...)
|
return Tag("label", children...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func IFrame(src string) *Element {
|
func IFrame(src string, children ...Ren) *Element {
|
||||||
return Tag("iframe", Src(src))
|
return Tag("iframe", children...).AppendChildren(Src(src))
|
||||||
}
|
}
|
||||||
|
|
||||||
func Address(children ...Ren) *Element {
|
func Address(children ...Ren) *Element {
|
||||||
|
|
|
||||||
10
htmgo-site/pages/snippets/chat.go
Normal file
10
htmgo-site/pages/snippets/chat.go
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
package snippets
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/maddalax/htmgo/framework/h"
|
||||||
|
)
|
||||||
|
|
||||||
|
func ChatExample(ctx *h.RequestContext) *h.Page {
|
||||||
|
SetSnippet(ctx, &ChatSnippet)
|
||||||
|
return Index(ctx)
|
||||||
|
}
|
||||||
|
|
@ -22,7 +22,7 @@ func getFunctionFilePath(fn interface{}) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetGithubPath(path string) string {
|
func GetGithubPath(path string) string {
|
||||||
return fmt.Sprintf("https://github.com/maddalax/htmgo/blob/master%s", path)
|
return fmt.Sprintf("https://github.com/maddalax/htmgo/tree/master/htmgo-site/partials%s.go", path)
|
||||||
}
|
}
|
||||||
|
|
||||||
func RenderCodeToString(partial h.PartialFunc) *h.Element {
|
func RenderCodeToString(partial h.PartialFunc) *h.Element {
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,8 @@ type Snippet struct {
|
||||||
sidebarName string
|
sidebarName string
|
||||||
path string
|
path string
|
||||||
partial h.PartialFunc
|
partial h.PartialFunc
|
||||||
|
externalRoute string
|
||||||
|
sourceCodePath string
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetSnippet(ctx *h.RequestContext, snippet *Snippet) {
|
func SetSnippet(ctx *h.RequestContext, snippet *Snippet) {
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,6 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func FormExample(ctx *h.RequestContext) *h.Page {
|
func FormExample(ctx *h.RequestContext) *h.Page {
|
||||||
SetSnippet(ctx, &FormWithLoadingState)
|
SetSnippet(ctx, &FormWithLoadingStateSnippet)
|
||||||
return Index(ctx)
|
return Index(ctx)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -65,7 +65,15 @@ func snippetView(snippet *Snippet) *h.Element {
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
h.Div(
|
h.Div(
|
||||||
h.Class("border px-8 py-4 rounded-md shadow-sm border-slate-200 w-full"),
|
h.ClassX("border px-8 py-4 rounded-md shadow-sm border-slate-200 w-full", map[string]bool{
|
||||||
|
"mb-6": snippet.externalRoute == "",
|
||||||
|
}),
|
||||||
|
h.IfElse(
|
||||||
|
snippet.externalRoute != "",
|
||||||
|
h.IFrame(
|
||||||
|
snippet.externalRoute,
|
||||||
|
h.Class("h-full min-h-[800px] w-[50vw]"),
|
||||||
|
),
|
||||||
h.Div(
|
h.Div(
|
||||||
h.Get(
|
h.Get(
|
||||||
h.GetPartialPath(snippet.partial),
|
h.GetPartialPath(snippet.partial),
|
||||||
|
|
@ -73,21 +81,33 @@ func snippetView(snippet *Snippet) *h.Element {
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
h.Div(
|
h.Div(
|
||||||
h.Class("mt-8 flex flex-col gap-2 justify-center"),
|
h.Class("flex flex-col gap-2 justify-center"),
|
||||||
h.Div(
|
h.Div(
|
||||||
h.Class("flex gap-2 items-center"),
|
h.Class("flex gap-2 items-center"),
|
||||||
h.A(
|
h.A(
|
||||||
|
h.Fragment(
|
||||||
githubLogo(),
|
githubLogo(),
|
||||||
h.Href(GetGithubPath(snippet.path)),
|
h.If(
|
||||||
h.Class("font-sm text-blue-500 hover:text-blue-400"),
|
snippet.externalRoute != "",
|
||||||
|
h.Text("View source"),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
|
h.Href(
|
||||||
|
h.Ternary(snippet.sourceCodePath == "", GetGithubPath(snippet.path), snippet.sourceCodePath),
|
||||||
|
),
|
||||||
|
h.Class("flex gap-1 items-center font-sm text-blue-500 hover:text-blue-400"),
|
||||||
|
),
|
||||||
|
h.If(
|
||||||
|
snippet.externalRoute == "",
|
||||||
h.H3(
|
h.H3(
|
||||||
h.Text("Source Code"),
|
h.Text("Source Code"),
|
||||||
h.Class("text-lg font-bold"),
|
h.Class("text-lg font-bold"),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
RenderCodeToString(snippet.partial),
|
),
|
||||||
|
h.If(snippet.externalRoute == "", RenderCodeToString(snippet.partial)),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
@ -98,7 +118,7 @@ func emptyState() *h.Element {
|
||||||
h.Div(
|
h.Div(
|
||||||
h.Class("flex gap-2 items-center"),
|
h.Class("flex gap-2 items-center"),
|
||||||
h.H3(
|
h.H3(
|
||||||
h.Text("Choose a snippet on the sidebar to view"),
|
h.Text("Choose an example on the sidebar to view"),
|
||||||
h.Class("text-lg"),
|
h.Class("text-lg"),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ func SnippetSidebar() *h.Element {
|
||||||
h.Class("mb-3"),
|
h.Class("mb-3"),
|
||||||
h.A(
|
h.A(
|
||||||
h.Href("#"),
|
h.Href("#"),
|
||||||
h.Text("Snippets"),
|
h.Text("Examples"),
|
||||||
h.Class("md:mt-4 text-xl text-slate-900 font-bold"),
|
h.Class("md:mt-4 text-xl text-slate-900 font-bold"),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"htmgo-site/partials/snippets"
|
"htmgo-site/partials/snippets"
|
||||||
)
|
)
|
||||||
|
|
||||||
var FormWithLoadingState = Snippet{
|
var FormWithLoadingStateSnippet = Snippet{
|
||||||
name: "Form",
|
name: "Form",
|
||||||
description: "A simple form submission example with a loading state",
|
description: "A simple form submission example with a loading state",
|
||||||
sidebarName: "Form with loading state",
|
sidebarName: "Form with loading state",
|
||||||
|
|
@ -12,6 +12,26 @@ var FormWithLoadingState = Snippet{
|
||||||
partial: snippets.FormExample,
|
partial: snippets.FormExample,
|
||||||
}
|
}
|
||||||
|
|
||||||
var Snippets = []Snippet{
|
var UserAuthSnippet = Snippet{
|
||||||
FormWithLoadingState,
|
name: "User Authentication",
|
||||||
|
description: "An example showing basic user registration and login with htmgo",
|
||||||
|
sidebarName: "User Authentication",
|
||||||
|
path: "/snippets/user-auth",
|
||||||
|
externalRoute: "https://auth-example.htmgo.dev",
|
||||||
|
sourceCodePath: "https://github.com/maddalax/htmgo/tree/master/examples/simple-auth",
|
||||||
|
}
|
||||||
|
|
||||||
|
var ChatSnippet = Snippet{
|
||||||
|
name: "Chat App",
|
||||||
|
description: "A simple chat application built with htmgo",
|
||||||
|
sidebarName: "Chat App",
|
||||||
|
path: "/snippets/chat",
|
||||||
|
externalRoute: "https://chat-example.htmgo.dev",
|
||||||
|
sourceCodePath: "https://github.com/maddalax/htmgo/tree/master/examples/chat",
|
||||||
|
}
|
||||||
|
|
||||||
|
var Snippets = []Snippet{
|
||||||
|
FormWithLoadingStateSnippet,
|
||||||
|
UserAuthSnippet,
|
||||||
|
ChatSnippet,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
10
htmgo-site/pages/snippets/user-auth.go
Normal file
10
htmgo-site/pages/snippets/user-auth.go
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
package snippets
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/maddalax/htmgo/framework/h"
|
||||||
|
)
|
||||||
|
|
||||||
|
func UserAuthExample(ctx *h.RequestContext) *h.Page {
|
||||||
|
SetSnippet(ctx, &UserAuthSnippet)
|
||||||
|
return Index(ctx)
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue