Documentation ¶
Overview ¶
Go(Golang) template manager, especially suited for web.
# There are 2 types of templateEnv(aka: 2 types of templateName). Default is ContextMode 1. ContextMode: Name starts with "C->" or not starts with "F->"
eg: "C->main/demo/demo.tpl.html" or "C-> main/demo/demo.tpl.html" (not: blanks before file(main/demo/demo.tpl.html) will be discarded) or "main/demo/demo.tpl.html"
2. FilesMode: Name starts with "F->". (default separator of multiple files is ";")
eg: "F->main/demo/demo.tpl.html" or "F-> main/demo/demo.tpl.html" or "F-> main/demo/demo.tpl.html;main/demo/demo_ads.tpl.html" (will use the first file name when executing template)
# ContextMode is using template nesting, somewhat like template-inheritance in django/jinja2/... ContextMode will load context templates, then execute template in file: `FilePathOfLayoutRelativeToRoot`.
FilesMode is basically the same as http/template ¶
Index ¶
- Constants
- func ContainsString(slice []string, contains string) bool
- func HTML(ctx *gin.Context, code int, name string, data interface{})
- func Version() string
- type Delims
- type QpsStat
- type TemplateConfig
- type TemplateEnv
- func (self *TemplateEnv) GetFilePaths(dir string) []string
- func (self *TemplateEnv) IsContextMode() bool
- func (self *TemplateEnv) IsFilesMode() bool
- func (self *TemplateEnv) StandardTemplateName() string
- func (self TemplateEnv) String() string
- func (self *TemplateEnv) ToContextMode() *TemplateEnv
- func (self *TemplateEnv) ToFilesMode() *TemplateEnv
- type TemplateManager
- func (tm *TemplateManager) DoShowDebugMessage() bool
- func (tm *TemplateManager) ExecuteTemplate(out io.Writer, templateName string, data interface{}) error
- func (tm *TemplateManager) GetFilePathOfBase() (name string)
- func (tm *TemplateManager) GetMapOfTemplateNameToDefinedNames() (m map[string]string)
- func (tm *TemplateManager) GetTemplate(tplName string) (*template.Template, bool)
- func (tm *TemplateManager) GetTemplateNames() (names []string)
- func (tm *TemplateManager) HTML(ctx *gin.Context, code int, name string, data interface{})
- func (tm *TemplateManager) Init(useMaster bool) error
- func (tm *TemplateManager) Instance(name string, data interface{}) render.Render
- func (tm *TemplateManager) MustTemplate(tplName string, filesForParsing []string) *template.Template
- func (tm *TemplateManager) ParseContextModeTemplate(te *TemplateEnv) *template.Template
- func (tm *TemplateManager) ParseFilesModeTemplate(te *TemplateEnv) *template.Template
- func (tm *TemplateManager) Report() string
- func (tm *TemplateManager) SetVerboseLevel(level int)
- type TemplateModePrefix
- type TemplateRender
Constants ¶
View Source
const ( MimeHtml = "text/html" VERSION = "0.7.1" )
View Source
const FilesSeparator = ";"
Variables ¶
This section is empty.
Functions ¶
func ContainsString ¶
ContainsString checks if the slice has the contains value in it.
Types ¶
type QpsStat ¶ added in v0.7.2
func NewQpsStat ¶ added in v0.7.2
func (*QpsStat) ShortString ¶ added in v0.7.2
type TemplateConfig ¶
type TemplateConfig struct { DirOfRoot string // template root dir DirOfMainRelativeToRoot string // template dir: main DirOfContextRelativeToRoot string // template dir: context FilePathOfLayoutRelativeToRoot string // template layout file path Extension string // template extension FuncMap template.FuncMap // template functions Delims Delims // delimiters IsDebugging bool // true: Show debug info; false: disable debug info and enable cache. VerboseLevel int // 0: not show anything EnableMinifyTemplate bool // enable minify template after loading it and before storing it to the memory. EnableMinifyHtml bool // decide to minify html while output ShowQps bool // if VerboseLevel >= 1 || ShowQps { // show qps }, default is false }
func NewDefaultConfig ¶ added in v0.7.2
func NewDefaultConfig(isDebugging bool) TemplateConfig
type TemplateEnv ¶ added in v0.7.2
type TemplateEnv struct { Mode TemplateModePrefix // template env: "C->" or "F->" Names []string // template names. ContextEnv has one "Names" only. }
func NewTemplateEnvByParsing ¶ added in v0.7.2
func NewTemplateEnvByParsing(tplName string) *TemplateEnv
func (*TemplateEnv) GetFilePaths ¶ added in v0.7.2
func (self *TemplateEnv) GetFilePaths(dir string) []string
func (*TemplateEnv) IsContextMode ¶ added in v0.7.2
func (self *TemplateEnv) IsContextMode() bool
func (*TemplateEnv) IsFilesMode ¶ added in v0.7.2
func (self *TemplateEnv) IsFilesMode() bool
func (*TemplateEnv) StandardTemplateName ¶ added in v0.7.2
func (self *TemplateEnv) StandardTemplateName() string
func (TemplateEnv) String ¶ added in v0.7.2
func (self TemplateEnv) String() string
func (*TemplateEnv) ToContextMode ¶ added in v0.7.2
func (self *TemplateEnv) ToContextMode() *TemplateEnv
func (*TemplateEnv) ToFilesMode ¶ added in v0.7.2
func (self *TemplateEnv) ToFilesMode() *TemplateEnv
type TemplateManager ¶
type TemplateManager struct { Config TemplateConfig TemplatesMap map[string]*template.Template // contains filtered or unexported fields }
func New ¶
func New(config TemplateConfig) *TemplateManager
func NewDefault ¶ added in v0.7.2
func NewDefault(isDebugging bool) *TemplateManager
func (*TemplateManager) DoShowDebugMessage ¶ added in v0.7.2
func (tm *TemplateManager) DoShowDebugMessage() bool
func (*TemplateManager) ExecuteTemplate ¶
func (tm *TemplateManager) ExecuteTemplate(out io.Writer, templateName string, data interface{}) error
func (*TemplateManager) GetFilePathOfBase ¶
func (tm *TemplateManager) GetFilePathOfBase() (name string)
func (*TemplateManager) GetMapOfTemplateNameToDefinedNames ¶
func (tm *TemplateManager) GetMapOfTemplateNameToDefinedNames() (m map[string]string)
func (*TemplateManager) GetTemplate ¶
func (tm *TemplateManager) GetTemplate(tplName string) (*template.Template, bool)
func (*TemplateManager) GetTemplateNames ¶
func (tm *TemplateManager) GetTemplateNames() (names []string)
func (*TemplateManager) HTML ¶
func (tm *TemplateManager) HTML(ctx *gin.Context, code int, name string, data interface{})
func (*TemplateManager) Init ¶
func (tm *TemplateManager) Init(useMaster bool) error
func (*TemplateManager) Instance ¶
func (tm *TemplateManager) Instance(name string, data interface{}) render.Render
func (*TemplateManager) MustTemplate ¶ added in v0.7.2
func (tm *TemplateManager) MustTemplate(tplName string, filesForParsing []string) *template.Template
func (*TemplateManager) ParseContextModeTemplate ¶
func (tm *TemplateManager) ParseContextModeTemplate(te *TemplateEnv) *template.Template
func (*TemplateManager) ParseFilesModeTemplate ¶
func (tm *TemplateManager) ParseFilesModeTemplate(te *TemplateEnv) *template.Template
func (*TemplateManager) Report ¶
func (tm *TemplateManager) Report() string
func (*TemplateManager) SetVerboseLevel ¶ added in v0.7.2
func (tm *TemplateManager) SetVerboseLevel(level int)
0: disables all
type TemplateModePrefix ¶ added in v0.7.2
type TemplateModePrefix string
const TemplateModeContextPrefix TemplateModePrefix = "C->"
const TemplateModeFilesPrefix TemplateModePrefix = "F->"
type TemplateRender ¶
type TemplateRender struct { Name string Data interface{} // contains filtered or unexported fields }
func (TemplateRender) Render ¶
func (r TemplateRender) Render(w http.ResponseWriter) error
func (TemplateRender) WriteContentType ¶
func (r TemplateRender) WriteContentType(w http.ResponseWriter)
Click to show internal directories.
Click to hide internal directories.