{"id":13615195,"url":"https://github.com/stephenlacy/daz","last_synced_at":"2025-03-15T12:30:26.868Z","repository":{"id":49178404,"uuid":"319690413","full_name":"stephenlacy/daz","owner":"stephenlacy","description":"Composable HTML components in Golang","archived":false,"fork":false,"pushed_at":"2023-04-19T14:07:53.000Z","size":683,"stargazers_count":201,"open_issues_count":0,"forks_count":6,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-05-21T13:05:04.396Z","etag":null,"topics":["components","golang","html","template"],"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/stephenlacy.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}},"created_at":"2020-12-08T16:05:00.000Z","updated_at":"2024-03-26T13:10:03.000Z","dependencies_parsed_at":"2023-07-27T22:49:23.751Z","dependency_job_id":null,"html_url":"https://github.com/stephenlacy/daz","commit_stats":null,"previous_names":["stephenlacy/daz","stevelacy/daz"],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stephenlacy%2Fdaz","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stephenlacy%2Fdaz/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stephenlacy%2Fdaz/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stephenlacy%2Fdaz/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stephenlacy","download_url":"https://codeload.github.com/stephenlacy/daz/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243730827,"owners_count":20338723,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["components","golang","html","template"],"created_at":"2024-08-01T20:01:10.451Z","updated_at":"2025-03-15T12:30:26.451Z","avatar_url":"https://github.com/stephenlacy.png","language":"Go","readme":"# daz\n\u003e Composable HTML components in Golang\n\n\u003cp align=\"center\"\u003e\n\t\u003cimg src=\"https://github.com/stevelacy/daz/raw/master/daz.go.png\" width=\"300\"\u003e\n\u003c/p\u003e\n\n[![GoDoc](https://godoc.org/github.com/stevelacy/daz?status.svg)](https://godoc.org/github.com/stevelacy/daz)![Go](https://github.com/stevelacy/daz/workflows/Go/badge.svg)\n\n\n![daz carbon example](./carbon.png)\n\nDaz is a \"functional\" alternative to using templates, and allows for nested components/lists\nAlso enables template-free server-side rendered components with support for nested lists. It is inspired by [HyperScript](https://github.com/hyperhype/hyperscript).\n\n\nA component can be created and used with simple functions:\n```golang\n// Example prop for a component\ntype User struct {\n\tName string\n\t// ...\n}\n\nfunc MyComponent(user User) HTML {\n\treturn H(\n\t\t\"div\",\n\t\tAttr{\"class\": \"bg-grey-50\"},\n\t\tuser.Name,\n\t)\n}\n\nfunc Root() HTML {\n\tuser := User{Name: \"Daz\"}\n\treturn H(\"html\", MyComponent(user))\n}\n\n// And used in a handler:\n\nfunc Handler(w http.ResponseWriter, r *http.Request) {\n\tw.Write([]byte(Root()()))\n}\n```\n\nLists can be easily created without needing to embed a `range / end` in a template:\n```golang\nitems := []HTML{\n\tH(\"li\", \"item one\"),\n\tH(\"li\", \"item two\"),\n}\n\nelement := H(\"ul\", Attr{\"class\": \"bg-grey-50\"}, items)\n\ndiv := H(\"div\", element)\n```\n\n\n### Install\n\n```\nimport (\n\t\"github.com/stevelacy/daz\"\n)\n\n```\n\n### Usage\n\n#### func `H`\n\nCreate a HTML element:\n```golang\nH(\"div\", ...attrs)\n\n```\n\n#### struct `Attr`\n\nHTML attributes:\n```golang\nAttr{\n\t\"class\": \"app\",\n\t\"onClick\": \"javascriptFunc()\",\n}\n```\n\n#### func `UnsafeContent`\n\nThis will bypass HTML sanitization and allow for direct injecting\n```golang\n\ninjection := \"\u003cscript\u003ealert('xss')\u003c/script\u003e\"\nroot := H(\"div\", UnsafeContent(injection))\n// \u003cscript\u003ealert('xss')\u003c/script\u003e\n```\n","funding_links":[],"categories":["Go"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstephenlacy%2Fdaz","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstephenlacy%2Fdaz","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstephenlacy%2Fdaz/lists"}