{"id":15177620,"url":"https://github.com/syarul/luax","last_synced_at":"2025-10-26T16:30:46.237Z","repository":{"id":255385400,"uuid":"849444112","full_name":"syarul/luax","owner":"syarul","description":"Template engine for writing HTML inside *.lua(x) files, like JSX.","archived":false,"fork":false,"pushed_at":"2024-10-26T03:36:06.000Z","size":69,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-10-30T05:33:38.401Z","etag":null,"topics":["ast","dsl","jsx","jsx-syntax","lua","react"],"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/syarul.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-08-29T15:52:02.000Z","updated_at":"2024-10-26T03:36:11.000Z","dependencies_parsed_at":null,"dependency_job_id":"8bc6d840-3041-472d-80fc-2dde54e97537","html_url":"https://github.com/syarul/luax","commit_stats":{"total_commits":14,"total_committers":2,"mean_commits":7.0,"dds":0.0714285714285714,"last_synced_commit":"e3966be4bb583f5f7ac31ae09e17304dc2570793"},"previous_names":["syarul/luax"],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syarul%2Fluax","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syarul%2Fluax/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syarul%2Fluax/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syarul%2Fluax/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/syarul","download_url":"https://codeload.github.com/syarul/luax/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238366726,"owners_count":19460172,"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":["ast","dsl","jsx","jsx-syntax","lua","react"],"created_at":"2024-09-27T14:41:24.484Z","updated_at":"2025-10-26T16:30:46.229Z","avatar_url":"https://github.com/syarul.png","language":"Lua","funding_links":[],"categories":[],"sub_categories":[],"readme":"## LuaX\n\nLuaX is Lua + HTML Syntax extension with built-in decent parse. In retrospect it's akin to React JSX.\n\n\u003ca href=\"https://luarocks.org/modules/syarul/luax\" rel=\"nofollow\"\u003e\u003cimg alt=\"Luarocks Package\" src=\"https://img.shields.io/badge/Luarocks-1.2.0-blue.svg\" style=\"max-width:100%;\"\u003e\u003c/a\u003e\n[![Lua CI](https://github.com/syarul/luax/actions/workflows/lua.yml/badge.svg)](https://github.com/syarul/luax/actions/workflows/lua.yml)\n\n## Decent Parser\nInitial inspiration comes from [https://bvisness.me/luax/](https://bvisness.me/luax/). The reason is to make it simpler with support of Lua `metaprogramming` where node `tags` is handle automatically without defining it.\n\n### Usage\n\nInstall with `Luarocks`\n\n`luarocks install luax`\n\nIf you only need the pragma without handling transpiling lua files, load the `LuaX` `h` pragma **only** with\n```lua\nlocal h = require('h')\n\nprint(h(div({ style = \"color: red;\" }, \"Hello from LuaX!\")))\n```\n\nYou'll get,\n\n```html\n\u003cdiv style=\"color: red;\"\u003eHello from LuaX!\u003c/div\u003e\n```\nSo how to use with actual HTML syntax in Lua? First create a `*.luax` file,\n\n```lua\n-- el.luax\nlocal attr = { style=\"color: red;\" }\nreturn \u003cdiv style={attr.stlye}\u003ehello from LuaX!\u003c/div\u003e\n```\n\nimport it on to the main\n```lua\n-- import luax transpiler to handle the parsing of *.luax file\nlocal h = require('luax')\n\nlocal el = require('el')\n\nprint(h(el))\n```\n\nYou'll get,\n\n```html\n\u003cdiv style=\"color: red;\"\u003eHello from LuaX!\u003c/div\u003e\n```\n\nSample usage with table structure\n\n```lua\nlocal function map(a, fcn)\n  local b = {}\n  for _, v in ipairs(a) do\n    table.insert(b, fcn(v))\n  end\n  return b\nend\n\nlocal filters = {\n  { url = \"#/\",          name = \"All\",       selected = true },\n  { url = \"#/active\",    name = \"Active\",    selected = false },\n  { url = \"#/completed\", name = \"Completed\", selected = false },\n}\n\nlocal content = map(filters, function(filter)\n  return \u003cli\u003e\n    \u003ca\n      class={filter.selected and 'selected' or nil}\n      href={filter.url}\n      _=\"on click add .selected to me\"\n    \u003e\n      {filter.name}\n    \u003c/a\u003e\n  \u003c/li\u003e\nend)\n\nreturn \u003cul class=\"filters\" _=\"on load set $filter to me\"\u003e\n    {content}\n\u003c/ul\u003e\n```\n\nSee the test folder to see more usage cases.\n\n## Sample Project\n\nCheck example with `lua examples/web-component/server.lua`\n\nAlso todoMCV example at,\n[https://github.com/syarul/todomvc-lua-luasocket-htmx-_hyperscript](https://github.com/syarul/todomvc-lua-luasocket-htmx-_hyperscript)\n\n## VSCode Integration\nInstall from [VSCode Extension Marketplace](https://marketplace.visualstudio.com/items?itemName=syarul.luax-syntax-highlighter) to support syntax highlighlight for `.luax` extension\n\n## Caveats\n\n- Since nodeName such `div`, `p`, etc+ are used as declared variables, so do **NOT** declare a function with the same name i.e.,\n\n```lua\nlocal function li()\n  return \u003cli\u003etodo 1\u003c/li\u003e\nend\n\n```\n- when using `table.concat` you need to convert to string so encapsulate with `h` pragma,\n- defining in bracket try to limit by using `'` instead of `\"` i.e., `{foo and 'foo' or nil}`,\n- leave attributes assignment with no spacing `{ foo=\"foo\" }` instead of `{ foo = \"foo\" }`,\n- \u003c!--\u003e HTML comments, not supported yet.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsyarul%2Fluax","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsyarul%2Fluax","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsyarul%2Fluax/lists"}