template

package
v0.0.0-...-af4311f Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2019 License: Apache-2.0 Imports: 7 Imported by: 4

Documentation

Index

Constants

View Source
const (
	// True is true string
	True = "true"
	// False is false string
	False = "false"
)
View Source
const (
	// Exist defines exist function
	// It checks whether argument exists
	Exist = "exist"
)
View Source
const (
	// Length defines len function
	Length = "len"
)
View Source
const (
	// Random defines random function
	Random = "random"
)
View Source
const (
	// Select defines select function
	Select = "select"
)

Variables

View Source
var (
	// ErrUnclosedScript defines missing '}' error
	ErrUnclosedScript = errors.New("unclosed script, missing '}'")
	// ErrUnrecognizedToken defines unreognized token error
	ErrUnrecognizedToken = errors.New("only %% and %{ is allowed")
	// ErrUnclosedParenthesis defines missing ')' error
	ErrUnclosedParenthesis = errors.New("unclosed parenthesis, missing ')'")
)

Functions

func Call

func Call(name string, args ...jsonutil.Variable) (string, error)

Call calls function of template

Types

type Lexer

type Lexer struct {
	// contains filtered or unexported fields
}

Lexer is lexer for template

func NewLexer

func NewLexer(raw []rune) *Lexer

NewLexer new a lexer for raw

func (*Lexer) IsEnd

func (lr *Lexer) IsEnd() bool

IsEnd judge whether lexer is end

func (*Lexer) NextToken

func (lr *Lexer) NextToken() ([]rune, Token, error)

NextToken returns next token of the template

type Template

type Template interface {
	Render(vs jsonutil.VariableMap) (string, error)
}

Template is a simple template support variable Golang template is too complex to use in this case

func New

func New(raw string) (Template, error)

New returns raw string to template

type Token

type Token int

Token defines template token

const (
	// VariableNameToken defines variable name token
	VariableNameToken Token = iota
	// FuncNameToken defines func name token
	FuncNameToken
	// ArgToken defines function arg token
	ArgToken
	// ArgVariableToken defines function arg variable name token
	ArgVariableToken
	// TextToken defines normal text token
	TextToken

	// UnknownToken defines token unknown
	UnknownToken
)

Jump to

Keyboard shortcuts

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