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: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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
⌂ 换网址