{"id":19675596,"url":"https://github.com/notnite/htmlua","last_synced_at":"2025-04-29T02:30:40.444Z","repository":{"id":216342297,"uuid":"741062301","full_name":"NotNite/htmlua","owner":"NotNite","description":"Serverside website rendering in vanilla Lua with the redbean web server","archived":false,"fork":false,"pushed_at":"2024-05-02T17:58:52.000Z","size":36,"stargazers_count":15,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-05T12:42:02.313Z","etag":null,"topics":["redbean"],"latest_commit_sha":null,"homepage":"","language":"Lua","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/NotNite.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,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-01-09T16:12:51.000Z","updated_at":"2025-03-31T14:04:32.000Z","dependencies_parsed_at":"2024-05-02T19:01:11.624Z","dependency_job_id":"4a178d52-89ba-4abb-a475-93eed818c06a","html_url":"https://github.com/NotNite/htmlua","commit_stats":null,"previous_names":["notnite/htmlua"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NotNite%2Fhtmlua","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NotNite%2Fhtmlua/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NotNite%2Fhtmlua/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NotNite%2Fhtmlua/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/NotNite","download_url":"https://codeload.github.com/NotNite/htmlua/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251420887,"owners_count":21586697,"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":["redbean"],"created_at":"2024-11-11T17:24:56.088Z","updated_at":"2025-04-29T02:30:39.726Z","avatar_url":"https://github.com/NotNite.png","language":"Lua","funding_links":[],"categories":[],"sub_categories":[],"readme":"# htmlua\n\nhtmlua converts this:\n\n```lua\ndocument {\n  html {\n    head {\n      meta { charset = \"utf-8\" },\n      title \"Hello, world!\"\n    },\n\n    body {\n      h1 \"Hello, world!\",\n      p \"This is a paragraph.\"\n    }\n  }\n}\n```\n\ninto this:\n\n```html\n\u003c!DOCTYPE html\u003e\n\u003chtml\u003e\n  \u003chead\u003e\n    \u003cmeta charset=\"utf-8\" /\u003e\n    \u003ctitle\u003eHello, world!\u003c/title\u003e\n  \u003c/head\u003e\n  \u003cbody\u003e\n    \u003ch1\u003eHello, world!\u003c/h1\u003e\n    \u003cp\u003eThis is a paragraph.\u003c/p\u003e\n  \u003c/body\u003e\n\u003c/html\u003e\n```\n\n...all dynamically at request time. It is effectively serverside rendering where your output file is being rendered from Lua functions. It is written in 100% vanilla Lua and can be integrated into any Lua environment. It supports a component-like system for reusing blocks of HTML. It runs on six operating systems with a single file thanks to the [redbean](https://redbean.dev/) web server.\n\nIt is suggested to read `src/pages/index.html.lua`, as it is heavily commented.\n\n## Why?\n\nI recently read [Ben Visness](https://bvisness.me/luax/)'s article about their custom Lua dialect for JSX-like elements. I thought I could build a system just as flexible to use in vanilla Lua.\n\n## Installation\n\n- Copy the contents of this repository into a new folder.\n- Download `redbean.com` from the redbean website.\n- Execute `./run.sh` to pack the web server and run it.\n\n## How it works\n\nThis abuses a few tricks in the Lua language spec:\n\n- Functions that take a single argument can be called without parenthesis (`ident(\"a\")` = `ident \"a\"`)\n- Key value pairs and array-like entries into tables can be mixed (`{ a = \"b\", \"c\" }`)\n\nThe keywords are actually functions in the global scope that create the HTML element and return a string. Props are identified by key/value pairs and children are identified as entries in the table. Valueluess props (such as `autoplay` on the `video` element) can be specified with `_ = { \"autoplay\" }`.\n\n## Using htmlua\n\n### Creating your first page\n\nCreate `pages/index.html.lua`:\n\n```lua\nreturn function()\n  return document {\n    html {\n      head {\n        meta { charset = \"utf-8\" },\n        title \"Hello, world!\"\n      },\n\n      body {\n        h1 \"Hello, world!\",\n        p \"This is a paragraph.\"\n      }\n    }\n  }\nend\n```\n\n### Adding more HTML elements\n\nPut a line like this in your `.init.lua`:\n\n```lua\nh2 = htmlua.elem(\"h2\")\n```\n\nYou can provide a second argument for options for this element:\n\n- `close: boolean = true` - whether to close the element with `\u003c/name\u003e`\n- `empty: boolean = false` - whether to close the element wiith `/\u003e` if there are no children\n\n### Creating a reusable component\n\n```lua\nlocal htmlua = require(\"htmlua\")\n\nlocal MyComponent = htmlua.component(function(props, children)\n  return {\n    h1(\"Hello, \" .. props.name .. \"!\"),\n    p \"This is a reusable component.\"\n  }\nend)\n\nreturn function()\n  return document {\n    html {\n      head {\n        meta { charset = \"utf-8\" }\n      },\n\n      body {\n        MyComponent { name = \"world\" },\n        hr {},\n        MyComponent { name = \"Lua\" }\n      }\n    }\n  }\nend\n```\n\n### Routing\n\nPaths get tried in this order:\n\n- `pages/:path/index.lua`\n- `pages/:path/index.html.lua`\n- `pages/:path.html.lua`\n- `pages/:path.lua`\n\n## Testimonials\n\n- \"this is based i like this\" - \u003chttps://c7.pm/\u003e\n- \"Stop programming\" - \u003chttps://coolmathgames.tech/\u003e\n- \":(\" - \u003chttps://camora.dev/\u003e\n- \"omg Roblox\" - \u003chttps://jabco.page/\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnotnite%2Fhtmlua","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnotnite%2Fhtmlua","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnotnite%2Fhtmlua/lists"}