kmgGoTpl

package
v0.0.0-...-05317bf Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2015 License: MIT Imports: 11 Imported by: 0

README

kmg golang template engine

A PHP like template engine write for golang.

一个像PHP的golang模板引擎.

当前版本不稳定,随时会产生不向前兼容.

  • 大幅度减少学习成本,你只需要知道,在 里面写golang语句, 在 里面写需要渲染的golang表达式即可.
  • .gotpl 表示普通文本模板,此处不做任何自动转义 .gotplhtml 表示html模板,此处做3种xss的自动转义.
  • 报错有文件名和行号.
  • 对html的3种xss转义自动支持(kmgXss.H kmxXss.Urlv kmgXss.Jsonv)
example

template file.

<?
package example
type Input struct{
	Name     string
	Value    string
	ShowName string
	Comment  string
	Need     bool
	ReadOnly bool
	Id       string
}
func tplInputString(config Input)string{
?>
<div class="form-group has-feedback">
    <label class="col-sm-2 control-label"><?=config.ShowName?>
    <? if config.Need{ ?>
        <span style="color:red">*</span>
    <? } ?>

    <div class="col-sm-8">
        <input type="text" autocomplete="off" class="form-control"
               <? if config.ReadOnly{ ?>readonly<? } ?>
               name="<?=config.Name?>"
        value="<?=config.Value?>"/>
        <span style="font-size:12px;color:red">
            <? if config.Comment!=""{ ?>
                提示: <?=config.Comment?>
            <? } ?>
        </span>
    </div>
</div>
<? }
?>

use the function kmgGoTpl.MustBuildTplInDir("src/github.com/bronze1man/kmg/kmgView/testFile") to compile the template in your make file.

TODO
  • 允许在golang的字符串,注释,部分出现语法引擎使用过的关键字( func { } import ( ) 等)
  • 自动golang类型分析(确定是否直接渲染字符串,慢?)
reference

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildTplOneFile

func BuildTplOneFile(in []byte, isHtml bool) (out []byte, err error)

func MustBuildTplInDir

func MustBuildTplInDir(path string)

func MustBuildTplInDirWithCache

func MustBuildTplInDirWithCache(root string)

此处路径表示 项目里面的一个路径

func MustBuildTplInPathList

func MustBuildTplInPathList(pathList []string)

Types

This section is empty.

Jump to

Keyboard shortcuts

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