Module restia.template

Template module.

Sets up an xhMoon environment and adds the utility functions.

Info:

  • License: Unlicense
  • Author: DarkWiiPlayer

Functions

inject (fn) Allows injecting code directly into the language environment.
require (modname) Requires a module in a similar way to Luas require function, but evaluates the code in the MoonXML language environment.
loadlua (code, filename) Loads a template from lua code.
loadmoon (code, filename) Loads a template from moonscript code.
render (...) Renders the template to a buffer table

Tables

loaded Stores required modules just like package.loaded does for normal Lua modules.

HTML Builder Environment

stylesheet (uri, async) Embeds a stylesheet into the document.
ulist (list) Renders an unordered list.
olist (list) Renders an ordered list.
vtable (...) Renders a table (vertical).
ttable (opt, rows) Renders a table.
lua (code) Renders a script tag from Lua code to be used by fengari.
moon (code) Renders a script tag from Moonscript code to be used by fengari.


Functions

inject (fn)
Allows injecting code directly into the language environment. This should only be used for very short snippets; using template.require is preferred.

Parameters:

  • fn function A function that gets called with the language environment.
require (modname)
Requires a module in a similar way to Luas require function, but evaluates the code in the MoonXML language environment. This allows writing specialized MoonHTML macros to avoid code duplication in views. As with requier, package.path is used to look for Lua modules.

Parameters:

  • modname string The name of the module.

Returns:

    module The loaded module. In other words, the return value of the evaluated Lua file.
loadlua (code, filename)
Loads a template from lua code. The code may be compiled bytecode.

Parameters:

  • code
  • filename
loadmoon (code, filename)
Loads a template from moonscript code.

Parameters:

  • code
  • filename
render (...)
Renders the template to a buffer table

Parameters:

  • ...

Tables

loaded
Stores required modules just like package.loaded does for normal Lua modules.

HTML Builder Environment

Automatically has access to the Restia library in the global variable ‘restia’.
stylesheet (uri, async)
Embeds a stylesheet into the document.

Parameters:

  • uri The URI to the stylesheet or a sequence of URIs
  • async boolean Load the stylesheet asynchronously and apply it once it’s loaded

Usage:

    stylesheet 'styles/site.css'
    stylesheet 'styles/form.css', true
ulist (list)
Renders an unordered list. List elements can be any valid MoonHTML data object, including functions and tables. They get passed directly to the li function call.

Parameters:

  • list table A sequence containing the list elements

Usage:

    ulist {
    	'Hello'
    	'World'
    	->
    		br 'foo'
    		print 'bar'
    	'That was a list'
    }
olist (list)
Renders an ordered list. Works like ulist.

Parameters:

  • list table A sequence containing the list elements

See also:

vtable (...)
Renders a table (vertical).

Parameters:

  • ... A list of rows (header rows can be marked by setting the header key)

Usage:

    vtable(
    	{'Name', 'Balance', header = true},
    	{'John', '500 €'}
    )
ttable (opt, rows)
Renders a table. Expects a sequence of keys as its first argument. Additional options can also be passed into the first table. Following arguments will be interpreted as key/value maps.

Parameters:

  • opt table A sequence containing the keys to be rendered.
  • rows table A sequence of tables that represent the table rows

Usage:

    ttable({'name', 'age', 'address', number: true, header: true, caption: -> h1 'People'}, {
    	{name: "John Doe", age: -> i 'unknown', address: -> i 'unknown'}
    })
lua (code)
Renders a script tag from Lua code to be used by fengari.

Parameters:

  • code string The content of the script tag (Lua code).

Usage:

    lua [[
    	print "Hello, World!"
    ]]
moon (code)
Renders a script tag from Moonscript code to be used by fengari. The code is first stripped of additional indentation and converted to Lua.

Parameters:

  • code string The content of the script tag (Moonscript code).

Usage:

    lua [[
    	print "Hello, World!"
    ]]
generated by LDoc 1.4.6 Last updated 2021-01-03 16:45:09