Documentation ¶
Overview ¶
Package view is implementation of aah framework view engine using Go Template engine. It supports multi-layouts, no-layout, partial inheritance and error pages.
Index ¶
- Variables
- func AddEngine(name string, engine Enginer) error
- func AddTemplateFunc(funcMap template.FuncMap)
- func StripPathPrefixAt(str, pathCut string) string
- func TrimPathPrefix(prefix string, fpaths ...string) string
- type EngineBase
- func (eb *EngineBase) AddTemplate(layout, key string, tmpl *template.Template) error
- func (eb *EngineBase) AutoFieldInsertion(name, v string) string
- func (eb *EngineBase) DirsPath(subDir string) ([]string, error)
- func (eb *EngineBase) FilesPath(subDir string) ([]string, error)
- func (eb *EngineBase) Get(layout, tpath, tmplName string) (*template.Template, error)
- func (eb *EngineBase) Init(fs *vfs.VFS, appCfg *config.Config, ...) error
- func (eb *EngineBase) LayoutFiles() ([]string, error)
- func (eb *EngineBase) NewTemplate(key string) *template.Template
- func (eb *EngineBase) Open(filename string) (string, error)
- func (eb *EngineBase) ParseErrors(errs []error) error
- func (eb *EngineBase) ParseFile(filename string) (*template.Template, error)
- func (eb *EngineBase) ParseFiles(t *template.Template, filenames ...string) (*template.Template, error)
- func (eb *EngineBase) SetHotReload(r bool)
- type Enginer
- type GoViewEngine
- type Templates
Constants ¶
This section is empty.
Variables ¶
var ( // TemplateFuncMap aah framework Go template function map. TemplateFuncMap = make(template.FuncMap) // DefaultDelimiter template default delimiter DefaultDelimiter = "{{.}}" )
var ( ErrTemplateEngineIsNil = errors.New("view: engine value is nil") ErrTemplateNotFound = errors.New("view: template not found") ErrTemplateKeyExists = errors.New("view: template key exists") )
view error messages
Functions ¶
func AddTemplateFunc ¶
AddTemplateFunc method adds given Go template funcs into function map.
func StripPathPrefixAt ¶
StripPathPrefixAt method strips the given path to path cut position.
For Example:
path := "/Users/jeeva/go/src/github.com/go-aah/tutorials/form/views/common/header.html" result := StripPrefixAt(path, "views/")
func TrimPathPrefix ¶
TrimPathPrefix method trims given file paths by prefix and returns comma separated string.
Types ¶
type EngineBase ¶
type EngineBase struct { CaseSensitive bool IsLayoutEnabled bool Name string BaseDir string FileExt string LeftDelim string RightDelim string AppConfig *config.Config Templates map[string]*Templates VFS *vfs.VFS // contains filtered or unexported fields }
EngineBase struct is to create common and repurpose the implementation. Could be used for custom view engine implementation.
func (*EngineBase) AddTemplate ¶
func (eb *EngineBase) AddTemplate(layout, key string, tmpl *template.Template) error
AddTemplate method adds the given template for layout and key.
func (*EngineBase) AutoFieldInsertion ¶
func (eb *EngineBase) AutoFieldInsertion(name, v string) string
AutoFieldInsertion method processes the aah view's to auto insert the field.
func (*EngineBase) DirsPath ¶
func (eb *EngineBase) DirsPath(subDir string) ([]string, error)
DirsPath method returns all sub directories from `<view-base-dir>/<sub-dir-name>`. if it not exists returns error.
func (*EngineBase) FilesPath ¶
func (eb *EngineBase) FilesPath(subDir string) ([]string, error)
FilesPath method returns all file path from `<view-base-dir>/<sub-dir-name>`. if it not exists returns error.
func (*EngineBase) Get ¶
func (eb *EngineBase) Get(layout, tpath, tmplName string) (*template.Template, error)
Get method returns the template based given name if found, otherwise nil.
func (*EngineBase) Init ¶
func (eb *EngineBase) Init(fs *vfs.VFS, appCfg *config.Config, baseDir, defaultEngineName, defaultFileExt string) error
Init method is to initialize the base fields values.
func (*EngineBase) LayoutFiles ¶
func (eb *EngineBase) LayoutFiles() ([]string, error)
LayoutFiles method returns the all layout files from `<view-base-dir>/layouts`. If layout directory doesn't exists it returns error.
func (*EngineBase) NewTemplate ¶
func (eb *EngineBase) NewTemplate(key string) *template.Template
NewTemplate method return new instance on `template.Template` initialized with key, template funcs and delimiters.
func (*EngineBase) Open ¶
func (eb *EngineBase) Open(filename string) (string, error)
Open method reads template from VFS if not found resolve from physical file system. Also does auto field insertion such as Anti-CSRF(anti_csrf_token) and requested page URL (_rt).
func (*EngineBase) ParseErrors ¶
func (eb *EngineBase) ParseErrors(errs []error) error
ParseErrors method to parse and log the template error messages.
func (*EngineBase) ParseFile ¶
func (eb *EngineBase) ParseFile(filename string) (*template.Template, error)
ParseFile method parses given single file.
func (*EngineBase) ParseFiles ¶
func (eb *EngineBase) ParseFiles(t *template.Template, filenames ...string) (*template.Template, error)
ParseFiles method parses given files with given template instance.
func (*EngineBase) SetHotReload ¶
func (eb *EngineBase) SetHotReload(r bool)
SetHotReload method set the view engine mode into hot reload without watcher.
type Enginer ¶
type Enginer interface { Init(fs *vfs.VFS, appCfg *config.Config, baseDir string) error Get(layout, path, tmplName string) (*template.Template, error) }
Enginer interface defines a methods for pluggable view engine.
type GoViewEngine ¶
type GoViewEngine struct {
*EngineBase
}
GoViewEngine implements the partial inheritance support with Go templates.
type Templates ¶
type Templates struct {
// contains filtered or unexported fields
}
Templates hold template reference of lowercase key and case sensitive key with reference to compliled template.