view.v0: Index | Files

package view

import ""

Package view is implementation of aah framework view engine using Go Template engine. It supports multi-layouts, no-layout, partial inheritance and error pages.


Package Files

funcs.go go_engine.go util.go version.go view.go


const Version = "0.9.0"

Version no. of aah framework view library


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

func AddEngine Uses

func AddEngine(name string, engine Enginer) error

AddEngine method adds the given name and engine to view store.

func AddTemplateFunc Uses

func AddTemplateFunc(funcMap template.FuncMap)

AddTemplateFunc method adds given Go template funcs into function map.

func StripPathPrefixAt Uses

func StripPathPrefixAt(str, pathCut string) string

StripPathPrefixAt method strips the given path to path cut position.

For Example:

path := "/Users/jeeva/go/src/"
result := StripPrefixAt(path, "views/")

func TrimPathPrefix Uses

func TrimPathPrefix(prefix string, fpaths ...string) string

TrimPathPrefix method trims given file paths by prefix and returns comma separated string.

type EngineBase Uses

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 Uses

func (eb *EngineBase) AddTemplate(layout, key string, tmpl *template.Template) error

AddTemplate method adds the given template for layout and key.

func (*EngineBase) AutoFieldInsertion Uses

func (eb *EngineBase) AutoFieldInsertion(name, v string) string

AutoFieldInsertion method processes the aah view's to auto insert the field.

func (*EngineBase) DirsPath Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

func (eb *EngineBase) ParseErrors(errs []error) error

ParseErrors method to parse and log the template error messages.

func (*EngineBase) ParseFile Uses

func (eb *EngineBase) ParseFile(filename string) (*template.Template, error)

ParseFile method parses given single file.

func (*EngineBase) ParseFiles Uses

func (eb *EngineBase) ParseFiles(t *template.Template, filenames ...string) (*template.Template, error)

ParseFiles method parses given files with given template instance.

func (*EngineBase) SetHotReload Uses

func (eb *EngineBase) SetHotReload(r bool)

SetHotReload method set teh view engine mode into hot reload without watcher.

type Enginer Uses

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.

func GetEngine Uses

func GetEngine(name string) (Enginer, bool)

GetEngine method returns the view engine from store by name otherwise nil.

type GoViewEngine Uses

type GoViewEngine struct {

GoViewEngine implements the partial inheritance support with Go templates.

func (*GoViewEngine) Init Uses

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 Uses

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) Add Uses

func (t *Templates) Add(key string, tmpl *template.Template) error

Add method adds the given template for the key.

func (*Templates) IsExists Uses

func (t *Templates) IsExists(key string) bool

IsExists method returns true if template key exists otherwise false.

func (*Templates) Keys Uses

func (t *Templates) Keys() []string

Keys method returns all the template keys.

func (*Templates) Lookup Uses

func (t *Templates) Lookup(key string) *template.Template

Lookup method return the template for given key.

Package view imports 13 packages (graph) and is imported by 3 packages. Updated 2018-07-09. Refresh now. Tools for package owners.