From 56c20d76dd7beceb0c62c02dcfe118ed074cb6bc Mon Sep 17 00:00:00 2001 From: RealAlexandreAI Date: Sun, 19 May 2024 13:53:08 +0800 Subject: [PATCH] Schema --- .github/ISSUE_TEMPLATE/bug-report---.md | 9 ++- .github/ISSUE_TEMPLATE/feature-request---.md | 3 + .github/workflows/ci.yaml | 4 +- .github/workflows/golangci-lint.yml | 6 +- .pre-commit-config.yaml | 10 --- README.md | 76 ++++++++++++++++---- component/button.templ | 6 +- component/button_templ.go | 19 +++-- component/example_pool.go | 44 ++++++++++++ component/index.templ | 59 +++++++-------- component/index_templ.go | 15 ++-- component/list.templ | 19 +++-- component/list_templ.go | 22 ++++-- component/main.templ | 35 +++++---- component/main_templ.go | 17 +++-- component/schema.go | 62 ++++++++++++++++ component/textarea.templ | 15 ++-- component/textarea_templ.go | 20 ++++-- component/wrapper.templ | 8 +-- go.mod | 3 +- go.sum | 6 +- handler.go | 45 ++++++++++++ loader.go | 62 ---------------- 23 files changed, 371 insertions(+), 194 deletions(-) create mode 100644 component/example_pool.go create mode 100644 component/schema.go create mode 100644 handler.go delete mode 100644 loader.go diff --git a/.github/ISSUE_TEMPLATE/bug-report---.md b/.github/ISSUE_TEMPLATE/bug-report---.md index e74e7d0..767afc6 100644 --- a/.github/ISSUE_TEMPLATE/bug-report---.md +++ b/.github/ISSUE_TEMPLATE/bug-report---.md @@ -6,17 +6,22 @@ labels: bug --- ## Describe the bug + A clear and concise description of what the bug is. ### Steps to reproduce + Steps to reproduce the behavior. ### Expected behavior + A clear and concise description of what you expected to happen. ### Environment - - OS: [e.g. Arch Linux] - - Other details that you think may affect. + +- OS: [e.g. Arch Linux] +- Other details that you think may affect. ### Additional context + Add any other context about the problem here. \ No newline at end of file diff --git a/.github/ISSUE_TEMPLATE/feature-request---.md b/.github/ISSUE_TEMPLATE/feature-request---.md index 3bd987c..7697447 100644 --- a/.github/ISSUE_TEMPLATE/feature-request---.md +++ b/.github/ISSUE_TEMPLATE/feature-request---.md @@ -6,10 +6,13 @@ labels: enhancement --- ## Summary + Brief explanation of the feature. ### Basic example + Include a basic example or links here. ### Motivation + Why are we doing this? What use cases does it support? What is the expected outcome? \ No newline at end of file diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 40241bc..ae2e064 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -5,7 +5,7 @@ on: branches: - main pull_request: - types: [opened, synchronize, reopened] + types: [ opened, synchronize, reopened ] jobs: build: @@ -14,7 +14,7 @@ jobs: strategy: fail-fast: false matrix: - go-version: ['1.21', '1.22'] + go-version: [ '1.21', '1.22' ] env: VERBOSE: 1 diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index e974bf9..68f9024 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -5,7 +5,7 @@ on: - main - master pull_request: - types: [opened, synchronize, reopened] + types: [ opened, synchronize, reopened ] permissions: contents: read @@ -16,8 +16,8 @@ jobs: golangci: strategy: matrix: - go: ['1.21', '1.22'] - os: [macos-latest] + go: [ '1.21', '1.22' ] + os: [ macos-latest ] name: lint runs-on: ${{ matrix.os }} steps: diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index ae7aeb2..5982455 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,15 +4,5 @@ repos: hooks: - id: go-fmt - id: go-vet - - id: go-lint - - id: go-imports - - id: go-cyclo - args: [-over=15] - - id: validate-toml - - id: no-go-testing - - id: golangci-lint - - id: go-critic - - id: go-unit-tests - - id: go-build - id: go-mod-tidy diff --git a/README.md b/README.md index cca6237..9f9554c 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,3 @@ - + ## 🖌Generative UI in Golang, based on HTMX and Templ, is useful in Multi-Agent Systems. ### 🌟 Reasons to Choose gen-ui-go -🌐 Continuously Updated UI Component Library: Our UI component library is constantly expanding, offering the latest design elements and features to help developers keep their applications modern while maintaining high performance and elegance. +🌐 Continuously Updated UI Component Library: Our UI component library is constantly expanding, offering the latest +design elements and features to help developers keep their applications modern while maintaining high performance and +elegance. -🖥️ Full Backend Rendering: gen-ui-go implements full backend rendering, ensuring data security and privacy. This makes it particularly suitable for scenarios that require a high degree of data control and customized rendering logic. +🖥️ Full Backend Rendering: gen-ui-go implements full backend rendering, ensuring data security and privacy. This makes +it particularly suitable for scenarios that require a high degree of data control and customized rendering logic. -🤖 Multi-Agent Planning Support: gen-ui-go supports multi-agent systems, allowing different agents to participate in UI planning and decision-making processes, providing robust support for complex interactions and automated workflows. +🤖 Multi-Agent Planning Support: gen-ui-go supports multi-agent systems, allowing different agents to participate in UI +planning and decision-making processes, providing robust support for complex interactions and automated workflows. -🔄 Interactivity in Semi-Automatic Workflows: In semi-automatic workflows, gen-ui-go offers the capability for real-time interaction, allowing users to dynamically adjust and optimize during the running process, thereby improving efficiency and responsiveness. +🔄 Interactivity in Semi-Automatic Workflows: In semi-automatic workflows, gen-ui-go offers the capability for real-time +interaction, allowing users to dynamically adjust and optimize during the running process, thereby improving efficiency +and responsiveness. -🔧 Suitable for Dynamic Environments: Whether it's a fast-paced agile development environment or a finely controlled production environment, gen-ui-go provides the tools and flexibility needed to adapt to various development requirements. +🔧 Suitable for Dynamic Environments: Whether it's a fast-paced agile development environment or a finely controlled +production environment, gen-ui-go provides the tools and flexibility needed to adapt to various development +requirements. ### Intro -## Updates +## Updates ### Timeline + ### Card + ### Conversation + +### Audio/Image/Video + ### Button + ### List -### Textarea +### Textarea + ## 🏁 Getting Started + To add the gen-ui-go to your Go project, use the following command: + + + +To register more components as examples: + ``` -// TODO Register here + +templ Button(text string) { + +} + +func init(){ + RegisterExample("/button", Button("Click Me!")) +} + +templ generate ``` + ## Roadmap - [x] Basic feature - [ ] Modern CSS like bulma -- [ ] Registry like otel collector +- [x] Registry Example +- [ ] Registry with Schema - [ ] More components - -See the [open issues](https://github.com/RealAlexandreAI/gen-ui-go/issues) for a full list of proposed features (and known issues). +See the [open issues](https://github.com/RealAlexandreAI/gen-ui-go/issues) for a full list of proposed features (and +known issues).

