Simple templating
Simplistic templating system inspired by Zed A. Shaw's minimal template for Tir.
Template features:
{{ code }} | Replaced with the string provided by 'code'. |
{% code %} | Execute code but do not output (used for loops, if, etc). |
{| code |} | Output code and preserve indentation. |
Usage:
local tmplt = lub.Template [[ Hello {{name}}. {% if parent then %} Your parent is {{parent.name}}. {% end %} ]] tmplt:run { name = 'Joe', parent = {name = 'Eve'}, } --> Hello Joe. --> Your parent is Eve.
.new (source)
Create a new template object ready to produce output by calling run. The source
parameters should be a string or a table with a path
key.
:run (env)
Returns resulting text by runngint the template with an environment table env
.