{"id":37193492,"url":"https://github.com/codekoala/templ-component-opts","last_synced_at":"2026-01-14T22:27:39.448Z","repository":{"id":214188805,"uuid":"734860106","full_name":"codekoala/templ-component-opts","owner":"codekoala","description":"Generate code for templ component option structs.","archived":false,"fork":false,"pushed_at":"2023-12-26T23:58:23.000Z","size":25,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-11-22T19:03:36.912Z","etag":null,"topics":["go","gogenerate","golang","templ"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/codekoala.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2023-12-22T20:46:15.000Z","updated_at":"2024-06-23T13:15:27.000Z","dependencies_parsed_at":"2023-12-26T14:40:24.552Z","dependency_job_id":"dd21326e-fab8-48b2-a3c9-04f45c382993","html_url":"https://github.com/codekoala/templ-component-opts","commit_stats":null,"previous_names":["codekoala/templ-component-opts"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/codekoala/templ-component-opts","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codekoala%2Ftempl-component-opts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codekoala%2Ftempl-component-opts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codekoala%2Ftempl-component-opts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codekoala%2Ftempl-component-opts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/codekoala","download_url":"https://codeload.github.com/codekoala/templ-component-opts/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codekoala%2Ftempl-component-opts/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28436382,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T21:32:52.117Z","status":"ssl_error","status_checked_at":"2026-01-14T21:32:33.442Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["go","gogenerate","golang","templ"],"created_at":"2026-01-14T22:27:38.698Z","updated_at":"2026-01-14T22:27:39.424Z","avatar_url":"https://github.com/codekoala.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Templ Component Opts\n\nThis project is designed to help generate code to simplify passing options to a [templ component](https://github.com/a-h/templ).\n\nRather than creating templ components that take multiple parameters, they can instead take a single parameters that includes the various bits of context that are important for the component.\n\nFor example:\n\n```templ\n// example/view/index.templ\npackage view\n\nimport (\n    \"time\"\n\n    \"github.com/codekoala/templ-component-opts/example/view/component/book\"\n)\n\ntempl Index() {\n    \u003chtml\u003e\n        \u003cbody\u003e\n            @book.Book(book.With(\n                book.Title(\"1984\"),\n                book.Author(\"George Orwell\"),\n                book.Published(MustParse(\"June 8, 1949\")),\n            ))\n\n            @book.Book(book.With(\n                book.Display(false),\n                book.Title(\"Dune\"),\n                book.Author(\"Frank Herbert\"),\n                book.Published(MustParse(\"August 1, 1965\")),\n            ))\n        \u003c/body\u003e\n    \u003c/html\u003e\n}\n\n// MustParse parses a date or panics.\nfunc MustParse(value string) time.Time {\n    val, err := time.Parse(\"January 2, 2006\", value)\n    if  err != nil {\n        panic(err)\n    }\n    return val\n}\n```\n\n## Installation\n\nYou can install `templ-component-opts` using the `go install` command:\n\n```sh\n$ go install github.com/codekoala/templ-component-opts@latest\n```\n\nThis will download and install the executable in your `$GOPATH/bin` directory.\n\n## Usage\n\nTo use `templ-component-opts`, simply create a struct with the various options that you may want to pass to a templ component and include the `//templ:component-opts` directive:\n\n```go\n// example/view/component/book/book.go\npackage book\n\nimport \"time\"\n\n// Opts defines options for the Book templ component.\n//\n//templ:component-opts\ntype Opts struct {\n\tTitle     string\n\tAuthor    string\n\tPublished time.Time\n\tDisplay   bool `default:\"true\"`\n}\n```\n\nAs illustrated by teh `Display` field, default values can be specified using the `default` tag.\n\nRun the `templ-component-opts` tool pointing to the project directory:\n\n```sh\n$ templ-component-opts .\n```\n\nThis will produce a new file with the suffix `_tcogen.go`:\n\n```go\n// example/view/component/book/book_tcogen.go\n// Code generated by templ-component-opts; DO NOT EDIT.\n// This file contains functions and methods for use with Opts in templ components.\npackage book\n\nimport (\n\t\"strconv\"\n\t\"time\"\n)\n\ntype Opt func(*Opts)\n\nfunc DefaultOpts() *Opts {\n\tout := \u0026Opts{Display: true}\n\treturn out\n}\nfunc With(opts ...Opt) *Opts {\n\tout := DefaultOpts()\n\tout.With(opts...)\n\treturn out\n}\nfunc (o *Opts) With(opts ...Opt) *Opts {\n\tfor _, opt := range opts {\n\t\topt(o)\n\t}\n\treturn o\n}\n\nfunc Title(in string) Opt {\n\treturn func(opts *Opts) {\n\t\topts.Title = in\n\t}\n}\n\nfunc Author(in string) Opt {\n\treturn func(opts *Opts) {\n\t\topts.Author = in\n\t}\n}\n\nfunc Published(in time.Time) Opt {\n\treturn func(opts *Opts) {\n\t\topts.Published = in\n\t}\n}\n\nfunc Display(in bool) Opt {\n\treturn func(opts *Opts) {\n\t\topts.Display = in\n\t}\n}\n\nfunc (o *Opts) DisplayStr() string {\n\treturn strconv.FormatBool(o.Display)\n}\n```\n\nIn the interest of keeping things as simple as possible, package level functions are created to populate fields in the annotated struct. For some data types, such as `int64`, `float64`, and `bool`, additional methods are generated on the struct to return a stringified version of the field.\n\n## `go generate`\n\nAdd a single `//go:generate templ-component-opts .` in your project, and `go generate` should automatically produce the `_tcogen.go` files for any struct with the `//templ:component-opts` directive.\n\n## License\n\nThis project is licensed under the MIT License. See the [LICENSE](./LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodekoala%2Ftempl-component-opts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodekoala%2Ftempl-component-opts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodekoala%2Ftempl-component-opts/lists"}