Skip to content

kohkimakimoto/gluatemplate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

Text template for gopher-lua

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages