gluatemplate

package module
v0.0.0-...-d9e2c9d Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2016 License: MIT Imports: 4 Imported by: 6

README

gluatemplate

Text template for gopher-lua

This product is based on Go Text Template. If you are not familiar with the syntax, please read the documentation.

Installation

go get github.com/kohkimakimoto/gluatemplate

API

template.dostring(text, table)

Returns string generated by text template with the table values. If this function fails, it returns nil, plus a string describing the error.

template.dofile(file, table)

Returns string generated by file template with the table values. If this function fails, it returns nil, plus a string describing the error.

Usage

package main

import (
    "github.com/yuin/gopher-lua"
    "github.com/kohkimakimoto/gluatemplate"
)

func main() {
    L := lua.NewState()
    defer L.Close()

    L.PreloadModule("template", gluatemplate.Loader)
    if err := L.DoString(`
local template = require("template")

local text = template.dostring([[
This is a text template library.
Created by {{.first_name}} {{.last_name}}
]], {
	first_name = "kohki",
	last_name = "makimoto",
})

print(text)
--
-- This is a text template library.
-- Created by kohki makimoto
--
`); err != nil {
        panic(err)
    }
}

Author

Kohki Makimoto kohki.makimoto@gmail.com

License

MIT license.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Loader

func Loader(L *lua.LState) int

Types

This section is empty.

Jump to

Keyboard shortcuts

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