template

package module
v0.0.0-...-3468418 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2020 License: MIT Imports: 9 Imported by: 0

README

template

模板结构

./templates
├── errors
├── layouts
│   ├── layout.tmpl
│   └── pjax_layout.tmpl
└── pages
	├── posts
	│   ├── posts.tmpl
	└── posts_detail
		└── posts_detail.tmpl

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Engine

type Engine struct {
	Errors <-chan error

	FuncMap    FuncMap
	HTMLRender Render
	// contains filtered or unexported fields
}

Engine 模板引擎

func NewEngine

func NewEngine(templateDir string, tmplFunc LoadTemplateFunc, funcMap FuncMap, opts ...Option) (*Engine, error)

NewEngine 创建一个gin引擎模板

func (*Engine) Close

func (en *Engine) Close() error

Close 关闭

func (*Engine) ErrorName

func (en *Engine) ErrorName(name string) string

ErrorName 单页

func (*Engine) Init

func (en *Engine) Init()

Init 初始化

func (*Engine) PageName

func (en *Engine) PageName(name string) string

PageName 页面

func (*Engine) RenderError

func (en *Engine) RenderError(w io.Writer, name string, data H, opts ...Option)

RenderError 渲染错误页面

func (*Engine) RenderPage

func (en *Engine) RenderPage(w io.Writer, name string, data H, opts ...Option)

RenderPage 渲染页面

func (*Engine) RenderSingle

func (en *Engine) RenderSingle(w io.Writer, name string, data H, opts ...Option)

RenderSingle 渲染单页面

func (*Engine) SingleName

func (en *Engine) SingleName(name string) string

SingleName 单页

func (*Engine) Watching

func (en *Engine) Watching() error

Watching 监听模板文件夹中是否有变动

type FuncMap

type FuncMap template.FuncMap

FuncMap ...

func NewFuncMap

func NewFuncMap() FuncMap

NewFuncMap instance

type H

type H map[string]interface{}

H is a shortcut for map[string]interface{}

type LoadTemplateFunc

type LoadTemplateFunc func(templatesDir string, funcMap FuncMap) Render

LoadTemplateFunc 加载模板函数类

type Option

type Option func(*Options)

Option 为可选参数赋值的函数

func GlobalConstant

func GlobalConstant(constant map[string]interface{}) Option

GlobalConstant ...

func GlobalVariable

func GlobalVariable(variable map[string]interface{}) Option

GlobalVariable ...

func Layout

func Layout(layout string) Option

Layout ...

func StatusCode

func StatusCode(statusCode int) Option

StatusCode ...

type Options

type Options struct {
	StatusCode     int
	Layout         string
	GlobalVariable map[string]interface{}
	GlobalConstant map[string]interface{}
}

Options 可选参数列表

type Render

type Render map[string]*template.Template

Render type

func DefaultLoadTemplate

func DefaultLoadTemplate(templatesDir string, funcMap FuncMap) Render

DefaultLoadTemplate ...

func NewRender

func NewRender() Render

NewRender instance

func (Render) Add

func (r Render) Add(name string, tmpl *template.Template) error

Add new template

func (Render) AddFromFilesFuncs

func (r Render) AddFromFilesFuncs(name string, funcMap FuncMap, files ...string) *template.Template

AddFromFilesFuncs supply add template from file callback func

func (Render) Execute

func (r Render) Execute(name string, wr io.Writer, data interface{}) error

Execute 执行

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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