{"id":13316232,"url":"https://github.com/Be1zebub/lua-template","last_synced_at":"2025-03-10T22:32:49.614Z","repository":{"id":103809259,"uuid":"606038119","full_name":"Be1zebub/lua-template","owner":"Be1zebub","description":"php style html+lua inline templater for luvit","archived":false,"fork":false,"pushed_at":"2023-10-07T03:43:41.000Z","size":56,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-07-29T19:13:20.293Z","etag":null,"topics":["html","lua","luajit","luvit","template-engine"],"latest_commit_sha":null,"homepage":"https://incredible-gmod.ru","language":"Lua","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Be1zebub.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":"2023-02-24T13:09:57.000Z","updated_at":"2024-04-03T12:19:19.000Z","dependencies_parsed_at":"2023-05-05T18:55:39.868Z","dependency_job_id":null,"html_url":"https://github.com/Be1zebub/lua-template","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Be1zebub%2Flua-template","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Be1zebub%2Flua-template/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Be1zebub%2Flua-template/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Be1zebub%2Flua-template/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Be1zebub","download_url":"https://codeload.github.com/Be1zebub/lua-template/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242939401,"owners_count":20209874,"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":["html","lua","luajit","luvit","template-engine"],"created_at":"2024-07-29T18:20:37.774Z","updated_at":"2025-03-10T22:32:49.596Z","avatar_url":"https://github.com/Be1zebub.png","language":"Lua","funding_links":[],"categories":[],"sub_categories":[],"readme":"# lua-template\nphp style html+lua inline templater for luvit\ndeps: jit `string.buffer`, luvit `uv` (used in `:weblit` for fs watch), luvit `coro-fs` (used in `:include` \u0026 `:weblit`) - all expect `string.buffer` is optional\n\n# usage\n```lua\n-- /init.lua\nlocal app = require(\"weblit-app\")\n\napp.bind({\n\thost = \"127.0.0.1\",\n\tport = 80\n})\n\napp.route({\n\t\tmethod = \"GET\",\n\t\tpath = \"/\"\n\t}, require(\"lua-template\"):weblit(\"views/index.html\", {app = app}))\n\napp.start()\n```\n```html\n\u003c!-- /views/index.html --\u003e\n\n\u003c?lua \u003c!-- lua codeblock --\u003e\n\tfunction Hex(r, g, b)\n\t\treturn string.format(\"#%x\", (r * 0x10000) + (g * 0x100) + b):upper()\n\tend\n?\u003e\n\u003chtml\u003e\n\u003chead\u003e\n\t\u003cstyle type=\"text/css\"\u003e\n\t\th1 {\n\t\t\tcolor: ${ Hex(22, 160, 133) }; \u003c!-- echo codeblock --\u003e\n\t\t}\n\n\t\t.user {\n\t\t\tdisplay: table;\n\t\t\tmargin-top: 16px;\n\t\t}\n\n\t\t.avatar {\n\t\t\twidth: 96px;\n\t\t\theight: 96px;\n\t\t\tborder-radius: 50%;\n\t\t}\n\n\t\t.user \u003e span {\n\t\t\tdisplay: table-cell;\n\t\t\tvertical-align: middle;\n\t\t\twhite-space: pre;\n\t\t}\n\n\t\t.name {\n\t\t\tfont-size: 24px;\n\t\t}\n\n\t\t.admin {\n\t\t\tcolor: #c0392b;\n\t\t}\n\t\u003c/style\u003e\n\u003c/head\u003e\n\u003cbody\u003e\n\t\u003ch1\u003eCurrent time: ${os.time()}\u003c/h1\u003e\n\n\t\u003c?lua\n\t\tlocal users = {\n\t\t\t{id = 1, name = \"Beelzebub\", avatar = \"https://avatars.githubusercontent.com/u/34854689\", admin = true},\n\t\t\t{id = 2, name = \"John Doe\", avatar = \"https://i.imgur.com/gQMQB7e.jpeg\"}\n\t\t}\n\n\t\tfor i, user in ipairs(users) do\n\t?\u003e\n\t\t\u003cdiv class=\"user\" id=\"user-${user.id}\"\u003e\n\t\t\t\u003cimg class=\"avatar\" src=\"${user.avatar}\"\u003e\n\t\t\t\u003cspan class=\"name\"\u003e ${user.name}\u003c/span\u003e\n\t\t\t\u003c?lua\n\t\t\t\tif user.admin then\n\t\t\t?\u003e\n\t\t\t\t\u003cspan class=\"admin\"\u003e (admin)\u003c/span\u003e\n\t\t\t\u003c?lua\n\t\t\t\tend\n\t\t\t?\u003e\n\t\t\u003c/div\u003e\n\t\u003c?lua\n\t\tend\n\t?\u003e\n\u003c/body\u003e\n\u003c/html\u003e\n```\n![Preview](https://user-images.githubusercontent.com/34854689/221614096-5cbb3d1c-e70a-46d3-81a8-76e48e1fa1a7.png)\n![DOM Preview](https://user-images.githubusercontent.com/34854689/221614401-37bcf860-554f-466c-a7a0-abf5d3da3407.png)\n\n# notes\nstring buffer support required! \nto got string buffer support, you can get latest luvit build here: https://github.com/truemedian/luvit-bin\n\n# todo\nadd templ style feature, i think it looks like a good api\nhttps://templ.guide/syntax-and-usage/elements/\n\n```lua\n-- обёртка над lua-template, позволяющая упаковывать конструкторы и их env в удобную функцию templ.render\n\ntempl.new(\"button\")\n:add(\"text\", tostring) -- имя аргумента, конструктор аргумента\n:html(\"\u003cbutton\u003e${text}\u003c/button\u003e\")-- можно указать html код в виде строки\n:path(\"path/to/your/document.html\") -- либо в виде пути к файлу\n\ntempl.render(\"button\", {text = \"Click me\"}) -- класс шаблона, аргументы шаблона - внутренне использует luaTemplate:eval(code, env) для рендера\n\n-- пример использования:\ntempl.render(\"background\")\ntempl.render(\"header\", {\n\tuser = oauth2:GetUser(request.cookie.token)\n})\ntempl.render(\"promotion\", {\n\tsearch_placeholders = db:GetRandomAddons(5),\n\tfeatured = db:GetFeatured()\n})\ntempl.render(\"marketplace\", {\n\tnewcommers = db:GetLatestAddons(4),\n\tpopular = db:GetPopularAddons(12)\n})\ntempl.render(\"footer\", {\n\tstats = {\n\t\taddonsLen = db:GetAddonsForSale(),\n\t\tonline = db:GetOnlineCount(),\n\t\tvisitors = db:GetUniqueVisitors()\n\t}\n})\n\nresponse.body = templ.pop()\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FBe1zebub%2Flua-template","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FBe1zebub%2Flua-template","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FBe1zebub%2Flua-template/lists"}