template

package
v0.0.0-...-f7fb57a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 28, 2019 License: BSD-3-Clause Imports: 6 Imported by: 0

README

template GoDoc

Usage

local template = require("template")

local mustache, err = template.choose("mustache")

local values = {name="world"}
print( mustache:render("Hello {{name}}!", values) ) -- mustache:render_file()
-- Output:"Hello world!"

local values = {data = {"one", "two"}}
print( mustache:render("{{#data}} {{.}} {{/data}}", values) )
-- Output:" one two "

Supported engines

Documentation

Overview

Package template implements template functionality for lua.

Example (Package)
state := lua.NewState()
Preload(state)
inspect.Preload(state)
source := `
local template = require("template")

local mustache, err = template.choose("mustache")

local values = {name="world"}
print( mustache:render("Hello {{name}}!", values) ) -- mustache:render_file(filename values)

local values = {data = {"one", "two"}}
print( mustache:render("{{#data}} {{.}} {{/data}}", values) )
`
if err := state.DoString(source); err != nil {
	log.Fatal(err.Error())
}
Output:

Hello world!
 one  two

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Choose

func Choose(L *lua.LState) int

Choose(): lua template.get(engine) returns (template_ud, err)

func Loader

func Loader(L *lua.LState) int

Loader is the module loader function.

func Preload

func Preload(L *lua.LState)

Preload adds template to the given Lua state's package.preload table. After it has been preloaded, it can be loaded using require:

local template = require("template")

func RegisterTemplateEngine

func RegisterTemplateEngine(driver string, i luaTemplateEngine)

RegisterTemplateEngine(): register template engine

func Render

func Render(L *lua.LState) int

Render(): lua template_ud:render(string, values) returns (string, err)

func RenderFile

func RenderFile(L *lua.LState) int

RenderFile(): lua template_ud:render(string, values) returns (string, err)

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL