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 ¶
- Constants
- 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 ¶
const Version = "0.9.0"
Version no. of aah framework view library
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 ¶ added in v0.8.1
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 ¶ added in v0.8.1
TrimPathPrefix method trims given file paths by prefix and returns comma separated string.
Types ¶
type EngineBase ¶ added in v0.8.1
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 ¶ added in v0.8.1
func (eb *EngineBase) AddTemplate(layout, key string, tmpl *template.Template) error
AddTemplate method adds the given template for layout and key.
func (*EngineBase) AutoFieldInsertion ¶ added in v0.9.0
func (eb *EngineBase) AutoFieldInsertion(name, v string) string
AutoFieldInsertion method processes the aah view's to auto insert the field.
func (*EngineBase) DirsPath ¶ added in v0.8.1
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 ¶ added in v0.8.1
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 ¶ added in v0.8.1
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 ¶ added in v0.8.1
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 ¶ added in v0.8.1
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 ¶ added in v0.8.1
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 ¶ added in v0.9.0
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 ¶ added in v0.8.1
func (eb *EngineBase) ParseErrors(errs []error) error
ParseErrors method to parse and log the template error messages.
func (*EngineBase) ParseFile ¶ added in v0.9.0
func (eb *EngineBase) ParseFile(filename string) (*template.Template, error)
ParseFile method parses given single file.
func (*EngineBase) ParseFiles ¶ added in v0.9.0
func (eb *EngineBase) ParseFiles(t *template.Template, filenames ...string) (*template.Template, error)
ParseFiles method parses given files with given template instance.
func (*EngineBase) SetHotReload ¶ added in v0.9.0
func (eb *EngineBase) SetHotReload(r bool)
SetHotReload method set teh 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.
func (*GoViewEngine) Init ¶
func (e *GoViewEngine) Init(fs *vfs.VFS, appCfg *config.Config, baseDir string) error
Init method initialize a template engine with given aah application config and application views base path.
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.
func (*Templates) IsExists ¶ added in v0.8.1
IsExists method returns true if template key exists otherwise false.