(back to top)

+ ## Contributing -Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are **greatly appreciated**. +Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any +contributions you make are **greatly appreciated**. -If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". +If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also +simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again! 1. Fork the Project @@ -112,6 +147,7 @@ Don't forget to give the project a star! Thanks again!

(back to top)

+ ## License Distributed under the GPLv3 License. See `LICENSE` for more information. @@ -121,6 +157,7 @@ Distributed under the GPLv3 License. See `LICENSE` for more information. + ## Contact RealAlexandreAI - [@RealAlexandreAI](https://twitter.com/RealAlexandreAI) @@ -132,16 +169,27 @@ Project Link: [https://github.com/RealAlexandreAI/gen-ui-go](https://github.com/ + [contributors-shield]: https://img.shields.io/github/contributors/RealAlexandreAI/gen-ui-go.svg?style=for-the-badge + [contributors-url]: https://github.com/RealAlexandreAI/gen-ui-go/graphs/contributors + [forks-shield]: https://img.shields.io/github/forks/RealAlexandreAI/gen-ui-go.svg?style=for-the-badge + [forks-url]: https://github.com/RealAlexandreAI/gen-ui-go/network/members + [stars-shield]: https://img.shields.io/github/stars/RealAlexandreAI/gen-ui-go.svg?style=for-the-badge + [stars-url]: https://github.com/RealAlexandreAI/gen-ui-go/stargazers + [issues-shield]: https://img.shields.io/github/issues/RealAlexandreAI/gen-ui-go.svg?style=for-the-badge + [issues-url]: https://github.com/RealAlexandreAI/gen-ui-go/issues + [license-shield]: https://img.shields.io/github/license/RealAlexandreAI/gen-ui-go.svg?style=for-the-badge + [license-url]: https://github.com/RealAlexandreAI/gen-ui-go/blob/master/LICENSE + [product-screenshot]: images/screenshot.png diff --git a/component/button.templ b/component/button.templ index 2ddb236..bc1e049 100644 --- a/component/button.templ +++ b/component/button.templ @@ -1,5 +1,9 @@ package component templ Button(text string) { - + +} + +func init() { + RegisterExample("/button", Button("Click Me!")) } diff --git a/component/button_templ.go b/component/button_templ.go index 5ec83c8..e7f5e85 100644 --- a/component/button_templ.go +++ b/component/button_templ.go @@ -5,10 +5,13 @@ package component //lint:file-ignore SA4006 This context is only used if a nested component is present. -import "github.com/a-h/templ" -import "context" -import "io" -import "bytes" +import ( + "bytes" + "context" + "io" + + "github.com/a-h/templ" +) func Button(text string) templ.Component { return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { @@ -23,14 +26,14 @@ func Button(text string) templ.Component { templ_7745c5c3_Var1 = templ.NopComponent } ctx = templ.ClearChildren(ctx) - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(" - - - - - - -
-
- -
-
- +
+
+ + + +
+
+
+
+
} -templ Style(){ - -} \ No newline at end of file +} diff --git a/component/index_templ.go b/component/index_templ.go index c5a4104..d9c7edd 100644 --- a/component/index_templ.go +++ b/component/index_templ.go @@ -5,10 +5,13 @@ package component //lint:file-ignore SA4006 This context is only used if a nested component is present. -import "github.com/a-h/templ" -import "context" -import "io" -import "bytes" +import ( + "bytes" + "context" + "io" + + "github.com/a-h/templ" +) func BodyContent() templ.Component { return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { @@ -23,7 +26,7 @@ func BodyContent() templ.Component { templ_7745c5c3_Var1 = templ.NopComponent } ctx = templ.ClearChildren(ctx) - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -47,7 +50,7 @@ func Style() templ.Component { templ_7745c5c3_Var2 = templ.NopComponent } ctx = templ.ClearChildren(ctx) - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } diff --git a/component/list.templ b/component/list.templ index 51ab82e..649144c 100644 --- a/component/list.templ +++ b/component/list.templ @@ -1,9 +1,18 @@ package component templ List(texts []string) { - + +} + +func init() { + RegisterExample("/list", List([]string{ + "ListItem1", + "ListItem2", + "ListItem3", + "ListItem4", + })) } diff --git a/component/list_templ.go b/component/list_templ.go index 80689f6..9fc1d1b 100644 --- a/component/list_templ.go +++ b/component/list_templ.go @@ -5,10 +5,13 @@ package component //lint:file-ignore SA4006 This context is only used if a nested component is present. -import "github.com/a-h/templ" -import "context" -import "io" -import "bytes" +import ( + "bytes" + "context" + "io" + + "github.com/a-h/templ" +) func List(texts []string) templ.Component { return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { @@ -35,7 +38,7 @@ func List(texts []string) templ.Component { var templ_7745c5c3_Var2 string templ_7745c5c3_Var2, templ_7745c5c3_Err = templ.JoinStringErrs(text) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `component/list.templ`, Line: 6, Col: 21} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `list.templ`, Line: 6, Col: 13} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var2)) if templ_7745c5c3_Err != nil { @@ -56,3 +59,12 @@ func List(texts []string) templ.Component { return templ_7745c5c3_Err }) } + +func init() { + RegisterExample("/list", List([]string{ + "ListItem1", + "ListItem2", + "ListItem3", + "ListItem4", + })) +} diff --git a/component/main.templ b/component/main.templ index e00fb12..877bb35 100644 --- a/component/main.templ +++ b/component/main.templ @@ -1,24 +1,23 @@ package component - templ Layout(title string, metaTags templ.Component) { - - - - @Style() - - - - @metaTags - { title } - - -
- @BodyContent() -
- - - + + + + @Style() + + + + @metaTags + { title } + + +
+ @BodyContent() +
+ + + } templ MetaTags(keywords, description string) { diff --git a/component/main_templ.go b/component/main_templ.go index 0b8f2e5..b365bd5 100644 --- a/component/main_templ.go +++ b/component/main_templ.go @@ -5,10 +5,13 @@ package component //lint:file-ignore SA4006 This context is only used if a nested component is present. -import "github.com/a-h/templ" -import "context" -import "io" -import "bytes" +import ( + "bytes" + "context" + "io" + + "github.com/a-h/templ" +) func Layout(title string, metaTags templ.Component) templ.Component { return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { @@ -46,7 +49,7 @@ func Layout(title string, metaTags templ.Component) templ.Component { var templ_7745c5c3_Var2 string templ_7745c5c3_Var2, templ_7745c5c3_Err = templ.JoinStringErrs(title) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `component/main.templ`, Line: 13, Col: 20} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `main.templ`, Line: 12, Col: 17} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var2)) if templ_7745c5c3_Err != nil { @@ -108,7 +111,7 @@ func MetaTags(keywords, description string) templ.Component { var templ_7745c5c3_Var5 string templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinStringErrs(keywords) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `component/main.templ`, Line: 25, Col: 41} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `main.templ`, Line: 24, Col: 41} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var5)) if templ_7745c5c3_Err != nil { @@ -121,7 +124,7 @@ func MetaTags(keywords, description string) templ.Component { var templ_7745c5c3_Var6 string templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.JoinStringErrs(description) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `component/main.templ`, Line: 26, Col: 47} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `main.templ`, Line: 25, Col: 47} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var6)) if templ_7745c5c3_Err != nil { diff --git a/component/schema.go b/component/schema.go new file mode 100644 index 0000000..e980948 --- /dev/null +++ b/component/schema.go @@ -0,0 +1,62 @@ +package component + +import ( + "encoding/json" + "fmt" +) + +type Metadata struct { + ExamplePath string +} + +type Input interface { + any + fmt.Stringer + json.Marshaler + json.Unmarshaler + Payload() any +} + +type Component interface { + Metadata() Metadata + Input() Input +} + +type payload = any + +type WrappedInput struct { + payload `json:",inline"` +} + +func (wi WrappedInput) String() string { + switch v := wi.payload.(type) { + case fmt.Stringer: + return v.String() + default: + return fmt.Sprintf("%v", v) + } +} + +func (wi WrappedInput) MarshalJSON() ([]byte, error) { + return json.Marshal(wi.payload) +} + +func (wi WrappedInput) UnmarshalJSON(b []byte) error { + return json.Unmarshal(b, &wi.payload) +} + +func (wi WrappedInput) Payload() any { + return wi.payload +} + +func WrapInput(p any) Input { + return WrappedInput{payload: p} +} + +func UnwrapInput(i Input, ref any) error { + b, err := i.MarshalJSON() + if err != nil { + return err + } + return json.Unmarshal(b, ref) +} diff --git a/component/textarea.templ b/component/textarea.templ index 80852dd..4030c96 100644 --- a/component/textarea.templ +++ b/component/textarea.templ @@ -1,9 +1,14 @@ package component templ Textarea(label, text string) { - -
- + +
+ +} + +func init() { + RegisterExample("/textarea", Textarea("TextArea label here.", + `"The quick brown fox jumps over the lazy dog" is an English-language pangram — a sentence that contains all the letters of the alphabet. The phrase is commonly used for touch-typing practice, testing typewriters and computer keyboards, displaying examples of fonts, and other applications involving text where the use of all letters in the alphabet is desired.`)) } diff --git a/component/textarea_templ.go b/component/textarea_templ.go index f4243de..f6ad784 100644 --- a/component/textarea_templ.go +++ b/component/textarea_templ.go @@ -5,10 +5,13 @@ package component //lint:file-ignore SA4006 This context is only used if a nested component is present. -import "github.com/a-h/templ" -import "context" -import "io" -import "bytes" +import ( + "bytes" + "context" + "io" + + "github.com/a-h/templ" +) func Textarea(label, text string) templ.Component { return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { @@ -30,7 +33,7 @@ func Textarea(label, text string) templ.Component { var templ_7745c5c3_Var2 string templ_7745c5c3_Var2, templ_7745c5c3_Err = templ.JoinStringErrs(label) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `component/textarea.templ`, Line: 4, Col: 40} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `textarea.templ`, Line: 4, Col: 37} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var2)) if templ_7745c5c3_Err != nil { @@ -43,7 +46,7 @@ func Textarea(label, text string) templ.Component { var templ_7745c5c3_Var3 string templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(text) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `component/textarea.templ`, Line: 7, Col: 10} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `textarea.templ`, Line: 7, Col: 8} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3)) if templ_7745c5c3_Err != nil { @@ -59,3 +62,8 @@ func Textarea(label, text string) templ.Component { return templ_7745c5c3_Err }) } + +func init() { + RegisterExample("/textarea", Textarea("TextArea label here.", + `"The quick brown fox jumps over the lazy dog" is an English-language pangram — a sentence that contains all the letters of the alphabet. The phrase is commonly used for touch-typing practice, testing typewriters and computer keyboards, displaying examples of fonts, and other applications involving text where the use of all letters in the alphabet is desired.`)) +} diff --git a/component/wrapper.templ b/component/wrapper.templ index 514ecbd..d9773ee 100644 --- a/component/wrapper.templ +++ b/component/wrapper.templ @@ -1,7 +1,7 @@ package component templ Wrap(orig templ.Component) { -
- @orig -
-} \ No newline at end of file +
+ @orig +
+} diff --git a/go.mod b/go.mod index 32080aa..4767510 100644 --- a/go.mod +++ b/go.mod @@ -4,9 +4,10 @@ go 1.21 require ( github.com/a-h/templ v0.2.680 + github.com/emirpasic/gods/v2 v2.0.0-alpha github.com/gin-gonic/gin v1.10.0 github.com/joho/godotenv v1.5.1 - github.com/samber/lo v1.38.1 + github.com/samber/lo v1.39.0 ) require ( diff --git a/go.sum b/go.sum index 63e4728..cf77985 100644 --- a/go.sum +++ b/go.sum @@ -11,6 +11,8 @@ github.com/cloudwego/iasm v0.2.0/go.mod h1:8rXZaNYT2n95jn+zTI1sDr+IgcD2GVs0nlbbQ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/emirpasic/gods/v2 v2.0.0-alpha h1:dwFlh8pBg1VMOXWGipNMRt8v96dKAIvBehtCt6OtunU= +github.com/emirpasic/gods/v2 v2.0.0-alpha/go.mod h1:W0y4M2dtBB9U5z3YlghmpuUhiaZT2h6yoeE+C1sCp6A= github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0= github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk= github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= @@ -51,8 +53,8 @@ github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6 github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/samber/lo v1.38.1 h1:j2XEAqXKb09Am4ebOg31SpvzUTTs6EN3VfgeLUhPdXM= -github.com/samber/lo v1.38.1/go.mod h1:+m/ZKRl6ClXCE2Lgf3MsQlWfh4bn1bz6CXEOxnEXnEA= +github.com/samber/lo v1.39.0 h1:4gTz1wUhNYLhFSKl6O+8peW0v2F4BCY034GRpU9WnuA= +github.com/samber/lo v1.39.0/go.mod h1:+m/ZKRl6ClXCE2Lgf3MsQlWfh4bn1bz6CXEOxnEXnEA= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= diff --git a/handler.go b/handler.go new file mode 100644 index 0000000..3eb5d8b --- /dev/null +++ b/handler.go @@ -0,0 +1,45 @@ +package main + +import ( + "github.com/RealAlexandreAI/gen-ui-go/component" + "github.com/a-h/templ" + "github.com/gin-gonic/gin" +) + +// loadHandlers +// +// @Description: +// @param r +func loadHandlers(r *gin.Engine) { + + r.GET("/", func(c *gin.Context) { + metaTags := component.MetaTags( + "gowebly, htmx example page, go with htmx", + "Welcome to example! You're here because it worked out.", + ) + + indexTemplate := component.Layout( + "Welcome to example!", + metaTags, + ) + + _ = indexTemplate.Render(c, c.Writer) + + }) + + componentRouter := r.Group("component") + + loadExamples(componentRouter) +} + +// loadExamples +// +// @Description: +// @param router +func loadExamples(router *gin.RouterGroup) { + component.ExamplePool.Each(func(key string, value templ.Component) { + router.GET(key, func(c *gin.Context) { + _ = component.Wrap(value).Render(c, c.Writer) + }) + }) +} diff --git a/loader.go b/loader.go deleted file mode 100644 index 8dd292a..0000000 --- a/loader.go +++ /dev/null @@ -1,62 +0,0 @@ -package main - -import ( - "github.com/RealAlexandreAI/gen-ui-go/component" - "github.com/gin-gonic/gin" -) - -// loadHandlers -// -// @Description: -// @param r -func loadHandlers(r *gin.Engine) { - - r.GET("/", func(c *gin.Context) { - metaTags := component.MetaTags( - "gowebly, htmx example page, go with htmx", - "Welcome to example! You're here because it worked out.", - ) - - indexTemplate := component.Layout( - "Welcome to example!", - metaTags, - ) - - _ = indexTemplate.Render(c, c.Writer) - - }) - - componentRouter := r.Group("component") - - loadComponents(componentRouter) -} - -// loadComponents -// -// @Description: -// @param router -func loadComponents(router *gin.RouterGroup) { - - router.GET("/button", func(c *gin.Context) { - comp := component.Button("Click Me!") - _ = component.Wrap(comp).Render(c, c.Writer) - }) - - router.GET("/list", func(c *gin.Context) { - comp := component.List([]string{ - "ListItem1", - "ListItem2", - "ListItem3", - "ListItem4", - }) - _ = component.Wrap(comp).Render(c, c.Writer) - }) - - router.GET("/textarea", func(c *gin.Context) { - comp := component.Textarea( - "TextArea label here.", - `"The quick brown fox jumps over the lazy dog" is an English-language pangram — a sentence that contains all the letters of the alphabet. The phrase is commonly used for touch-typing practice, testing typewriters and computer keyboards, displaying examples of fonts, and other applications involving text where the use of all letters in the alphabet is desired.`) - _ = component.Wrap(comp).Render(c, c.Writer) - }) - -}