gview

package
v1.8.4-0...-cbac34e Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2019 License: MIT Imports: 24 Imported by: 0

Documentation

Overview

Package gview implements a template engine based on text/template.

Index

Constants

View Source
const (
	// Default group name for instance usage.
	DEFAULT_NAME = "default"
)

Variables

This section is empty.

Functions

func ParseContent

func ParseContent(content string, params Params) (string, error)

ParseContent parses the template content directly using the default view object and returns the parsed content.

Types

type FuncMap

type FuncMap = map[string]interface{}

FuncMap is type for custom template functions.

type Params

type Params = map[string]interface{}

Params is type for template params.

type View

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

View object for template engine.

func Instance

func Instance(name ...string) *View

Instance returns an instance of View with default settings. The parameter <name> is the name for the instance.

func New

func New(path ...string) *View

New returns a new view object. The parameter <path> specifies the template directory path to load template files.

func (*View) AddPath

func (view *View) AddPath(path string) error

AddPath adds a absolute or relative path to the search paths.

func (*View) Assign

func (view *View) Assign(key string, value interface{})

Assign binds a template variable to current view object. Each goroutine will take effect after the call, so it is concurrent-safe.

func (*View) Assigns

func (view *View) Assigns(data Params)

Assign binds multiple template variables to current view object. Each goroutine will take effect after the call, so it is concurrent-safe.

func (*View) BindFunc

func (view *View) BindFunc(name string, function interface{})

BindFunc registers customized template function named <name> with given function <function> to current view object. The <name> is the function name which can be called in template content.

func (*View) BindFuncMap

func (view *View) BindFuncMap(funcMap FuncMap)

BindFuncMap registers customized template functions by map to current view object. The key of map is the template function name and the value of map is the address of customized function.

func (*View) Parse

func (view *View) Parse(file string, params ...Params) (parsed string, err error)

ParseContent parses given template file <file> with given template parameters <params> and function map <funcMap> and returns the parsed string content.

func (*View) ParseContent

func (view *View) ParseContent(content string, params ...Params) (string, error)

ParseContent parses given template content <content> with given template parameters <params> and function map <funcMap> and returns the parsed content in []byte.

func (*View) SetDelimiters

func (view *View) SetDelimiters(left, right string)

SetDelimiters sets customized delimiters for template parsing.

func (*View) SetI18n

func (view *View) SetI18n(manager *gi18n.Manager)

SetI18n binds i18n manager to view engine.

func (*View) SetPath

func (view *View) SetPath(path string) error

SetPath sets the template directory path for template file search. The parameter <path> can be absolute or relative path, but absolute path is suggested.

Jump to

Keyboard shortcuts

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