{"id":16209238,"url":"https://github.com/gilzoide/molde","last_synced_at":"2025-03-19T08:31:01.016Z","repository":{"id":70590414,"uuid":"81756618","full_name":"gilzoide/molde","owner":"gilzoide","description":"Zero dependency, single file template engine for Lua 5.1+ with builtin sandbox support","archived":false,"fork":false,"pushed_at":"2023-01-08T14:41:29.000Z","size":69,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-28T16:58:43.573Z","etag":null,"topics":["lua","luarocks","sandboxed","single-file","template","template-engine","zero-dependency"],"latest_commit_sha":null,"homepage":"https://gilzoide.github.io/molde/topics/README.md.html","language":"Lua","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"lgpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gilzoide.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","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},"funding":{"github":["gilzoide"],"patreon":null,"open_collective":null,"ko_fi":"gilzoide","tidelift":null,"community_bridge":null,"liberapay":"gilzoide","issuehunt":null,"otechie":null,"lfx_crowdfunding":null,"custom":null}},"created_at":"2017-02-12T20:58:00.000Z","updated_at":"2023-09-25T13:24:57.000Z","dependencies_parsed_at":"2023-02-24T13:30:32.863Z","dependency_job_id":null,"html_url":"https://github.com/gilzoide/molde","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gilzoide%2Fmolde","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gilzoide%2Fmolde/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gilzoide%2Fmolde/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gilzoide%2Fmolde/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gilzoide","download_url":"https://codeload.github.com/gilzoide/molde/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243976478,"owners_count":20377691,"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":["lua","luarocks","sandboxed","single-file","template","template-engine","zero-dependency"],"created_at":"2024-10-10T10:28:52.787Z","updated_at":"2025-03-19T08:31:01.011Z","avatar_url":"https://github.com/gilzoide.png","language":"Lua","readme":"Molde\n=====\n[![Build Status](https://travis-ci.org/gilzoide/molde.svg?branch=master)](https://travis-ci.org/gilzoide/molde)\n\nZero dependency, single file template engine for Lua 5.1+ with builtin sandbox\nsupport.\n\nIt compiles a template string to a function that generates the final\nstring by substituting values by the ones in a sandboxed environment.\n\n\nTemplates\n---------\nThere are 3 constructs templates recognize:\n\n- **Literals**: Content that will be copied unmodified to the final string.\n  Read the [note on long strings](#note-on-long-strings)\n- **Value**: A value processed by Lua and appended to the final string,\n  stringified by `tostring`\n- **Statement**: A Lua code block to be copied unmodified to the generated code,\n  used for variable assignments, repetitions, conditions, etc. It doesn't\n  directly generate contents for the final string\n\n**Values** are delimited by matching `{{` and `}}`, **statements** by `{%` and\n`%}`, and everything else is considered **literal**. Delimiter characters `{`,\n`}` and `%` can be escaped using a leading backslash. If you want literal `}}`\nor `%}` in your template, they **must** be escaped, or molde will return\nerror.\n\nExample:\n\n```\nNOTE: This is not a valid molde template for educational purposes.\n\nBy default, everything is copied unmodified to the final string.\n\nValues are just Lua expressions:\n- Hello {{ \"world\" }}\n  \"Hello world\"\n- {{ 5 + 3 * 4 }}\n  \"17\"\n- {{ nil or \"default\" }}\n  \"default\"\n- You are using {{ _VERSION }}\n  \"You are using Lua 5.3\" (You may use Lua 5.1 and 5.2 as well)\n- Line 1{{ \"\\n\" }}Line 2\n  \"Line 1\n  Line 2\"\n- Escaping \\{{ Hi! \\}} (Note that you MUST escape the closing '}}')\n  \"Escaping {{ Hi! }}\"\n- Escaping is characterwise, so \\{{ is as valid as {\\{\n  \"Escaping is characterwise, so {{ is as valid as {{\"\n- table.insert is used in values {{ so they must be a valid expression! }}\n  Error: ')' expected near 'they'\n\nStatements are Lua statements:\n- {% for i = 1, 5 do %}{{ i }} {% end %}\n  \"1 2 3 4 5 \"\n- {% -- this is just a comment, y'know %}\n  \"\"\n- {{ unbound_variable }}{% unbound_variable = \"Hi!\" %} {{ unbound_variable }}\n  \"nil Hi!\"\n- {% if false then %}This will never be printed{% else %}Conditionals!{% end %}\n  \"Conditionals!\"\n- \\{% Escaping works \\%} {\\% here as well %\\} (You MUST escape closing '%}' too)\n  \"{% Escaping works %} {% here as well %}\"\n- {% if without_then %}Statements must form valid Lua code!{% end %}\n  Error: 'then' expected near 'table'\n```\n\n\nNote on long strings\n--------------------\nThe lua reference manual says:\n\n\tFor convenience, when the opening long bracket is immediately\n\tfollowed by a newline, the newline is not included in the string.\n\nThe code generated by molde to insert literals uses long strings, so newlines\nthat come immediately after a closing value or statement **will not** be\nconsidered in the final string.\n\n\nInstalling\n----------\nUsing [LuaRocks](https://luarocks.org/):\n\n\t# luarocks install molde\n\nOr you may copy the only source file `molde.lua` to your Lua path\n\n\n\nUsing\n-----\n```lua\nlocal molde = require 'molde'\n\n-- molde.load and molde.loadfile return a function that receives a table\n-- with the values to substitute, and the optional environment (default: _G)\nhello_template = molde.load([[Hello {{ name or \"world\" }}]])\nprint(hello_template()) -- \"Hello world\"\nprint(hello_template{name = \"gilzoide\"}) -- \"Hello gilzoide\"\nname = \"gilzoide\"\nprint(hello_template({}, _ENV or getfenv())) -- \"Hello gilzoide\"\n\n-- load the template from a file (same template)\nhello_template = molde.loadfile(\"hello_template\")\nname = nil\nprint(hello_template()) -- \"Hello world\"\n```\n\n\n\nTesting\n-------\nRun automated tests using [busted](http://olivinelabs.com/busted/):\n\n\t$ busted\n\n\nDocumentation\n-------------\nThe API is documented using [LDoc](https://github.com/stevedonovan/LDoc) and\nis available at [github pages](http://gilzoide.github.io/molde).\n\nTo generate:\n\n\t$ ldoc . -d docs\n\n\nChange log\n----------\n\n+ 2.0.0 - Removed dependency on LPegLabel in favor of a pure streaming parser,\n  added `molde.tokenize`, changed `molde.parse` function to be an iterator\n  instead of returning table, move doc comments to source file, changed\n  `string_bracket_level` to be a function argument instead of module-wide\n  configuration, change `molde.load` to return `nil` + error instead of raising.\n+ 1.0.1 - Fix error handling for matching on LpegLabel v1.5\n+ 1.0.0 - Updated to use LpegLabel version 1.5+\n+ 0.1.6 - Support for Lua 5.1\n\n","funding_links":["https://github.com/sponsors/gilzoide","https://ko-fi.com/gilzoide","https://liberapay.com/gilzoide"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgilzoide%2Fmolde","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgilzoide%2Fmolde","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgilzoide%2Fmolde/lists"}